SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | List of all members
Mailbox< Item > Class Template Reference

#include <Mailbox.h>

Public Member Functions

 Mailbox (const char *name, int size)
 
 ~Mailbox ()
 
void send (const Item &msg)
 
bool trySend (const Item &msg)
 
bool sendIfNotSentLast (const Item &msg, bool(*checker)(const Item &a, const Item &b))
 
Item receive ()
 
bool tryReceive (Item &item)
 
int size () const
 
int numItems () const
 Return the number of items currently in the queue. More...
 

Constructor & Destructor Documentation

Mailbox ( const char *  name,
int  size 
)

Create a mailbox with a maximum queue size of size items. If size is zero, then the mailbox will use rendevous semantics, where a sender will block until a reciever is waiting for the item. The item will be handed off synchronously. name should be a static string which describes the primitive for debugging purposes.

~Mailbox ( )

Destroy the mailbox. All items in the queue are silently dropped.

Member Function Documentation

int numItems ( ) const

Return the number of items currently in the queue.

Item receive ( )

Receive an item from the queue. If the queue is empty, the thread will block until another thread sends an item. Multiple threads may call recieve concurrently, but no guarantee is made as to which thread will recieve the next token. However, implementors should give preference to the thread that has been waiting the longest.

void send ( const Item &  msg)

Puts msg in the queue. If the queue is full, the thread will be blocked until there is room in the queue. Messages from the same thread will be placed in the queue in a first-in/first out order. Multiple threads may call send concurrently, and the messages will be placed in the queue in an arbitrary order.

bool sendIfNotSentLast ( const Item &  msg,
bool(*)(const Item &a, const Item &b)  checker 
)

Send msg to the queue only if the checker function fails to compare the msg to what is already the last item there. This is useful if we want to make certain that at least one of a particular message (like a viewer resize redraw) gets put on the mailbox without spamming it. This blocks like send does. It returns true if msg was added to the queue and false if it wasn't.

int size ( ) const

Return the maximum size of the mailbox queue, as given in the constructor.

bool tryReceive ( Item &  item)

Attempt to recieve item from the mailbox. If the queue is empty, the thread is blocked and tryRecieve will return false. Otherwise, tryRecieve returns true.

bool trySend ( const Item &  msg)

Attempt to send msg to the queue. If the queue is full, the thread will not be blocked, and trySend will return false. Otherwise, trySend will return true. This may never complete if the reciever only uses tryRecieve.


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