DABC (Data Acquisition Backbone Core)  2.9.9
Data Structures | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends
dabc::MemoryPool Class Reference

#include <dabc/MemoryPool.h>

Inheritance diagram for dabc::MemoryPool:
dabc::ModuleAsync dabc::Module dabc::Worker dabc::Object verbs::MemoryPool

Data Structures

struct  RequesterReq
 

Public Member Functions

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 map all buffers into internal structures. More...
 
bool Allocate (BufferSize_t bufsize=0, unsigned number=0) throw ()
 Allocates memory for the memory pool and creates references. More...
 
bool Assign (bool isowner, const std::vector< void * > &bufs, const std::vector< unsigned > &sizes) throw ()
 This is alternative method to supply memory to the pool. More...
 
bool CheckChangeCounter (unsigned &cnt)
 Check if memory pool structure was changed since last call, do not involves memory pool mutex. More...
 
virtual const char * ClassName () const
 Returns class name of the object. More...
 
unsigned GetAlignment () const
 Following methods should be used after memory pool is created. More...
 
void * GetBufferLocation (unsigned id) const
 Returns location of preallocated buffer. More...
 
unsigned GetBufferSize (unsigned id) const
 Returns size of preallocated buffer. More...
 
unsigned GetMaxBufSize () const
 Return maximum buffer size in the pool. More...
 
unsigned GetMaxNumSegments () const
 Returns number of preallocated segments. More...
 
unsigned GetMinBufSize () const
 Return minimum buffer size in the pool. More...
 
unsigned GetNumBuffers () const
 Returns number of preallocated buffers. More...
 
bool GetPoolInfo (std::vector< void * > &bufs, std::vector< unsigned > &sizes)
 Return pointers and sizes of all memory buffers in the pool. More...
 
MutexGetPoolMutex () const
 
double GetUsedRatio () const
 Return relative usage of memory pool buffers. More...
 
bool IsEmpty () const
 Return true, if memory pool is not yet created. More...
 
 MemoryPool (const std::string &name, bool withmanager=false)
 
bool Reconstruct (Command cmd)
 Reconstruct memory pool base on command configuration. More...
 
bool Release () throw ()
 Release memory and structures, allocated by memory pool. More...
 
bool SetAlignment (unsigned align)
 Following methods could be used for configuration of pool before memory pool is allocated. More...
 
Buffer TakeBuffer (BufferSize_t size=0) throw ()
 Returns Buffer object with exclusive access rights. More...
 
virtual ~MemoryPool ()
 
- Public Member Functions inherited from dabc::Module
std::string GetInfoParName () const
 
- Public Member Functions inherited from dabc::Worker
bool ActivateTimeout (double tmout_sec)
 Method used to produce timeout events in the worker. More...
 
Command Assign (Command cmd)
 ! Assign command with processor before command be submitted to other processor This produce ReplyCommand() call when command execution is finished Command itself returned if operation was successful, otherwise null() command More...
 
void AssignAddon (WorkerAddon *addon)
 Assigns addon to the worker Should be called before worker assigned to the thread. More...
 
bool AssignToThread (ThreadRef thrd, bool sync=true)
 Assign worker to thread, worker becomes active immediately. More...
 
bool CanSubmitCommand () const
 Returns true if command can be submitted to worker. More...
 
RecordField Cfg (const std::string &name, Command cmd=nullptr) const
 Returns configuration field of specified name Configuration value of specified name searched in following places: More...
 
bool DettachFromThread ()
 Detach worker from the thread, later worker can be assigned to some other thread Method especially useful to normally finish object recursion (if it possible). More...
 
bool Execute (Command cmd, double tmout=-1.)
 Execute command in the processor. More...
 
bool Execute (const std::string &cmd, double tmout=-1.)
 
bool HasThread () const
 Indicates if pointer on thread is not zero; thread-safe. More...
 
bool IsOwnThread () const
 Returns true if called from thread. More...
 
bool MakeThreadForWorker (const std::string &thrdname="")
 Creates appropriate thread for worker and assign worker to the thread. More...
 
Parameter Par (const std::string &name) const
 Returns reference on worker parameter object. More...
 
virtual std::string RequiredThrdClass () const
 Method returns name of required thread class for processor. More...
 
void SetWorkerPriority (int nq)
 
bool Submit (Command cmd)
 Submit command for execution in the processor. More...
 
ThreadRef thread ()
 Return reference on the worker thread; thread-safe. More...
 
std::string ThreadName () const
 Returns name of the worker thread; thread-safe
More...
 
 Worker (Reference parent, const std::string &name)
 
std::string WorkerAddress (bool full=true)
 Return address, which can be used to submit command to the worker If full specified, command can be submitted from any node, which has connection to this node. More...
 
uint32_t WorkerId () const
 
int WorkerPriority () const
 
virtual ~Worker ()
 
- Public Member Functions inherited from dabc::Object
bool AddChild (Object *child, bool withmutex=true) throw ()
 Add object to list of child objects, thread safe More...
 
bool AddChildAt (Object *child, unsigned pos, bool withmutex=true)
 Add object to list of child objects at specified position. More...
 
