Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <blort/ThreadObject/Thread.h>
00026
00027 CEventClass::CEventClass(void)
00028 :m_bCreated(TRUE)
00029 {
00030 #ifdef WINDOWS
00031 m_event = CreateEvent(NULL,FALSE,FALSE,NULL);
00032 if( !m_event )
00033 {
00034 m_bCreated = FALSE;
00035 }
00036 #else
00037 pthread_mutexattr_t mattr;
00038
00039 pthread_mutexattr_init(&mattr);
00040 pthread_mutex_init(&m_lock,&mattr);
00041 pthread_cond_init(&m_ready,NULL);
00042
00043 #endif
00044 }
00045
00046 CEventClass::~CEventClass(void)
00047 {
00048 #ifdef WINDOWS
00049 CloseHandle(m_event);
00050 #else
00051 pthread_cond_destroy(&m_ready);
00052 pthread_mutex_destroy(&m_lock);
00053 #endif
00054 }
00055
00056
00063 void
00064 CEventClass::Set()
00065 {
00066 #ifdef WINDOWS
00067 SetEvent(m_event);
00068 #else
00069 pthread_mutex_lock(&m_lock);
00070 pthread_mutex_unlock(&m_lock);
00071 pthread_cond_signal(&m_ready);
00072 #endif
00073 }
00074
00082 BOOL
00083 CEventClass::Wait()
00084 {
00085 #ifdef WINDOWS
00086 if( WaitForSingleObject(m_event,INFINITE) != WAIT_OBJECT_0 )
00087 {
00088 return FALSE;
00089 }
00090 return TRUE;
00091 #else
00092 pthread_mutex_lock(&m_lock);
00093 pthread_cond_wait(&m_ready,&m_lock);
00094 return TRUE;
00095 #endif
00096 }
00097
00104 void
00105 CEventClass::Reset()
00106 {
00107 #ifndef WINDOWS
00108 pthread_mutex_unlock(&m_lock);
00109 #endif
00110 }
00111