minor changes
[anytun.git] / Sockets / Semaphore.h
blobacafea4865a926c5582e47250a6e31259385901d
1 /**
2 ** \file Semaphore.h
3 ** \date 2007-04-13
4 ** \author grymse@alhem.net
5 **/
6 /*
7 Copyright (C) 2007 Anders Hedstrom
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #ifndef _SOCKETS_Semaphore_H
24 #define _SOCKETS_Semaphore_H
26 #include "sockets-config.h"
27 #include <pthread.h>
28 #ifdef MACOSX
29 #include <sys/semaphore.h>
30 #else
31 #include <semaphore.h>
32 #endif
35 #ifdef SOCKETS_NAMESPACE
36 namespace SOCKETS_NAMESPACE {
37 #endif
40 /** pthread semaphore wrapper.
41 \ingroup threading */
42 class Semaphore
44 public:
45 Semaphore();
46 Semaphore(unsigned int start_val);
47 ~Semaphore();
49 int Post();
50 int Wait();
51 int TryWait();
52 int GetValue(int&);
54 private:
55 Semaphore(const Semaphore& ) {} // copy constructor
56 Semaphore& operator=(const Semaphore& ) { return *this; } // assignment operator
57 sem_t m_sem;
63 #ifdef SOCKETS_NAMESPACE
64 } // namespace SOCKETS_NAMESPACE {
65 #endif
66 #endif // _SOCKETS_Semaphore_H