missing project/build files
[client-tools.git] / src / external / 3rd / library / soePlatform / CSAssist / utils / Base / solaris / Event.h
blobb2101e24a85c8d165fda7d89470073763a3ff58b
1 ////////////////////////////////////////
2 // Event.h
3 //
4 // Purpose:
5 // 1. Declair the CEvent class that encapsulates the functionality of a
6 // single-locking semaphore.
7 //
8 // Revisions:
9 // 07/10/2001 Created
12 #ifndef BASE_SOLARIS_EVENT_H
13 #define BASE_SOLARIS_EVENT_H
15 #if !defined(_REENTRANT)
16 # pragma message( "Excluding Base::CEvent - requires multi-threaded compile. (_REENTRANT)" )
17 #else
20 #include "Platform.h"
22 namespace Base
25 ////////////////////////////////////////
26 // Class:
27 // CEvent
29 // Purpose:
30 // Encapsulates the functionality of a singal-locking semaphore.
31 // This class is valuable for thread syncronization when a thead's
32 // execution needs to be dependent upon another thread.
34 // Public Methods:
35 // Signal() : Signals a thread that has called Wait() so that it can
36 // continue execution. This function returns true if the waiting
37 // thread was signalled successfully, otherwise false is returned.
38 // Wait() : Halts the calling thread's execution indefinately until
39 // a Singal() call is made by an external thread. If the thread is
40 // successfully signalled, the function returns eWAIT_SIGNAL. If
41 // timeout period expires without a signal, eWAIT_TIMEOUT is returned.
42 // If the function fails, eWAIT_ERROR is returned.
44 class CEvent
46 public:
47 CEvent();
48 virtual ~CEvent();
50 bool Signal();
51 int32 Wait(uint32 timeout = 0);
52 public:
53 enum { eWAIT_ERROR, eWAIT_SIGNAL, eWAIT_TIMEOUT };
54 private:
55 pthread_mutex_t mMutex;
56 pthread_cond_t mCond;
57 bool mInitialized;
58 bool mSignaled;
59 int32 mWaiting;
62 inline bool CEvent::Signal()
64 if (!mInitialized)
65 return false;
66 pthread_mutex_lock(&mMutex);
67 if(mWaiting > 0)
69 pthread_cond_signal(&mCond);
71 else
73 mWaiting = true;
75 pthread_mutex_unlock(&mMutex);
76 return true;
81 #endif // #if defined(_MT)
83 #endif // BASE_SOLARIS_EVENT_H