otsdaq-mu2e-stm  5.02.01
buffer_pool.hh
1 #ifndef BUFFER_POOL_hh_
2 #define BUFFER_POOL_hh_
3 
4 // Ring buffer code
5 #include "ring_buffer.hh"
6 
7 // Pre-allocated buffer pool for memory reuse
8 class BufferPool {
9 
10 private:
11 
12  // Pool of pre-allocated buffers
13  std::vector<std::shared_ptr<DataStruct>> pool;
14  // Mutex for thread safety
15  std::mutex mutex;
16 
17 public:
18 
19  // Constructor to initialize buffer pool
20  BufferPool(size_t pool_size, size_t buffer_size);
21 
22  // Destructor for logging
23  ~BufferPool() {
24  std::cout << "BufferPool destructor called.\n";
25  }
26 
27  // Acquire a buffer from the pool
28  std::shared_ptr<DataStruct> acquire();
29 
30  // Return a buffer to the pool
31  void release(std::shared_ptr<DataStruct> buffer);
32 
33 };
34 
35 #endif