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

/ray/src/lib/threads/condition.h

Go to the documentation of this file.
00001 /*
00002  * lib/threads/condition.h
00003  * 
00004  * Implementing a thread condition; an object that threads can block 
00005  * on, if they find a certain condition to be false. 
00006  * 
00007  * Copyright (c) 2004 by Wolfgang Wieser ] wwieser (a) gmx <*> de [ 
00008  * 
00009  * This file may be distributed and/or modified under the terms of the 
00010  * GNU General Public License version 2 as published by the Free Software 
00011  * Foundation. (See COPYING.GPL for details.)
00012  * 
00013  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00014  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00015  * 
00016  */
00017 
00018 #ifndef _ThreadLibrary_WaitCondition_H_
00019 #define _ThreadLibrary_WaitCondition_H_ 1
00020 
00028 #include <lib/sconfig.h>    /* MUST be first */
00029 
00030 /* Can we use our own pthreads-based implementation? This should be faster.*/
00031 #if USE_PRIVATE__PTHREADS
00032 # include <errno.h>   /* for EGAGIN */
00033 # include <pthread.h>
00034 #else
00035 # include <glib/gthread.h>
00036 #endif  /* USE_PRIVATE__PTHREADS */
00037 
00038 #include <lib/threads/mutex.h>
00039 
00040 
00057 class WaitCondition
00058 {
00059     private:
00060 #if USE_PRIVATE__PTHREADS
00061         pthread_cond_t c;
00062 #else
00063         GCond *c;
00064 #endif
00065         
00066     public:
00068         WaitCondition();
00069         
00071         ~WaitCondition();
00072         
00083         inline void signal()
00084 #if USE_PRIVATE__PTHREADS
00085             {  pthread_cond_signal(&c);  }
00086 #else
00087             {  g_cond_signal(c);  }
00088 #endif
00089         
00098         inline void broadcast()
00099 #if USE_PRIVATE__PTHREADS
00100             {  pthread_cond_broadcast(&c);  }
00101 #else
00102             {  g_cond_broadcast(c);  }
00103 #endif
00104         
00126         inline void wait(ConditionMutex &m)
00127 #if USE_PRIVATE__PTHREADS
00128             {  pthread_cond_wait(&c,&m.m);  }
00129 #else
00130             {  g_cond_wait(c,m.m);  }
00131 #endif
00132         
00143         int wait(ConditionMutex &m,long msec);
00144         
00145 };
00146 
00147 #endif  /* _ThreadLibrary_WaitCondition_H_ */

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