ObjectFindChild (const char *name) const
 returns pointer on child object with given name More...
 
Reference FindChildRef (const char *name, bool force=false) const throw ()
 returns reference on child object with given name More...
 
bool GetAllChildRef (ReferencesVector *vect) const
 
ObjectGetChild (unsigned n) const
 returns pointer on child object More...
 
Reference GetChildRef (unsigned n) const
 returns reference on child object More...
 
Reference GetFolder (const std::string &name, bool force=false) throw ()
 Return folder of specified name, no special symbols allowed. More...
 
const char * GetName () const
 Returns name of the object, thread safe More...
 
ObjectGetParent () const
 Returns pointer on parent object, thread safe More...
 
Reference GetParentRef () const
 
bool IsChildsHidden () const
 Return true if object wants to hide childs from hierarchy scan, thread safe More...
 
bool IsHidden () const
 Return true if object wants to be hidden from hierarchy scan, thread safe More...
 
bool IsLogging () const
 Return true if object selected for logging, thread safe More...
 
bool IsName (const char *str) const
 Checks if object name is same as provided string, thread safe More...
 
bool IsName (const char *str, int len) const
 Checks if object name is same as provided, thread safe More...
 
bool IsName (const std::string &str) const
 Checks if object name is same as provided string, thread safe More...
 
bool IsNameMatch (const std::string &mask) const
 Check if object name match to the mask. More...
 
bool IsOwner () const
 Returns true if object is owner of its children, thread safe More...
 
bool IsParent (Object *obj) const
 Checks if specified argument is in the list of object parents. More...
 
bool IsTopXmlLevel () const
 Return true if object should be searched in the top level of the xml file, thread safe More...
 
std::string ItemName (bool compact=true) const
 Produce string, which can be used as name argument in dabc::mgr.FindItem(name) call. More...
 
unsigned NumChilds () const
 returns number of child objects More...
 
 Object (const std::string &name, unsigned flags=flIsOwner)
 Resolve problem with child-parent mutex locking. More...
 
 Object (Reference parent, const std::string &name, unsigned flags=flIsOwner)
 
virtual void Print (int lvl=0)
 Print object content on debug output. More...
 
bool RemoveChild (Object *child, bool cleanup=true) throw ()
 Detach child from parent object If cleanup==true and parent is owner of child, child will be destroyed. More...
 
bool RemoveChildAt (unsigned n, bool cleanup=true) throw ()
 Detach child object from parent at specified position If cleanup==true and object is owner of child, child will be destroyed. More...
 
bool RemoveChilds (bool cleanup=true)
 Remove all childs. More...
 
void SetLogging (bool on=true)
 Sets logging flag, thread safe More...
 
virtual ~Object ()
 

Static Public Member Functions

static unsigned GetDfltAlignment ()
 
static unsigned GetDfltBufSize ()
 
static void SetDfltAlignment (unsigned v)
 
static void SetDfltBufSize (unsigned v)
 
- Static Public Member Functions inherited from dabc::Worker
static int cmd_bool (bool v)
 
- Static Public Member Functions inherited from dabc::Object
static void Destroy (Object *obj) throw ()
 User method for object destroyment. More...
 
static void InspectGarbageCollector ()
 \ brief Methods to inspect how many objects pointers are remained More...
 
static bool NameMatch (const std::string &name, const std::string &mask)
 Check if name matches to specified mask. More...
 
static bool NameMatchM (const std::string &name, const std::string &mask)
 Check if name matches to specified mask. More...
 
static unsigned NumInstances ()
 Static variable counts total number of objects instances. More...
 

Protected Member Functions

bool _Allocate (BufferSize_t bufsize=0, unsigned number=0) throw ()
 Method to allocate memory for the pool, mutex should be locked. More...
 
bool _ProcessRequests ()
 Process submitted requests, if returns true if any requests was processed. More...
 
Buffer _TakeBuffer (BufferSize_t size, bool except, bool reserve_memory=true)
 Central method, which reserves memory from pool and fill structures of buffer. More...
 
void DecreaseSegmRefs (MemSegment *segm, unsigned num)
 Decrease references of specified segments. More...
 
virtual int ExecuteCommand (Command cmd)
 Main method where commands are executed. More...
 
virtual bool Find (ConfigIO &cfg)
 Method to locate object in xml file. More...
 
void IncreaseSegmRefs (MemSegment *segm, unsigned num)
 Method increases ref.counuters of all segments. More...
 
bool IsSingleSegmRefs (MemSegment *segm, unsigned num)
 Return true when all segments has refcnt==1. More...
 
virtual void OnThreadAssigned ()
 
virtual void ProcessConnectEvent (const std::string &name, bool on)
 Method called by framework when connection state of the item is changed. More...
 
virtual void ProcessConnectionActivated (const std::string &name, bool on)
 Method called when port started or stopped. More...
 
virtual void ProcessEvent (const EventId &)
 
bool ProcessSend (unsigned port)
 Method called by framework when at least one buffer can be send to output port. More...
 
bool RecheckRequests (bool from_recv=false)
 
void ReleaseRawBuffer (unsigned indx)
 Release raw buffer, allocated before by TakeRawBuffer. More...
 
