14#ifndef SIMICS_SYSTEMC_IFACE_TRANSACTION_DATA_BUFFER_POOL_H
15#define SIMICS_SYSTEMC_IFACE_TRANSACTION_DATA_BUFFER_POOL_H
17#include <simics/base/transaction.h>
21#include <unordered_map>
36 : data_(num_bytes, 0) {
38 throw std::invalid_argument {
39 "Cannot allocate an empty data buffer"
42 buffer_.data = &data_.front();
43 buffer_.len = num_bytes;
44 bytes_.data = &data_.front();
45 bytes_.len = num_bytes;
49 buffer_.data =
nullptr;
50 bytes_.data =
nullptr;
67 auto size = SIM_transaction_size(transaction);
69 throw std::logic_error {
70 "The number of bytes for this data buffer ("
72 +
") does not fit the size of the transaction ("
73 + std::to_string(size) +
")"
77 SIM_get_transaction_bytes(transaction, buffer_);
82 auto size = SIM_transaction_size(transaction);
84 throw std::logic_error {
85 "The number of bytes for this data buffer ("
87 +
") does not fit the size of the transaction ("
88 + std::to_string(size) +
")"
92 SIM_set_transaction_bytes(transaction, bytes_);
96 std::vector<unsigned char> data_;
107 for (
auto it = pool_.begin(); it != pool_.end(); ++it) {
114 auto roundup_size = roundUpSize(size);
115 auto it = pool_.find(roundup_size);
116 if (it != pool_.end()) {
127 pool_.emplace(buf->
numBytes(), buf);
133 static unsigned roundUpSize(
unsigned size) {
140 if (size <= 8388608) {
143 throw std::logic_error {
144 "The transaction data buffer does not support"
145 " data larger than 8M. Please report it."
149 std::unordered_multimap<unsigned, TransactionDataBuffer*> pool_;
Definition: transaction_data_buffer_pool.h:104
virtual ~TransactionDataBufferPool()
Definition: transaction_data_buffer_pool.h:106
void release(TransactionDataBuffer *buf)
Definition: transaction_data_buffer_pool.h:126
TransactionDataBuffer * acquire(unsigned size)
Definition: transaction_data_buffer_pool.h:112
Definition: transaction_data_buffer_pool.h:31
void copyToBuffer(const transaction_t *transaction)
Copy the bytes from transaction to buffer_.
Definition: transaction_data_buffer_pool.h:66
TransactionDataBuffer(unsigned num_bytes)
Definition: transaction_data_buffer_pool.h:35
void copyFromBuffer(const transaction_t *transaction)
Copy the bytes_ to transaction.
Definition: transaction_data_buffer_pool.h:81
virtual ~TransactionDataBuffer()
Definition: transaction_data_buffer_pool.h:48
unsigned char * dataPtr() const
Returns the data pointer to the data buffer.
Definition: transaction_data_buffer_pool.h:60
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:55