Homepage Demos Overview Downloads Tutorials Reference
Credits

SharedQueue< maxsize, maxentries > Class Template Reference

#include <SharedQueue.h>

Inheritance diagram for SharedQueue< maxsize, maxentries >:

Inheritance graph
[legend]
List of all members.

Detailed Description

template<unsigned int maxsize, unsigned int maxentries>
class SharedQueue< maxsize, maxentries >

SharedQueue is a shared memory message buffer for interprocess communication.

This doesn't gain you much functionality over the Aperios messages - in fact, you lose some because you have to poll this for new data whereas Aperios will notify you.

However, the big advantage of this is that you don't have any lag time from the system in sending the message from one process to the other - it's instantly available. Also, you can poll for new data from within a loop, whereas you cannot check to see if you have any messages waiting from Aperios until you exit to the system.

This makes no assumptions about the data to be stored - it's all just an array of bytes

Assumptions are made about reception usage: all entries will be processed and then cleared so that the queue is emptied. You cannot pop the front, only clear the whole thing. This assumption allows much simpler/faster access. (Otherwise we need to implement a circular buffer and worry about wrap around. *shrug* Not too hard, but unnecessary complication for now.)

Definition at line 27 of file SharedQueue.h.

Public Member Functions

 SharedQueue ()
 constructor

template<class T> bool SharedQueue (const T &obj)
 inserts a class into the queue

void * reserve (unsigned int size)
 reserves a number of bytes in the queue, LEAVES QUEUE LOCKED, call done when finished

void done ()
 call this when you're finished filling in a buffer you received from reserve

bool clear (unsigned int taken)
 checks to see if the number taken by the reader is the number added, and then clears

unsigned int size () const
 returns current number of entries

unsigned int size (unsigned int i) const
 returns size of entry i

const void * data (unsigned int i) const
 returns data of entry i


Static Public Attributes

const unsigned int MAX_SIZE = maxsize
 maximum capacity of data storage for the queue

const unsigned int MAX_ENTRIES = maxentries
 maximum number of entries that can be queued


Protected Types

typedef LockScope< ProcessID::NumProcesses > AutoLock
 for convenience in locking functions


Protected Member Functions

unsigned int buf_end ()
 returns the first free byte in buf

unsigned int round_up (unsigned int sz)
 returns sz rounded up to the nearest word (makes sz divisible by sizeof(int))


Protected Attributes

MutexLock< ProcessID::NumProcesses > lock
 provides mutual exclusion on non-const functions

char buf [MAX_SIZE]
 data storage

unsigned int len
 holds number of entries

entry_t entries [MAX_ENTRIES]
 holds entry information


Member Typedef Documentation

template<unsigned int maxsize, unsigned int maxentries>
typedef LockScope<ProcessID::NumProcesses> SharedQueue< maxsize, maxentries >::AutoLock [protected]
 

for convenience in locking functions

Definition at line 71 of file SharedQueue.h.

Referenced by SharedQueue< maxsize, maxentries >::clear(), and SharedQueue< maxsize, maxentries >::reserve().


Constructor & Destructor Documentation

template<unsigned int maxsize, unsigned int maxentries>
SharedQueue< maxsize, maxentries >::SharedQueue  ) 
 

constructor

Definition at line 90 of file SharedQueue.h.

template<unsigned int maxsize, unsigned int maxentries>
template<class T>
bool SharedQueue< maxsize, maxentries >::SharedQueue const T &  obj  ) 
 

inserts a class into the queue


Member Function Documentation

template<unsigned int maxsize, unsigned int maxentries>
unsigned int SharedQueue< maxsize, maxentries >::buf_end  )  [inline, protected]
 

returns the first free byte in buf

Definition at line 63 of file SharedQueue.h.

Referenced by SharedQueue< maxsize, maxentries >::reserve().

template<unsigned int maxsize, unsigned int maxentries>
bool SharedQueue< maxsize, maxentries >::clear unsigned int  taken  ) 
 

checks to see if the number taken by the reader is the number added, and then clears

This will allow you to process entries without locking the entire queue, but still not worry about missing one (or more) if it was added while you were processing the last one.

Definition at line 124 of file SharedQueue.h.

Referenced by EventTranslator::translateEvents().

