• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/threading/Event.h

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #ifndef _event_h
00018 #define _event_h
00019 
00020 #include <spl/types.h>
00021 #include <spl/threading/Mutex.h>
00022 #include <spl/RefCountPtr.h>
00023 
00030 class Event;
00031 typedef RefCountPtr<Event> EventPtr;
00032 typedef WeakReference<Event, EventPtr> EventRef;
00033 
00034 REGISTER_TYPEOF( 498, EventPtr );
00035 REGISTER_TYPEOF( 450, EventRef );
00036 
00038 class Event
00039 {
00040 private:
00041         // forbid copy constructor
00042         inline Event(const Event& e) {}
00043         inline void operator =(const Event& e) {}
00044 
00045 public:
00046         Event();
00047         Event( int timeout );
00048         virtual ~Event();
00049         void Wait();
00050         void Notify();
00051         void SetTimeOut( int ms );
00052 
00053 protected:
00054         int m_timeoutMs;
00055 
00056 #ifdef _WINDOWS
00057         HANDLE hevent;
00058 #else
00059         pthread_cond_t cond;
00060         pthread_mutex_t mtx;
00061 #endif
00062 };
00063 
00064 inline void ValidateType(const Event& e)
00065 {
00066 }
00067 
00068 inline void ValidateType(const Event *e)
00069 {
00070         if ( NULL != e )
00071         {
00072                 DEBUG_NOTE_MEM(e);
00073                 ASSERT_MEM(e, sizeof(Event));
00074         }
00075 }
00076 
00077 REGISTER_TYPEOF( 452, Event );
00078 
00081 #endif