rogue
Loading...
Searching...
No Matches
Pool.h
Go to the documentation of this file.
1
17#ifndef __ROGUE_INTERFACES_STREAM_POOL_H__
18#define __ROGUE_INTERFACES_STREAM_POOL_H__
19#include "rogue/Directives.h"
20
21#include <stdint.h>
22
23#include <memory>
24#include <queue>
25#include <thread>
26
28#include "rogue/Queue.h"
29
30namespace rogue {
31namespace interfaces {
32namespace stream {
33
34class Frame;
35class Buffer;
36
71class Pool : public rogue::EnableSharedFromThis<rogue::interfaces::stream::Pool> {
72 // Mutex
73 std::mutex mtx_;
74
75 // Track buffer allocations
76 uint32_t allocMeta_;
77
78 // Total memory allocated
79 uint32_t allocBytes_;
80
81 // Total buffers allocated
82 uint32_t allocCount_;
83
84 // Buffer queue
85 std::queue<uint8_t*> dataQ_;
86
87 // Fixed size buffer mode
88 uint32_t fixedSize_;
89
90 // Buffer queue count
91 uint32_t poolSize_;
92
93 public:
95 Pool();
96
98 virtual ~Pool();
99
111 uint32_t getAllocBytes();
112
124 uint32_t getAllocCount();
125
136 virtual std::shared_ptr<rogue::interfaces::stream::Frame> acceptReq(uint32_t size, bool zeroCopyEn);
137
150 virtual void retBuffer(uint8_t* data, uint32_t meta, uint32_t size);
151
153 static void setup_python();
154
165 void setFixedSize(uint32_t size);
166
177 uint32_t getFixedSize();
178
186 void setPoolSize(uint32_t size);
187
195 uint32_t getPoolSize();
196
197 protected:
213 std::shared_ptr<rogue::interfaces::stream::Buffer> allocBuffer(uint32_t size, uint32_t* total);
214
231 std::shared_ptr<rogue::interfaces::stream::Buffer> createBuffer(void* data,
232 uint32_t meta,
233 uint32_t size,
234 uint32_t alloc);
235
245 void decCounter(uint32_t alloc);
246};
247
249typedef std::shared_ptr<rogue::interfaces::stream::Pool> PoolPtr;
250} // namespace stream
251} // namespace interfaces
252} // namespace rogue
253#endif
Typed shared-from-this helper for Rogue classes.
Frame and buffer allocator for stream endpoints.
Definition Pool.h:71
void decCounter(uint32_t alloc)
Decrements allocation counter.
Definition Pool.cpp:192
virtual ~Pool()
Destroys the pool and releases any cached buffer storage.
Definition Pool.cpp:51
void setFixedSize(uint32_t size)
Sets fixed-size mode.
Definition Pool.cpp:115
uint32_t getFixedSize()
Returns fixed-size allocation setting.
Definition Pool.cpp:123
void setPoolSize(uint32_t size)
Sets buffer pool size.
Definition Pool.cpp:128
virtual void retBuffer(uint8_t *data, uint32_t meta, uint32_t size)
Returns buffer data to the allocator.
Definition Pool.cpp:88
uint32_t getAllocBytes()
Returns total currently allocated bytes.
Definition Pool.cpp:58
uint32_t getPoolSize()
Returns configured maximum number of cached pool entries.
Definition Pool.cpp:136
std::shared_ptr< rogue::interfaces::stream::Buffer > allocBuffer(uint32_t size, uint32_t *total)
Allocate a buffer passed size.
Definition Pool.cpp:142
uint32_t getAllocCount()
Returns total currently allocated buffer count.
Definition Pool.cpp:63
std::shared_ptr< rogue::interfaces::stream::Buffer > createBuffer(void *data, uint32_t meta, uint32_t size, uint32_t alloc)
Creates a Buffer with a pre-allocated data block.
Definition Pool.cpp:178
static void setup_python()
Registers this type with Python bindings.
Definition Pool.cpp:102
virtual std::shared_ptr< rogue::interfaces::stream::Frame > acceptReq(uint32_t size, bool zeroCopyEn)
Services a frame allocation request from a master.
Definition Pool.cpp:72
Pool()
Constructs a pool with default allocation behavior enabled.
Definition Pool.cpp:42
std::shared_ptr< rogue::interfaces::stream::Pool > PoolPtr
Shared pointer alias for Pool.
Definition Pool.h:249