sprint 1-alpha
sprint/thread/event.h
Go to the documentation of this file.
00001 /******************************************************************************
00002 *   SPRINT::event
00003 *
00004 *   Copyright (C) 2003-2007  Paolo Medici <www.pmx.it>
00005 *
00006 *  This library is free software; you can redistribute it and/or
00007 *  modify it under the terms of the GNU Lesser General Public
00008 *  License as published by the Free Software Foundation; either
00009 *  version 2.1 of the License, or (at your option) any later version.
00010 *
00011 *  This library is distributed in the hope that it will be useful,
00012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 *  Lesser General Public License for more details.
00015 *
00016 *  You should have received a copy of the GNU Lesser General Public
00017 *  License along with this library; if not, write to the Free Software
00018 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019 *
00020 *******************************************************************************/
00021 
00027 #ifndef _SPRINT_EVENT_H
00028 #define _SPRINT_EVENT_H
00029 
00030 #include <sprint/sysdef.h>
00031 
00032 #ifdef WIN32
00033 
00034 namespace sprint {
00035 
00037 class event {
00038 private:
00039         HANDLE m_event;
00040 public:
00042         event(bool bManualReset = true, bool InitialStatus = false)
00043         {
00044                 m_event = CreateEvent(NULL, bManualReset, InitialStatus, NULL);
00045         }
00046         ~event()
00047         {
00048                 ::CloseHandle(m_event);
00049         }
00051         inline void signal() const
00052         {
00053                 ::SetEvent(m_event);
00054         }
00056         inline void unsignal() const
00057         {
00058                 ::ResetEvent(m_event);
00059         }
00060 
00063         inline bool wait(DWORD timeout) const
00064         {
00065                 return ::WaitForSingleObject(m_event, timeout) == WAIT_OBJECT_0;        
00066         }
00067 
00069         inline DWORD win_wait(DWORD timeout) const
00070         {
00071                 return ::WaitForSingleObject(m_event, timeout); 
00072         }
00073 
00075         inline operator HANDLE() { return m_event; }
00076 
00077 };
00078 
00079 }
00080 
00081 #endif          // _win32       
00082 
00083 #endif          // _PM_EVENT_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines