Shellp
|
00001 /* 00002 00003 This file is a part of Shellp, a 'shell helper' library. 00004 00005 Copyright (C) 2011-2012 Jori Liesenborgs 00006 00007 Contact: jori.liesenborgs@gmail.com 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 00022 USA 00023 00024 */ 00025 00026 #ifndef SHELLP_SIGNALWAITER_H 00027 00028 #define SHELLP_SIGNALWAITER_H 00029 00030 #include <jthread/jmutex.h> 00031 #if !defined(WIN32) && !defined(_WIN32_WCE) 00032 #include <pthread.h> 00033 #endif // !WIN32 && !_WIN32_WCE 00034 00035 namespace shellp 00036 { 00037 00038 class SignalWaiter 00039 { 00040 public: 00041 SignalWaiter(); 00042 ~SignalWaiter(); 00043 00044 bool init(); 00045 void destroy(); 00046 00047 bool waitForSignal(); 00048 bool signal(); 00049 00050 bool clearSignalBuffers(); 00051 bool isInit() { return m_init; } 00052 private: 00053 #ifndef WIN32 00054 pthread_cond_t m_cond; 00055 pthread_mutex_t m_mutex; 00056 #else 00057 HANDLE m_eventObject; 00058 #endif // WIN32 00059 bool m_init; 00060 jthread::JMutex m_countMutex,m_waitMutex; 00061 int m_count; 00062 bool m_isWaiting; 00063 }; 00064 00065 } // end namespace 00066 00067 #endif // SHELLP_SIGNALWAITER_H 00068