IPQ (InterProcessQueue) provides a generic way for information to be shared between processes or threads.
More...
|
int | getElementSize () const |
| Returns the size of each element in the queue in bytes. More...
|
|
::std::string | getFileName () const |
| Get the filename. More...
|
|
unsigned int | getGetOffset () const |
| Useful only for debugging. More...
|
|
unsigned int | getLostElementCount () const |
| Get the number of elements lost on the last read. More...
|
|
unsigned int | getMaxOffset () const |
| Useful only for debugging. More...
|
|
int | getNumAvailable () const |
| Gets the number of unread elements available in the queue. More...
|
|
unsigned int | getPutOffset () const |
| Used internally, but made public for debugging. More...
|
|
int | getQueueSize () const |
| Returns the allocated size of the queue. More...
|
|
bool | isDataAvailable () const |
| Checks to see if there are any unread elements (would a read not block?). More...
|
|
bool | isEmpty () const |
| Checks to see if the queue is empty. More...
|
|
unsigned int | read () |
| Read the oldest unread element from the queue. More...
|
|
bool | readNewest () |
| Get the newest element from the queue (with locking). More...
|
|
bool | readNewestConditionalCopy () |
| Reads and copies the newest element from the queue into the localElement buffer, but only if has not been previously read. More...
|
|
void | setNoneAvailable () |
| Sets the number of available (unread) elements to zero (catches up) More...
|
|
virtual | ~IPQbufferBase () |
| Destructor Making this d'tor virtual causes the d'tors of inheriting classes to be called first when the d'tor is called on this base class (polymorphic), followed by the base class d'tor. More...
|
|
virtual int | getElementSize () const =0 |
| Returns the size of each element in the queue in bytes. More...
|
|
virtual ::std::string | getFileName () const =0 |
| Get the filename. More...
|
|
virtual unsigned int | getGetOffset () const =0 |
| Useful only for debugging. More...
|
|
virtual unsigned int | getLostElementCount () const =0 |
| Get the number of elements lost on the last read. More...
|
|
virtual unsigned int | getMaxOffset () const =0 |
| Useful only for debugging. More...
|
|
virtual int | getNumAvailable () const =0 |
| Gets the number of unread elements available in the queue. More...
|
|
virtual unsigned int | getPutOffset () const =0 |
|
virtual int | getQueueSize () const =0 |
| Returns the allocated size of the queue. More...
|
|
virtual bool | isDataAvailable () const =0 |
| Checks to see if there are any unread elements (would a read not block?). More...
|
|
virtual bool | isEmpty () const =0 |
| Checks to see if the queue is empty. More...
|
|
virtual unsigned int | read ()=0 |
| Read the oldest unread element from the queue. More...
|
|
virtual bool | readNewest ()=0 |
| Get the newest element from the queue (with locking). More...
|
|
virtual bool | readNewestConditionalCopy ()=0 |
| Reads and copies the newest element from the queue into the localElement buffer, but only if has not been previously read. More...
|
|
virtual void | setNoneAvailable ()=0 |
| Sets the number of available (unread) elements to zero (catches up) More...
|
|
virtual | ~IPQinterface ()=0 |
| Destructor Making this d'tor virtual causes the d'tors of inheriting classes to be called first when the d'tor is called on this base class (polymorphic), followed by the base class d'tor. More...
|
|
|
virtual bool | createBuffer ()=0 |
| Create a new file or shared memory. More...
|
|
::std::string | getTrimmedFilename () |
| Get the trimmed filename. More...
|
|
void | init () |
| This does all the real constructor work. More...
|
|
| IPQbufferBase (void *localElement, int elementSize, const ::std::string &filename, bool isCreator=false, int nElements=0, unsigned int testOffset=0) |
| Constructor for a read/write queue. More...
|
|
virtual bool | openBuffer ()=0 |
| Open an existing file or shared memory. More...
|
|
void | trimShmemFilename () |
| Shared memory filenames must contain only one '/' and it must be the first character; this routine fixes up the filename. More...
|
|
void | write () |
| Put an element into the queue. More...
|
|
virtual void | write ()=0 |
| Useful only for debugging. More...
|
|
IPQ (InterProcessQueue) provides a generic way for information to be shared between processes or threads.
The queues are fixed in length (number of elements) and width (element size). The queues may be transient in shared memory or persistent in memory mapped files with these implementations provides by classes that implement the abstract methods of this class. This buffer class provides the actual storage mechanism. It also provides read and write methods to be inherited by the derived classes. This class throws exceptions, in particular on the constructor and the write methods, so make sure you catch them! Because this is a circular queue, if the reader falls more than the queue depth behind the writer then elements will be overwritten that can never be read and are lost forever. The read methods returns the number of lost elements.
Note that each instance of reader has its own set of pointers to keep track of where it is in the queue. A single instance shared by multiple threads has this feature, so it may only be useful if one of the threads is designated as the master reader. An exception is if the threads are just reading the most recent element off the top of the queue, in other words not really using the queue feature but more as a data sharing mechanism between writers and readers.
Some facts about Linux interactions with this class.
-
Shared memory is limited in size to half the physical memory size.
-
Shared memory exists in /dev/shm and can be deleted just like any file.
-
If you are using large objects (structures) for the elements, you can run into limitations caused by stack size. Increase stacksize with:
-
csh(limit stacksize <sizeKB>) or
-
sh(ulimit [-S][-H] -s <sizeKB>
-
Shared memory is much faster than a memory mapped file.
-
Memory mapped files off a fileserver are very slow.
-
Memory mapped files are limited to 2GB in size.
- See Also
- IPQreader, IPQwriter
Definition at line 77 of file IPQbufferBase.h.