SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
transaction_pool.h
Go to the documentation of this file.
1// -*- mode: C++; c-file-style: "virtutech-c++" -*-
2
3/*
4 © 2014 Intel Corporation
5
6 This software and the related documents are Intel copyrighted materials, and
7 your use of them is governed by the express license under which they were
8 provided to you ("License"). Unless the License provides otherwise, you may
9 not use, modify, copy, publish, distribute, disclose or transmit this software
10 or the related documents without Intel's prior written permission.
11
12 This software and the related documents are provided as is, with no express or
13 implied warranties, other than those that are expressly stated in the License.
14*/
15
16#ifndef SIMICS_SYSTEMC_IFACE_TRANSACTION_POOL_H
17#define SIMICS_SYSTEMC_IFACE_TRANSACTION_POOL_H
18
22#include <tlm>
23
24#include <deque>
25#include <set>
26
27namespace simics {
28namespace systemc {
29namespace iface {
30
34class TransactionPool : public tlm::tlm_mm_interface {
35 typedef tlm::tlm_generic_payload gp_t;
36
37 public:
39 : active_cnt_(0) {
40 }
41
43 // Once the TransactionPool object is destroyed, the pool_ member is
44 // invalid. The deleter avoids pushing the payload back into an invalid
45 // member and deletes the payload. The delete of the payload deletes
46 // the TransactionExtension as well.
47 static struct : public tlm::tlm_mm_interface {
48 void free(tlm::tlm_generic_payload *gp) override {
49 delete gp;
50 }
51 } deleter;
52
53 for (std::set<gp_t *>::iterator it = all_payloads_.begin();
54 it != all_payloads_.end(); ++it) {
55 if ((*it)->get_ref_count() == 0) {
56 delete *it;
57 } else {
58 (*it)->set_mm(&deleter);
59 }
60 }
61 }
62
63 // tlm_mm_interface
64 // free method is invoked when the reference count of the GP
65 // is reduced to zero
66 void free(gp_t *transaction_ptr) override {
67 // Reset sticky extension state (do not delete the extension).
68 if (auto *ext = transaction_ptr->get_extension<
70 ext->reset();
71 }
72
73 transaction_ptr->reset();
74 simics::systemc::utility::reset_payload(transaction_ptr);
75 pool_.push_back(transaction_ptr);
76 --active_cnt_;
77 assert(active_cnt_ >= 0 && "Active number of GP becomes negative");
78 }
79
81 gp_t *gp = NULL;
82 if (pool_.empty()) {
83 // mm object is explicit passed when create gp_t
84 // there is no need to call set_mm
85 gp = new gp_t(this);
86 // Set sticky extension. Deleted in ~tlm_generic_payload()
87 gp->set_extension(new iface::TransactionExtension);
88 all_payloads_.insert(gp);
89 } else {
90 gp = pool_.front();
91 pool_.pop_front();
92 }
93
94 ++active_cnt_;
95 return Transaction(gp);
96 }
97
98 unsigned PoolSize() const {
99 return pool_.size();
100 }
101
102 int active_cnt() const {
103 return active_cnt_;
104 }
105
106 private:
107 // queue holding payloads currently not allocated
108 std::deque<gp_t *> pool_;
109 std::set<gp_t *> all_payloads_;
110 // Active number of GP in use right now
111 int active_cnt_;
112};
113
114} // namespace iface
115} // namespace systemc
116} // namespace simics
117
118#endif
Definition: transaction_extension.h:54
A memory manager that implements the tlm::tlm_mm_interface providing a pool of transaction objects.
Definition: transaction_pool.h:34
int active_cnt() const
Definition: transaction_pool.h:102
void free(gp_t *transaction_ptr) override
Definition: transaction_pool.h:66
unsigned PoolSize() const
Definition: transaction_pool.h:98
TransactionPool()
Definition: transaction_pool.h:38
~TransactionPool()
Definition: transaction_pool.h:42
Transaction acquire()
Definition: transaction_pool.h:80
Class that encapsulates a generic_payload and returns it to the TransactionPool when the Transaction ...
Definition: transaction.h:31
Definition: adapter.h:81