Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/Posix/Mailbox.hpp

Go to the documentation of this file.
00001 #ifndef __J2K__Mailbox_HPP__
00002 #define __J2K__Mailbox_HPP__
00003 
00004 /*
00005 We use a Mutex to protect the Mailbox LinkList to be
00006 used or modify by more than one message sender at a given time.
00007 */
00008 
00009 #include <j2k/Fred/Standard.hpp>
00010 #include <j2k/445/DList_pchar.hpp>
00011 #include <j2k/445/Posix/Mutex.hpp>
00012 
00013 class Mailbox {
00014 public:
00015   Mailbox() {
00016     queue = new DList_pchar();
00017   }
00018 
00019   void send( char* item ) {
00020     mutex0.lock();
00021     queue.append( item );
00022     mutex0.unlock();
00023   }
00024 
00025   char* receive() {
00026     char* item = NULL;
00027     mutex0.lock();
00028     if ( queue.size() != 0 ) {
00029       queue.setFirst();
00030       item = queue.remove();
00031     }
00032     mutex0.unlock();
00033     return item;
00034   }
00035 
00036 private:
00037   // N.B.:  We cannot use RWLock, since read actions may modify the list.
00038   Mutex mutex0;   
00039   DList_pchar* queue;
00040 };
00041 
00042 #endif

Generated on Sun Oct 14 18:46:40 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001