void ReplyReadyRequests ()
 Inform requesters, that buffer is provided. More...
 
bool TakeRawBuffer (unsigned &indx)
 Reserve raw buffer without creating Buffer instance. More...
 
- Protected Member Functions inherited from dabc::ModuleAsync
void ActivateInput (unsigned port=0)
 Produces event for specified input port Should be used when processing was stopped due to return false in ProcessRecv method. More...
 
void ActivateOutput (unsigned port=0)
 Produces event for specified output port. More...
 
void ActivatePool (unsigned pool)
 Produces event for specified pool handle. More...
 
bool CanRecv (unsigned indx=0) const
 Method return true if recv from specified port can be done. More...
 
bool CanSend (unsigned indx=0) const
 Method return true if send over specified port can be done. More...
 
bool CanTakeBuffer (unsigned pool=0)
 Returns true if memory pool can provide buffer. More...
 
 ModuleAsync (const std::string &name, Command cmd=nullptr)
 Constructor of ModuleAsync class. More...
 
unsigned NumCanRecv (unsigned indx=0) const
 Method return number of buffers which can be received via the port. More...
 
unsigned NumCanSend (unsigned indx=0) const
 Method return number of send operation can be done for specified port. More...
 
unsigned NumCanTake (unsigned pool=0) const
 Method return number of buffers which could be taken from data queue assigned with the pool. More...
 
Buffer PoolQueueItem (unsigned pool=0, unsigned nbuf=0)
 Returns buffer from queue assigned with the pool. More...
 
virtual bool ProcessBuffer (unsigned pool=0)
 Method called by framework when at least one buffer available in pool handle. More...
 
virtual void ProcessInputEvent (unsigned port)
 Method called by framework when input event is produced. More...
 
virtual void ProcessOutputEvent (unsigned port)
 Method called by framework when output event is produced. More...
 
virtual void ProcessPoolEvent (unsigned pool)
 Method called by framework when pool event is produced. More...
 
virtual bool ProcessRecv (unsigned port=0)
 Method called by framework when at least one buffer available in input port. More...
 
virtual void ProcessTimerEvent (unsigned timer)
 Method called by framework when timer event is produced. More...
 
virtual void ProcessUserEvent (unsigned item)
 Method called by framework when custom user event is produced. More...
 
Buffer Recv (unsigned indx=0)
 Methods receives buffers from the port. More...
 
bool RecvQueueFull (unsigned port=0)
 Returns true if receive queue is full and block input. More...
 
Buffer RecvQueueItem (unsigned port=0, unsigned nbuf=0)
 Returns buffer from receive queue of the input port. More...
 
bool Send (Buffer &buf)
 Send buffer over first output port. More...
 
bool Send (unsigned indx, Buffer &buf)
 Methods to send buffer via specified output port. More...
 
void SignalRecvWhenFull (unsigned port=0)
 Let input signal only when queue is full. More...
 
bool SkipInputBuffers (unsigned indx=0, unsigned nbuf=1)
 Remove items in input queue. More...
 
Buffer TakeBuffer (unsigned pool=0)
 Take buffer from memory pool. More...
 
BufferSize_t TotalSizeCanRecv (unsigned indx=0) const
 Method return total size of buffers can be received via the port. More...
 
virtual ~ModuleAsync ()
 Destructor of ModuleAsync class. More...
 
- Protected Member Functions inherited from dabc::Module
virtual void AfterModuleStop ()
 
virtual void BeforeModuleStart ()
 
bool BindPorts (const std::string &inpname, const std::string &outname)
 Bind input and output ports that both will share same connection. More...
 
virtual void BuildFieldsMap (RecordFieldsMap *cont)
 Fill fields map, which is relevant for the object Objects hierarchy produced from dabc::Manager. More...
 
bool CanSendToAllOutputs (bool exclude_disconnected=true) const
 
EventId ConstructUserItemEvent (unsigned indx=0)
 
unsigned CreateInput (const std::string &name, unsigned queue=10)
 
unsigned CreateOutput (const std::string &name, unsigned queue=10)
 
virtual Parameter CreatePar (const std::string &name, const std::string &kind="")
 
unsigned CreatePoolHandle (const std::string &poolname, unsigned queue=10)
 Creates handle for memory pool, which preserves reference on memory pool and provides fast access to memory pool functionality. More...
 
unsigned CreateTimer (const std::string &name, double period_sec=-1., bool synchron=false)
 
unsigned CreateUserItem (const std::string &name)
 
void DisconnectAllPorts (bool witherr=false)
 Method disconnects all module ports, should be called only from Module thread. More...
 
bool DisconnectPort (const std::string &name, bool witherr=false)
 Disconnect port from transport. More...
 
virtual bool DoStop ()
 
void EnsurePorts (unsigned numinp=0, unsigned numout=0, const std::string &poolname="")
 Method ensure that at least specified number of input and output ports will be created. More...
 
unsigned FindInput (const std::string &name) const
 
unsigned FindOutput (const std::string &name) const
 
unsigned FindPool (const std::string &name) const
 
PortRef FindPort (const std::string &name) const
 
