Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

/ray/src/lib/threads/tsemaphore.cc

Go to the documentation of this file.
00001 /*
00002  * lib/threads/tsemaphore.cc
00003  * 
00004  * Implementing semaphore class for thread synchronisation. 
00005  * 
00006  * Copyright (c) 2004 by Wolfgang Wieser ] wwieser (a) gmx <*> de [ 
00007  * 
00008  * This file may be distributed and/or modified under the terms of the 
00009  * GNU General Public License version 2 as published by the Free Software 
00010  * Foundation. (See COPYING.GPL for details.)
00011  * 
00012  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014  * 
00015  */
00016 
00017 #include "tsemaphore.h"
00018 
00019 
00020 #if !USE_PRIVATE__POSIX_SEMAPHORES
00021 void Semaphore::post()
00022 {
00023     m.lock();
00024     ++v;
00025     c.broadcast();
00026     m.unlock();
00027 }
00028 #endif
00029 
00030 
00031 #if !USE_PRIVATE__POSIX_SEMAPHORES
00032 void Semaphore::wait()
00033 {
00034     m.lock();
00035     if(v)
00036     {
00037         --v;
00038         m.unlock();
00039         return;
00040     }
00041     // v=0; Need to wait. 
00042     
00043     // We do NOT unlock here; the condition takes care of it. 
00044     while(!v)  c.wait(m);
00045     
00046     m.unlock();
00047 }
00048 #endif
00049 
00050 
00051 #if !USE_PRIVATE__POSIX_SEMAPHORES
00052 bool Semaphore::test()
00053 {
00054     bool retval;
00055     m.lock();
00056     if(v)
00057     {  --v;  retval=0;  }
00058     else
00059     {  retval=1;  }
00060     m.unlock();
00061     return(retval);
00062 }
00063 #endif

Generated on Sat Feb 19 22:33:46 2005 for Ray by doxygen 1.3.5