EventClass.cpp
Go to the documentation of this file.
00001 //
00002 // EventClass.cpp: implementation file
00003 //
00004 // Copyright (C) Walter E. Capers.  All rights reserved
00005 //
00006 // This source is free to use as you like.  If you make
00007 // any changes please keep me in the loop.  Email them to
00008 // walt.capers@comcast.net.
00009 //
00010 // PURPOSE:
00011 //
00012 //  To implement event signals as a C++ object
00013 //
00014 // REVISIONS
00015 // =======================================================
00016 // Date: 10.25.07        
00017 // Name: Walter E. Capers
00018 // Description: File creation
00019 //
00020 // Date:
00021 // Name:
00022 // Description:
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 


blort
Author(s): Thomas Mörwald , Michael Zillich , Andreas Richtsfeld , Johann Prankl , Markus Vincze , Bence Magyar
autogenerated on Wed Aug 26 2015 15:24:12