unsigned FindTimer (const std::string &name)
 
unsigned FindUserItem (const std::string &name)
 
ModuleItemGetItem (unsigned id) const
 
std::string InputName (unsigned indx=0, bool fullname=false) const
 
unsigned InputQueueCapacity (unsigned indx=0) const
 
bool InputQueueFull (unsigned indx=0) const
 
bool IsAutoPool (unsigned indx=0) const
 Returns true when handle automatically delivers buffers via the connection. More...
 
bool IsInputConnected (unsigned indx=0) const
 
bool IsOutputConnected (unsigned indx=0) const
 
bool IsPoolConnected (unsigned indx=0) const
 
bool IsPortConnected (const std::string &name) const
 
bool IsRunning () const
 Returns true if module if running. More...
 
bool IsValidInput (unsigned indx=0) const
 
bool IsValidOutput (unsigned indx=0) const
 
bool IsValidPool (unsigned indx=0) const
 
bool IsValidTimer (unsigned indx) const
 
bool IsValidUserItem (unsigned indx) const
 
virtual void ModuleCleanup ()
 Method, which can be reimplemented by user and should cleanup all references on buffers and other objects. More...
 
unsigned NumInputs () const
 
unsigned NumOutputs () const
 
unsigned NumPools () const
 
unsigned NumTimers () const
 
virtual void ObjectCleanup ()
 Inherited method, called during module destroy. More...
 
std::string OutputName (unsigned indx=0, bool fullname=false) const
 
unsigned OutputQueueCapacity (unsigned indx=0) const
 
std::string PoolName (unsigned indx=0, bool fullname=false) const
 
unsigned PortQueueCapacity (const std::string &name) const
 
virtual int PreviewCommand (Command cmd)
 This method called before command will be executed. More...
 
virtual double ProcessTimeout (double last_diff)
 
void ProduceInputEvent (unsigned indx=0, unsigned cnt=1)
 
void ProduceOutputEvent (unsigned indx=0, unsigned cnt=1)
 
void ProducePoolEvent (unsigned indx=0, unsigned cnt=1)
 
void ProduceUserItemEvent (unsigned indx=0, unsigned cnt=1)
 
virtual bool ReplyCommand (Command cmd)
 Reimplement this method to react on command reply Return true if command can be destroyed by framework. More...
 
void SendToAllOutputs (Buffer &buf)
 
void SetAutoStop (bool on=true)
 If set, module will be automatically stopped when all i/o ports are disconnected. More...
 
void SetInfoParName (const std::string &name)
 
virtual void SetModulePriority (int pri=-1)
 
bool SetPortLoopLength (const std::string &name, unsigned cnt)
 
bool SetPortRatemeter (const std::string &name, const Parameter &ref)
 
bool SetPortSignaling (const std::string &name, Port::EventsProducing signal)
 
void ShootTimer (const std::string &name, double delay_sec=0.)
 
void ShootTimer (unsigned indx, double delay_sec=0.)
 
bool Start ()
 Starts execution of the module code. More...
 
bool Stop ()
 Stops execution of the module code. More...
 
bool SubmitCommandToTransport (const std::string &portname, Command cmd)
 Submits command to transport, assigned with the port. More...
 
std::string TimerName (unsigned n=0, bool fullname=false) const
 
std::string UserItemName (unsigned indx=0, bool fullname=false) const
 
- Protected Member Functions inherited from dabc::Worker
bool _FireDoNothingEvent ()
 
bool _FireEvent (uint16_t evid)
 
bool _FireEvent (uint16_t evid, uint32_t arg, int pri=-1)
 
bool _IsFireEvent () const
 
bool ActivateMainLoop ()
 
virtual void BeforeHierarchyScan (Hierarchy &h)
 Method called before publisher makes next snapshot of hierarchy. More...
 
void CancelCommands ()
 
void CleanupPublisher (bool sync=true)
 Release reference on publisher and unsubscribe/unpublish all registered entries. More...
 
CommandDefinition CreateCmdDef (const std::string &name)
 
virtual bool DestroyByOwnThread ()
 Inherited method from Object, invoked at the moment when worker requested to be destroyed by its thread. More...
 
bool DestroyPar (const std::string &name)
 Method must be used if worker wants to destroy parameter. More...
 
virtual void DoWorkerAfterMainLoop ()
 Internal - function executed after leaving main loop. More...
 
virtual void DoWorkerMainLoop ()
 Internal - entrance function for main loop execution. More...
 
bool ExecuteIn (Worker *dest, Command cmd)
 Executes command in specified worker. More...
 
bool FireEvent (uint16_t evid)
 
bool FireEvent (uint16_t evid, uint32_t arg, int pri=-1)
 
Reference GetPublisher ()
 Return reference on publisher. More...
 
bool IsWorkerActive () const
 Method indicates if worker is running in the thread and accepts normal events. More...
 
virtual void ObjectDestroyed (Object *)
 Method to clear object reference, will be called from thread context (when possible) More...
 
virtual void ProcessParameterEvent (const ParameterEvent &evnt)
 Interface method to retrieve subscribed parameter events. More...
 
virtual bool Publish (const Hierarchy &h, const std::string &path)
 
