16 #ifndef DABC_MemoryPool
17 #define DABC_MemoryPool
19 #ifndef DABC_ModuleAsync
37 class BufferContainer;
124 MemoryPool(
const std::string &name,
bool withmanager =
false);
127 virtual const char*
ClassName()
const {
return "MemoryPool"; }
149 bool Assign(
bool isowner, const std::vector<
void*>& bufs, const std::vector<
unsigned>& sizes) throw();
155 bool _GetPoolInfo(std::vector<
void*>& bufs, std::vector<
unsigned>& sizes,
unsigned* changecnt = 0);
158 bool GetPoolInfo(std::vector<
void*>& bufs, std::vector<
unsigned>& sizes);
227 void SetMem(
unsigned buffersize,
unsigned numbuffers,
unsigned align = 0)
229 if (buffersize*numbuffers != 0) {
#define DABC_COMMAND(cmd_class, cmd_name)
#define DABC_REFERENCE(RefClass, ParentClass, T)
Container for data, referenced by Buffer class.
Reference on memory from memory pool.
void SetMem(unsigned buffersize, unsigned numbuffers, unsigned align=0)
Represents command with its arguments.
bool SetStr(const std::string &name, const char *value)
bool SetUInt(const std::string &name, unsigned v)
Interface class between xml configuration and dabc objects.
Manager of everything in DABC
Reference on dabc::MemoryPool class
unsigned GetMaxBufSize() const
Return maximum buffer size in the pool.
double GetUsedRatio() const
Return usage of memory pool.
Reference CreateNewRequester()
unsigned GetMinBufSize() const
Return minimum buffer size in the pool.
Buffer TakeBuffer(BufferSize_t size=0)
static unsigned fDfltAlignment
default alignment for memory allocation
std::vector< RequesterReq > fReqests
configuration for each output
virtual void ProcessEvent(const EventId &)
Buffer _TakeBuffer(BufferSize_t size, bool except, bool reserve_memory=true)
Central method, which reserves memory from pool and fill structures of buffer.
bool _ProcessRequests()
Process submitted requests, if returns true if any requests was processed.
Queue< unsigned, true > fPending
queue with requester indexes which are waiting release of the memory
bool Release()
Release memory and structures, allocated by memory pool.
unsigned GetMaxNumSegments() const
Returns number of preallocated segments.
static void SetDfltAlignment(unsigned v)
bool fEvntFired
indicates if event was fired to process memory requests
virtual int ExecuteCommand(Command cmd)
Main method where commands are executed.
bool SetAlignment(unsigned align)
Following methods could be used for configuration of pool before memory pool is allocated.
bool IsEmpty() const
Return true, if memory pool is not yet created.
bool Assign(bool isowner, const std::vector< void * > &bufs, const std::vector< unsigned > &sizes)
This is alternative method to supply memory to the pool.
virtual void OnThreadAssigned()
void ReleaseRawBuffer(unsigned indx)
Release raw buffer, allocated before by TakeRawBuffer.
bool Reconstruct(Command cmd)
Reconstruct memory pool base on command configuration.
virtual void ProcessConnectionActivated(const std::string &name, bool on)
Method called when port started or stopped.
unsigned fChangeCounter
memory pool change counter, incremented every time memory is allocated or freed
void IncreaseSegmRefs(MemSegment *segm, unsigned num)
Method increases ref.counuters of all segments.
MemoryBlock * fMem
list of preallocated memory
bool _Allocate(BufferSize_t bufsize=0, unsigned number=0)
Method to allocate memory for the pool, mutex should be locked.
Mutex * GetPoolMutex() const
bool GetPoolInfo(std::vector< void * > &bufs, std::vector< unsigned > &sizes)
Return pointers and sizes of all memory buffers in the pool.
unsigned GetMaxBufSize() const
Return maximum buffer size in the pool.
bool CheckChangeCounter(unsigned &cnt)
Check if memory pool structure was changed since last call, do not involves memory pool mutex.
bool IsSingleSegmRefs(MemSegment *segm, unsigned num)
Return true when all segments has refcnt==1.
unsigned GetBufferSize(unsigned id) const
Returns size of preallocated buffer.
virtual const char * ClassName() const
Returns class name of the object.
bool TakeRawBuffer(unsigned &indx)
Reserve raw buffer without creating Buffer instance.
unsigned fAlignment
alignment boundary for memory
double GetUsedRatio() const
Return relative usage of memory pool buffers.
bool Allocate(BufferSize_t bufsize=0, unsigned number=0)
Allocates memory for the memory pool and creates references.
bool _GetPoolInfo(std::vector< void * > &bufs, std::vector< unsigned > &sizes, unsigned *changecnt=0)
Return pointers and sizes of all memory buffers in the pool Could be used by devices and transport to...
Buffer TakeBuffer(BufferSize_t size=0)
Returns Buffer object with exclusive access rights.
static unsigned GetDfltAlignment()
bool fProcessingReq
flag indicate if memory pool processing requests, for debug purposes
virtual bool Find(ConfigIO &cfg)
Method to locate object in xml file.
static void SetDfltBufSize(unsigned v)
unsigned GetMinBufSize() const
Return minimum buffer size in the pool.
unsigned GetAlignment() const
Following methods should be used after memory pool is created.
bool RecheckRequests(bool from_recv=false)
unsigned GetNumBuffers() const
Returns number of preallocated buffers.
MemoryPool(const std::string &name, bool withmanager=false)
void DecreaseSegmRefs(MemSegment *segm, unsigned num)
Decrease references of specified segments.
bool ProcessSend(unsigned port)
Method called by framework when at least one buffer can be send to output port.
void ReplyReadyRequests()
Inform requesters, that buffer is provided.
virtual void ProcessConnectEvent(const std::string &name, bool on)
Method called by framework when connection state of the item is changed.
static unsigned fDfltBufSize
default buffer size
void * GetBufferLocation(unsigned id) const
Returns location of preallocated buffer.
static unsigned GetDfltBufSize()
bool fUseThread
indicate if thread functionality should be used to process supplied requests
Reference on dabc::ModuleAsync class
Base class for user-derived code, implementing event-processing.
virtual void OnThreadAssigned()
Mutex * ObjectMutex() const
Returns mutex, used for protection of Object data members.
Reference on the arbitrary object
Object * GetObject() const
Return pointer on the object.
bool HasThread() const
Indicates if pointer on thread is not zero; thread-safe.
const char * xmlBufferSize
const char * xmlAlignment
const char * xmlNumBuffers
Event structure, exchanged between DABC threads.
Structure with descriptor of single memory segment.