template<unsigned int maxsize, unsigned int maxentries>
const void* SharedQueue< maxsize, maxentries >::data unsigned int  i  )  const [inline]
 

returns data of entry i

Definition at line 59 of file SharedQueue.h.

Referenced by EventTranslator::translateEvents().

template<unsigned int maxsize, unsigned int maxentries>
void SharedQueue< maxsize, maxentries >::done  )  [inline]
 

call this when you're finished filling in a buffer you received from reserve

Definition at line 44 of file SharedQueue.h.

Referenced by EventTranslator::enqueue().

template<unsigned int maxsize, unsigned int maxentries>
void * SharedQueue< maxsize, maxentries >::reserve unsigned int  size  ) 
 

reserves a number of bytes in the queue, LEAVES QUEUE LOCKED, call done when finished

Definition at line 111 of file SharedQueue.h.

Referenced by EventTranslator::enqueue().

template<unsigned int maxsize, unsigned int maxentries>
unsigned int SharedQueue< maxsize, maxentries >::round_up unsigned int  sz  )  [inline, protected]
 

returns sz rounded up to the nearest word (makes sz divisible by sizeof(int))

Definition at line 66 of file SharedQueue.h.

Referenced by SharedQueue< maxsize, maxentries >::reserve().

template<unsigned int maxsize, unsigned int maxentries>
unsigned int SharedQueue< maxsize, maxentries >::size unsigned int  i  )  const [inline]
 

returns size of entry i

Definition at line 56 of file SharedQueue.h.

template<unsigned int maxsize, unsigned int maxentries>
unsigned int SharedQueue< maxsize, maxentries >::size  )  const [inline]
 

returns current number of entries

Definition at line 53 of file SharedQueue.h.

Referenced by SharedQueue< maxsize, maxentries >::clear(), and EventTranslator::translateEvents().


Member Data Documentation

template<unsigned int maxsize, unsigned int maxentries>
char SharedQueue< maxsize, maxentries >::buf[MAX_SIZE] [protected]
 

data storage

Definition at line 74 of file SharedQueue.h.

Referenced by SharedQueue< 3 *1024, 100 >::data(), and SharedQueue< maxsize, maxentries >::reserve().

template<unsigned int maxsize, unsigned int maxentries>
entry_t SharedQueue< maxsize, maxentries >::entries[MAX_ENTRIES] [protected]
 

holds entry information

Definition at line 86 of file SharedQueue.h.

Referenced by SharedQueue< 3 *1024, 100 >::buf_end(), SharedQueue< 3 *1024, 100 >::data(), SharedQueue< maxsize, maxentries >::reserve(), and SharedQueue< 3 *1024, 100 >::size().

template<unsigned int maxsize, unsigned int maxentries>
unsigned int SharedQueue< maxsize, maxentries >::len [protected]
 

holds number of entries

Definition at line 83 of file SharedQueue.h.

Referenced by SharedQueue< 3 *1024, 100 >::buf_end(), SharedQueue< maxsize, maxentries >::clear(), SharedQueue< maxsize, maxentries >::reserve(), and SharedQueue< 3 *1024, 100 >::size().

template<unsigned int maxsize, unsigned int maxentries>
MutexLock<ProcessID::NumProcesses> SharedQueue< maxsize, maxentries >::lock [protected]
 

provides mutual exclusion on non-const functions

Definition at line 69 of file SharedQueue.h.

Referenced by SharedQueue< maxsize, maxentries >::clear(), SharedQueue< 3 *1024, 100 >::done(), and SharedQueue< maxsize, maxentries >::reserve().

template<unsigned int maxsize, unsigned int maxentries>
const unsigned int SharedQueue< maxsize, maxentries >::MAX_ENTRIES = maxentries [static]
 

maximum number of entries that can be queued

Definition at line 32 of file SharedQueue.h.

Referenced by SharedQueue< maxsize, maxentries >::reserve().

template<unsigned int maxsize, unsigned int maxentries>
const unsigned int SharedQueue< maxsize, maxentries >::MAX_SIZE = maxsize [static]
 

maximum capacity of data storage for the queue

Definition at line 30 of file SharedQueue.h.

Referenced by SharedQueue< maxsize, maxentries >::reserve().


The documentation for this class was generated from the following file:
Tekkotsu v2.0
Generated Wed Jan 21 03:23:26 2004 by Doxygen 1.3.4