Main Page   Class Hierarchy   Compound List   File List   Compound Members  

CAVERNts_condition_c.hxx

00001 /******************************************************************
00002  * CAVERNsoft
00003  * Copyright (C) 1994-2000 Electronic Visualization Laboratory,
00004  * all rights reserved
00005  * By Jason Leigh, Yong-joo Cho, Naveen Krishnaprasad, Chris Scharver,
00006  * Stuart Bailey, Atul Nayak,Shalini Venkataraman
00007  * University of Illinois at Chicago
00008  * 
00009  * This publication and its text and code may not be copied for commercial 
00010  * use without the express written permission of the University of Illinois
00011  * at Chicago.
00012  * The contributors disclaim any representation of warranty: use this
00013  * code at your own risk.
00014  * Direct questions, comments etc to cavern@evl.uic.edu
00015  ******************************************************************/
00016 
00017 #ifndef _CAVERNPLUS_CONDITION_C
00018 #define _CAVERNPLUS_CONDITION_C
00019 
00020 #include "CAVERNts_mutex_c.hxx"
00021 
00022 #ifdef CAVERN_USE_GLOBUS_THREADS       
00023         typedef globus_cond_t CAVERN_COND_T;
00024 #elif defined(CAVERN_USE_PTHREADS)
00025         typedef pthread_cond_t CAVERN_COND_T;
00026 #elif defined(CAVERN_USE_WINDOWSTHREADS)
00027     class _CAVERN_COND_T 
00028     {
00029     public:
00030         _CAVERN_COND_T() {
00031             waiters = 0;
00032             wasBroadcast = 0;
00033             sema = CreateSemaphore(NULL, 0, 0xFFFFFFFF, NULL);
00034             waitersDone = CreateEvent(NULL, FALSE, FALSE, NULL);
00035             waitersLock = CreateMutex(NULL, FALSE, NULL);
00036         }
00037 
00038         virtual ~_CAVERN_COND_T() {
00039             if (waitersDone) CloseHandle(waitersDone);
00040             if (waitersLock) CloseHandle(waitersLock);
00041             if (sema) CloseHandle(sema);
00042         }
00043 
00044         long waiters;  // Number of waiting threads.
00045         HANDLE waitersLock; // Serialize access to the waiters count.
00046 
00047         // Queue up threads waiting for the condition to become signaled.
00048         HANDLE sema; 
00049 
00050         // An auto reset event used by the broadcast/signal thread to wait
00051         // for the waiting thread(s) to wake up and get a chance at the
00052         // semaphore.
00053         HANDLE waitersDone;
00054 
00055         // Keeps track of whether we were broadcasting or just signaling.
00056         size_t wasBroadcast;
00057     };
00058 
00059     typedef _CAVERN_COND_T * CAVERN_COND_T;
00060 #else
00061         #error One of CAVERN_USE_GLOBUS_THREADS, CAVERN_USE_PTHREADS, or CAVERN_USE_WINDOWSTHREADS must be defined.
00062 #endif
00063 
00107 class CAVERNts_condition_c {
00108 public:
00109 
00117         int wait(CAVERNts_mutex_c *mutex);
00118 
00127         int signal();
00128 
00135         int broadcastSignal();
00136 
00138         CAVERN_COND_T *getCondition();
00139 
00140         CAVERNts_condition_c();
00141         ~CAVERNts_condition_c();
00142 
00143 private:
00144         CAVERN_COND_T itsCV;
00145 };
00146 
00147 
00148 #endif
00149 

Generated at Mon Jul 2 14:24:42 2001 for CAVERNsoft by doxygen1.2.8-20010617 written by Dimitri van Heesch, © 1997-2001