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 virtual void free(tlm::tlm_generic_payload *gp) {
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
64 gp_t *gp = NULL;
65 if (pool_.empty()) {
66 // mm object is explicit passed when create gp_t
67 // there is no need to call set_mm
68 gp = new gp_t(this);
69 // Set sticky extension. Deleted in ~tlm_generic_payload()
70 gp->set_extension(new iface::TransactionExtension);
71 all_payloads_.insert(gp);
72 } else {
73 gp = pool_.front();
74 pool_.pop_front();
75 }
76
77 ++active_cnt_;
78 return Transaction(gp);
79 }
80
81 // free method is invoked when the reference count of the GP
82 // is reduced to zero
83 void free(gp_t *transaction_ptr) {
84 // For sticky extensions, they will be reused without cleared
85 transaction_ptr->reset();
86 simics::systemc::utility::reset_payload(transaction_ptr);
87 pool_.push_back(transaction_ptr);
88 --active_cnt_;
89 assert(active_cnt_ >= 0 && "Active number of GP becomes negative");
90 }
91
92 unsigned PoolSize() const {
93 return pool_.size();
94 }
95
96 int active_cnt() const {
97 return active_cnt_;
98 }
99
100 private:
101 // queue holding payloads currently not allocated
102 std::deque<gp_t *> pool_;
103 std::set<gp_t *> all_payloads_;
104 // Active number of GP in use right now
105 int active_cnt_;
106};
107
108} // namespace iface
109} // namespace systemc
110} // namespace simics
111
112#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:96
void free(gp_t *transaction_ptr)
Definition: transaction_pool.h:83
unsigned PoolSize() const
Definition: transaction_pool.h:92
TransactionPool()
Definition: transaction_pool.h:38
~TransactionPool()
Definition: transaction_pool.h:42
Transaction acquire()
Definition: transaction_pool.h:63
Class that encapsulates a generic_payload and returns it to the TransactionPool when the Transaction ...
Definition: transaction.h:31
Definition: pci_bus_interface.h:24