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