virtual bool PublishPars (const std::string &path)
 
bool RegisterForParameterEvent (const std::string &mask, bool onlychangeevent=true)
 Subscribe to parameter events from local or remote node. More...
 
void SetParValue (const std::string &name, const RecordField &v)
 Set parameter value and sync with worker hierarchy. More...
 
void SetWorkerCfgId (int id=-1)
 Set identifier which can be used in XML configuration ${}# formula It means that correspondent to the ID element of array will be extracted. More...
 
bool SingleLoop (double tmout)
 
virtual bool Subscribe (const std::string &path)
 
virtual bool Unpublish (const Hierarchy &h, const std::string &path)
 
bool UnregisterForParameterEvent (const std::string &mask)
 Unsubscribe to parameter events from local or remote node. More...
 
virtual bool Unsubscribe (const std::string &path)
 
 Worker (const ConstructorPair &pair)
 Special constructor, designed for inherited classes. More...
 
void WorkerSleep (double tmout)
 
- Protected Member Functions inherited from dabc::Object
virtual void _ChildsChanged ()
 Method called when new childs are add or old are removed. More...
 
virtual bool _DoDeleteItself ()
 This method is called at the moment when DecReference think that object can be destroyed and wants to return true. More...
 
bool _IsNormalState ()
 Same as IsNormalState() but without mutex lock - user should lock mutex himself. More...
 
virtual ObjectCreateInstance (const std::string &name)
 Method used to create new item to be placed as child of the object. More...
 
void DeleteThis ()
 Method should be used by the object to delete itself. More...
 
bool DestroyCalledFromOwnThread ()
 Internal DABC method, should be called by thread which was requested to destroy object. More...
 
void FillFullName (std::string &fullname, Object *upto, bool exclude_top_parent=false) const
 Method used to produce full item name,. More...
 
bool GetFlag (unsigned fl) const
 Return value of selected flag, not thread safe
More...
 
bool IsNormalState ()
 Return true if object is in normal state. More...
 
unsigned NumReferences ()
 Return number of references on the object. More...
 
 Object (const ConstructorPair &pair, unsigned flags=flIsOwner)
 
MutexObjectMutex () const
 Returns mutex, used for protection of Object data members. More...
 
void SetAutoDestroy (bool on=true)
 Set autodestroy flag for the object Once enabled, object will be destroyed when last reference will be cleared. More...
 
void SetFlag (unsigned fl, bool on=true)
 Change value of selected flag, not thread safe
More...
 
void SetName (const char *name)
 Changes object name. More...
 
void SetNameDirect (const char *name)
 Changes object name disregard of existing references. More...
 
void SetOwner (bool on=true)
 Specifies if object will be owner of its new childs. More...
 

Protected Attributes

unsigned fAlignment
 alignment boundary for memory More...
 
unsigned fChangeCounter
 memory pool change counter, incremented every time memory is allocated or freed More...
 
bool fEvntFired
 indicates if event was fired to process memory requests More...
 
MemoryBlockfMem
 list of preallocated memory More...
 
Queue< unsigned, true > fPending
 queue with requester indexes which are waiting release of the memory More...
 
bool fProcessingReq
 flag indicate if memory pool processing requests, for debug purposes More...
 
std::vector< RequesterReqfReqests
 configuration for each output More...
 
bool fUseThread
 indicate if thread functionality should be used to process supplied requests More...
 
- Protected Attributes inherited from dabc::Module
bool fAutoStop
 module will automatically stop when all i/o ports will be disconnected More...
 
dabc::Reference fDfltPool
 direct reference on memory pool, used when no pool handles are not created More...
 
std::string fInfoParName
 full name of parameter, used as info More...
 
std::vector< InputPort * > fInputs
 array of input ports More...
 
std::vector< ModuleItem * > fItems
 map for fast search of module items More...
 
std::vector< OutputPort * > fOutputs
 array of output ports More...
 
std::vector< PoolHandle * > fPools
 array of pools More...
 
std::string fPublishPars
 path where module pars will be published More...
 
bool fRunState
 true if module in the running state More...
 
unsigned fSysTimerIndex
 index of timer, which will be used with module itself More...
 
std::vector< Timer * > fTimers
 array of timers More...
 
std::vector< ModuleItem * > fUsers
 array of user items More...
 
- Protected Attributes inherited from dabc::Worker
WorkerAddonRef fAddon
 extension of worker for some special events More...
 
Reference fPublisher
 reference on publisher, once found, remain until end of object live More...
 
ThreadRef fThread
 reference on the thread, once assigned remain whole time More...
 
MutexfThreadMutex
 pointer on main thread mutex More...
 
bool fWorkerActive
 indicates if worker can submit events to the thread More...
 
int fWorkerCfgId
 special ID, can be used in XML configuration in ${}# formula More...
 
CommandsQueue fWorkerCommands
 all kinds of commands, processed by the worker More...
 
int fWorkerCommandsLevel
 Number of process commands recursion. More...
 
unsigned fWorkerFiredEvents
 indicate current balance between fired and processed events, used to correctly halt worker More...
 
Hierarchy fWorkerHierarchy
 place for publishing of worker parameters More...
 
