16#ifndef SIMICS_SYSTEMC_IFACE_TRANSACTION_DATA_BUFFER_POOL_H
17#define SIMICS_SYSTEMC_IFACE_TRANSACTION_DATA_BUFFER_POOL_H
19#include <simics/base/transaction.h>
23#include <unordered_map>
38 : data_(num_bytes, 0) {
40 throw std::invalid_argument {
41 "Cannot allocate an empty data buffer"
44 buffer_.data = &data_.front();
45 buffer_.len = num_bytes;
46 bytes_.data = &data_.front();
47 bytes_.len = num_bytes;
51 buffer_.data =
nullptr;
52 bytes_.data =
nullptr;
69 auto size = SIM_transaction_size(transaction);
71 throw std::logic_error {
72 "The number of bytes for this data buffer ("
74 +
") does not fit the size of the transaction ("
75 + std::to_string(size) +
")"
79 SIM_get_transaction_bytes(transaction, buffer_);
84 auto size = SIM_transaction_size(transaction);
86 throw std::logic_error {
87 "The number of bytes for this data buffer ("
89 +
") does not fit the size of the transaction ("
90 + std::to_string(size) +
")"
94 SIM_set_transaction_bytes(transaction, bytes_);
98 std::vector<unsigned char> data_;
109 for (
auto it = pool_.begin(); it != pool_.end(); ++it) {
116 auto roundup_size = roundUpSize(size);
117 auto it = pool_.find(roundup_size);
118 if (it != pool_.end()) {
129 pool_.emplace(buf->
numBytes(), buf);
135 static unsigned roundUpSize(
unsigned size) {
142 if (size <= 8388608) {
145 throw std::logic_error {
146 "The transaction data buffer does not support"
147 " data larger than 8M. Please report it."
151 std::unordered_multimap<unsigned, TransactionDataBuffer*> pool_;
Definition: transaction_data_buffer_pool.h:106
virtual ~TransactionDataBufferPool()
Definition: transaction_data_buffer_pool.h:108
void release(TransactionDataBuffer *buf)
Definition: transaction_data_buffer_pool.h:128
TransactionDataBuffer * acquire(unsigned size)
Definition: transaction_data_buffer_pool.h:114
Definition: transaction_data_buffer_pool.h:33
void copyToBuffer(const transaction_t *transaction)
Copy the bytes from transaction to buffer_.
Definition: transaction_data_buffer_pool.h:68
TransactionDataBuffer(unsigned num_bytes)
Definition: transaction_data_buffer_pool.h:37
void copyFromBuffer(const transaction_t *transaction)
Copy the bytes_ to transaction.
Definition: transaction_data_buffer_pool.h:83
virtual ~TransactionDataBuffer()
Definition: transaction_data_buffer_pool.h:50
unsigned char * dataPtr() const
Returns the data pointer to the data buffer.
Definition: transaction_data_buffer_pool.h:62
unsigned numBytes() const
Returns the maximum number of bytes in the data buffer, it is not affected by reSize and clear.
Definition: transaction_data_buffer_pool.h:57