![]() |
Semaphore.hGo to the documentation of this file.00001 00006 /* 00007 Copyright (C) 2007-2011 Anders Hedstrom 00008 00009 This library is made available under the terms of the GNU GPL, with 00010 the additional exemption that compiling, linking, and/or using OpenSSL 00011 is allowed. 00012 00013 If you would like to use this library in a closed-source application, 00014 a separate license agreement is available. For information about 00015 the closed-source license agreement for the C++ sockets library, 00016 please visit http://www.alhem.net/Sockets/license.html and/or 00017 email license@alhem.net. 00018 00019 This program is free software; you can redistribute it and/or 00020 modify it under the terms of the GNU General Public License 00021 as published by the Free Software Foundation; either version 2 00022 of the License, or (at your option) any later version. 00023 00024 This program is distributed in the hope that it will be useful, 00025 but WITHOUT ANY WARRANTY; without even the implied warranty of 00026 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00027 GNU General Public License for more details. 00028 00029 You should have received a copy of the GNU General Public License 00030 along with this program; if not, write to the Free Software 00031 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00032 */ 00033 #ifndef _SOCKETS_Semaphore_H 00034 #define _SOCKETS_Semaphore_H 00035 00036 #include "sockets-config.h" 00037 #ifdef _WIN32 00038 #include "socket_include.h" 00039 #include <windows.h> 00040 #else 00041 #include <pthread.h> 00042 #ifdef MACOSX 00043 #include <sys/semaphore.h> 00044 #else 00045 #include <semaphore.h> 00046 #endif 00047 #endif 00048 00049 00050 #ifdef SOCKETS_NAMESPACE 00051 namespace SOCKETS_NAMESPACE { 00052 #endif 00053 00054 #ifdef _WIN32 00055 typedef LONG value_t; 00056 #else 00057 typedef unsigned int value_t; 00058 #endif 00059 00062 class Semaphore 00063 { 00064 public: 00065 Semaphore(value_t start_val = 0); 00066 ~Semaphore(); 00067 00069 int Post(); 00072 int Wait(); 00073 00075 int TryWait(); 00076 00078 int GetValue(int&); 00079 00080 private: 00081 Semaphore(const Semaphore& ) {} // copy constructor 00082 Semaphore& operator=(const Semaphore& ) { return *this; } // assignment operator 00083 #ifdef _WIN32 00084 HANDLE m_handle; 00085 #else 00086 sem_t m_sem; 00087 #endif 00088 }; 00089 00090 00091 00092 00093 #ifdef SOCKETS_NAMESPACE 00094 } // namespace SOCKETS_NAMESPACE { 00095 #endif 00096 #endif // _SOCKETS_Semaphore_H 00097 |