uint32_t fWorkerId
 worker id in thread list, used for events submit More...
 
int fWorkerPriority
 priority of events, submitted by worker to the thread More...
 
- Protected Attributes inherited from dabc::Object
int fObjectBlock
 counter for blocking calls, as long as non-zero, non of child can be removed More...
 
ReferencesVectorfObjectChilds
 list of the child objects More...
 
unsigned fObjectFlags
 flag, protected by the mutex More...
 
MutexfObjectMutex
 mutex protects all private property of the object More...
 
std::string fObjectName
 object name More...
 
Reference fObjectParent
 reference on the parent object More...
 
int fObjectRefCnt
 accounts how many references existing on the object, thread safe More...
 

Static Protected Attributes

static unsigned fDfltAlignment = 16
 default alignment for memory allocation More...
 
static unsigned fDfltBufSize = 4096
 default buffer size More...
 

Friends

class Buffer
 
class BufferContainer
 
class Manager
 
class MemoryPoolRef
 

Additional Inherited Members

- Public Types inherited from dabc::Worker
enum  EPriotiryLevels { priorityMaximum = 0 , priorityMinimum = -1 , priorityDefault = -7 , priorityMagic = -77 }
 
enum  EWorkerEventsCodes { evntFirstCore = 1 , evntFirstAddOn = 100 , evntFirstSystem = 200 , evntFirstUser = 1000 }
 
- Protected Types inherited from dabc::Object
enum  EFlags {
  flStateMask = 0x000f , flIsOwner = 0x0010 , flCleanup = 0x0020 , flHasThread = 0x0040 ,
  flAutoDestroy = 0x0080 , flLogging = 0x0100 , flNoMutex = 0x0200 , flHidden = 0x0400 ,
  flChildsHidden = 0x0800 , flTopXmlLevel = 0x1000
}
 
- Static Protected Member Functions inherited from dabc::Object
static ConstructorPair MakePair (const std::string &fullname, bool withmanager=true)
 Internal DABC method, used to produce pair - object parent and object name, which is typically should be used as argument in class constructor. More...
 
static ConstructorPair MakePair (Object *prnt, const std::string &fullname, bool withmanager=true)
 Internal DABC method, used to produce pair - object parent and object name, which is typically should be used as argument in class constructor. More...
 
static ConstructorPair MakePair (Reference prnt, const std::string &fullname, bool withmanager=true)
 Internal DABC method, used to produce pair - object parent and object name, which is typically should be used as argument in class constructor. More...
 

Detailed Description

Definition at line 39 of file MemoryPool.h.

Constructor & Destructor Documentation

◆ MemoryPool()

dabc::MemoryPool::MemoryPool ( const std::string &  name,
bool  withmanager = false 
)

Definition at line 137 of file MemoryPool.cxx.

◆ ~MemoryPool()

dabc::MemoryPool::~MemoryPool ( )
virtual

Reimplemented in verbs::MemoryPool.

Definition at line 152 of file MemoryPool.cxx.

Member Function Documentation

◆ Find()

bool dabc::MemoryPool::Find ( ConfigIO cfg)
protectedvirtual

Method to locate object in xml file.

Can be reimplemented in derived classes to check more attributes like class name

Reimplemented from dabc::Module.

Definition at line 157 of file MemoryPool.cxx.

◆ TakeRawBuffer()

bool dabc::MemoryPool::TakeRawBuffer ( unsigned &  indx)
protected

Reserve raw buffer without creating Buffer instance.

Definition at line 318 of file MemoryPool.cxx.

◆ ReleaseRawBuffer()

void dabc::MemoryPool::ReleaseRawBuffer ( unsigned  indx)
protected

Release raw buffer, allocated before by TakeRawBuffer.

Definition at line 326 of file MemoryPool.cxx.

◆ _TakeBuffer()

dabc::Buffer dabc::MemoryPool::_TakeBuffer ( BufferSize_t  size,
bool  except,
bool  reserve_memory = true 
)
protected

Central method, which reserves memory from pool and fill structures of buffer.

Definition at line 333 of file MemoryPool.cxx.

◆ _Allocate()

bool dabc::MemoryPool::_Allocate ( BufferSize_t  bufsize = 0,
unsigned  number = 0 
)
throw (
)
protected

Method to allocate memory for the pool, mutex should be locked.

Definition at line 187 of file MemoryPool.cxx.

◆ _ProcessRequests()

bool dabc::MemoryPool::_ProcessRequests ( )
protected

Process submitted requests, if returns true if any requests was processed.

◆ ReplyReadyRequests()

void dabc::MemoryPool::ReplyReadyRequests ( )
protected

Inform requesters, that buffer is provided.

◆ IncreaseSegmRefs()

void dabc::MemoryPool::IncreaseSegmRefs ( MemSegment segm,
unsigned  num 
)
protected

Method increases ref.counuters of all segments.

Definition at line 423 of file MemoryPool.cxx.

◆ DecreaseSegmRefs()

void dabc::MemoryPool::DecreaseSegmRefs ( MemSegment segm,
unsigned  num 
)
protected

Decrease references of specified segments.

Definition at line 462 of file MemoryPool.cxx.

◆ IsSingleSegmRefs()

bool dabc::MemoryPool::IsSingleSegmRefs ( MemSegment segm,
unsigned  num 
)
protected

Return true when all segments has refcnt==1.

Definition at line 442 of file MemoryPool.cxx.

◆ OnThreadAssigned()

virtual void dabc::MemoryPool::OnThreadAssigned ( )
inlineprotectedvirtual

Reimplemented from dabc::Module.

Definition at line 102 of file MemoryPool.h.

◆ ProcessSend()

bool dabc::MemoryPool::ProcessSend ( unsigned  port)
protectedvirtual

Method called by framework when at least one buffer can be send to output port.

Can be reimplemented by the user. Method should return true is user want method to be called again for next possibility to send buffer

Reimplemented from dabc::ModuleAsync.

Definition at line 483 of file MemoryPool.cxx.

◆ ProcessEvent()

void dabc::MemoryPool::ProcessEvent ( const EventId ev)
protectedvirtual

Reimplemented from dabc::Module.

Definition at line 496 of file MemoryPool.cxx.

◆ ExecuteCommand()

int dabc::MemoryPool::ExecuteCommand ( Command  cmd)
protectedvirtual

Main method where commands are executed.

Reimplemented from dabc::Module.

Definition at line 646 of file MemoryPool.cxx.

◆ ProcessConnectionActivated()

void dabc::MemoryPool::ProcessConnectionActivated ( const std::string &  name,
bool  on 
)
protectedvirtual

Method called when port started or stopped.

We could start buffer sending

Reimplemented from dabc::Module.

Definition at line 678 of file MemoryPool.cxx.

◆ ProcessConnectEvent()

void dabc::MemoryPool::ProcessConnectEvent ( const std::string &  name,
bool  on 
)
protectedvirtual

Method called by framework when connection state of the item is changed.

Can be reimplemented by the user. Called when input/output port or pool handle are connected or disconnected diregard of running state of the module

Reimplemented from dabc::ModuleAsync.

Definition at line 686 of file MemoryPool.cxx.

◆ RecheckRequests()

bool dabc::MemoryPool::RecheckRequests ( bool  from_recv = false)
protected

Definition at line 513 of file MemoryPool.cxx.

◆ ClassName()

virtual const char* dabc::MemoryPool::ClassName ( ) const
inlinevirtual

Returns class name of the object.

Reimplemented from dabc::ModuleAsync.

Definition at line 127 of file MemoryPool.h.

◆ GetPoolMutex()

Mutex* dabc::MemoryPool::GetPoolMutex ( ) const
inline

Definition at line 129 of file MemoryPool.h.

◆ IsEmpty()

bool dabc::MemoryPool::IsEmpty ( ) const

Return true, if memory pool is not yet created.

Definition at line 237 of file MemoryPool.cxx.

◆ SetAlignment()

bool dabc::MemoryPool::SetAlignment ( unsigned  align)

Following methods could be used for configuration of pool before memory pool is allocated.

Set alignment of allocated memory

Definition at line 172 of file MemoryPool.cxx.

◆ Allocate()

bool dabc::MemoryPool::Allocate ( BufferSize_t  bufsize = 0,
unsigned  number = 0 
)
throw (
)

Allocates memory for the memory pool and creates references.

Only can be called for empty memory pool. If no values are specified, requested values, configured by modules are used. TODO: Another alternative is to configure memory pool via xml file

Definition at line 203 of file MemoryPool.cxx.

◆ Assign()

bool dabc::MemoryPool::Assign ( bool  isowner,
const std::vector< void * > &  bufs,
const std::vector< unsigned > &  sizes 
)
throw (
)

This is alternative method to supply memory to the pool.

User could allocate buffers itself and provide it to this method. If specified, memory pool will take ownership over this memory - means free() function will be called to release this memory

Definition at line 209 of file MemoryPool.cxx.

◆ _GetPoolInfo()

bool dabc::MemoryPool::_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 map all buffers into internal structures.

Memory pool mutex must be locked at this point, changecnt can be used to identify if memory pool was changed since last call

Definition at line 294 of file MemoryPool.cxx.

◆ GetPoolInfo()

bool dabc::MemoryPool::GetPoolInfo ( std::vector< void * > &  bufs,
std::vector< unsigned > &  sizes 
)

Return pointers and sizes of all memory buffers in the pool.

Definition at line 311 of file MemoryPool.cxx.

◆ Release()

bool dabc::MemoryPool::Release ( )
throw (
)

Release memory and structures, allocated by memory pool.

Definition at line 223 of file MemoryPool.cxx.

◆ GetAlignment()

unsigned dabc::MemoryPool::GetAlignment ( ) const

Following methods should be used after memory pool is created.

Returns alignment, used for memory pool allocation

Definition at line 181 of file MemoryPool.cxx.

◆ GetMaxNumSegments()

unsigned dabc::MemoryPool::GetMaxNumSegments ( ) const

Returns number of preallocated segments.

◆ GetNumBuffers()

unsigned dabc::MemoryPool::GetNumBuffers ( ) const

Returns number of preallocated buffers.

Definition at line 244 of file MemoryPool.cxx.

◆ GetBufferSize()

unsigned dabc::MemoryPool::GetBufferSize ( unsigned  id) const

Returns size of preallocated buffer.

Definition at line 251 of file MemoryPool.cxx.

◆ GetBufferLocation()

void * dabc::MemoryPool::GetBufferLocation ( unsigned  id) const

Returns location of preallocated buffer.

Definition at line 287 of file MemoryPool.cxx.

◆ GetUsedRatio()

double dabc::MemoryPool::GetUsedRatio ( ) const

Return relative usage of memory pool buffers.

Definition at line 629 of file MemoryPool.cxx.

◆ GetMaxBufSize()

unsigned dabc::MemoryPool::GetMaxBufSize ( ) const

Return maximum buffer size in the pool.

Definition at line 258 of file MemoryPool.cxx.

◆ GetMinBufSize()

unsigned dabc::MemoryPool::GetMinBufSize ( ) const

Return minimum buffer size in the pool.

Definition at line 272 of file MemoryPool.cxx.

◆ TakeBuffer()

dabc::Buffer dabc::MemoryPool::TakeBuffer ( BufferSize_t  size = 0)
throw (
)

Returns Buffer object with exclusive access rights.

Parameters
[in]sizedefines requested buffer area, if = 0 returns next empty buffer If size longer as single buffer, memory pool will try to produce segmented list. Returned object will have at least specified size (means, size can be bigger). In case when memory pool cannot provide specified memory exception will be thrown

Definition at line 409 of file MemoryPool.cxx.

◆ CheckChangeCounter()

bool dabc::MemoryPool::CheckChangeCounter ( unsigned &  cnt)

Check if memory pool structure was changed since last call, do not involves memory pool mutex.

Definition at line 603 of file MemoryPool.cxx.

◆ Reconstruct()

bool dabc::MemoryPool::Reconstruct ( Command  cmd)

Reconstruct memory pool base on command configuration.

If some parameters not specified, configured values from xml file will be used. As very last point, defaults from static variables will be used

Definition at line 612 of file MemoryPool.cxx.

◆ GetDfltAlignment()

static unsigned dabc::MemoryPool::GetDfltAlignment ( )
inlinestatic

Definition at line 210 of file MemoryPool.h.

◆ GetDfltBufSize()

static unsigned dabc::MemoryPool::GetDfltBufSize ( )
inlinestatic

Definition at line 211 of file MemoryPool.h.

◆ SetDfltAlignment()

static void dabc::MemoryPool::SetDfltAlignment ( unsigned  v)
inlinestatic

Definition at line 213 of file MemoryPool.h.

◆ SetDfltBufSize()

static void dabc::MemoryPool::SetDfltBufSize ( unsigned  v)
inlinestatic

Definition at line 214 of file MemoryPool.h.

Friends And Related Function Documentation

◆ Manager

friend class Manager
friend

Definition at line 40 of file MemoryPool.h.

◆ Buffer

friend class Buffer
friend

Definition at line 41 of file MemoryPool.h.

◆ MemoryPoolRef

friend class MemoryPoolRef
friend

Definition at line 42 of file MemoryPool.h.

◆ BufferContainer

friend class BufferContainer
friend

Definition at line 43 of file MemoryPool.h.

Field Documentation

◆ fMem

MemoryBlock* dabc::MemoryPool::fMem
protected

list of preallocated memory

Definition at line 55 of file MemoryPool.h.

◆ fAlignment

unsigned dabc::MemoryPool::fAlignment
protected

alignment boundary for memory

Definition at line 57 of file MemoryPool.h.

◆ fReqests

std::vector<RequesterReq> dabc::MemoryPool::fReqests
protected

configuration for each output

Definition at line 59 of file MemoryPool.h.

◆ fPending

Queue<unsigned, true> dabc::MemoryPool::fPending
protected

queue with requester indexes which are waiting release of the memory

Definition at line 61 of file MemoryPool.h.

◆ fEvntFired

bool dabc::MemoryPool::fEvntFired
protected

indicates if event was fired to process memory requests

Definition at line 63 of file MemoryPool.h.

◆ fProcessingReq

bool dabc::MemoryPool::fProcessingReq
protected

flag indicate if memory pool processing requests, for debug purposes

Definition at line 64 of file MemoryPool.h.

◆ fChangeCounter

unsigned dabc::MemoryPool::fChangeCounter
protected

memory pool change counter, incremented every time memory is allocated or freed

Definition at line 66 of file MemoryPool.h.

◆ fUseThread

bool dabc::MemoryPool::fUseThread
protected

indicate if thread functionality should be used to process supplied requests

Definition at line 68 of file MemoryPool.h.

◆ fDfltAlignment

unsigned dabc::MemoryPool::fDfltAlignment = 16
staticprotected

default alignment for memory allocation

Definition at line 70 of file MemoryPool.h.

◆ fDfltBufSize

unsigned dabc::MemoryPool::fDfltBufSize = 4096
staticprotected

default buffer size

Definition at line 71 of file MemoryPool.h.


The documentation for this class was generated from the following files: