Mixe for Privacy and Anonymity in the Internet
CASemaphore.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2000, The JAP-Team
3 All rights reserved.
4 Redistribution and use in source and binary forms, with or without modification,
5 are permitted provided that the following conditions are met:
6 
7  - Redistributions of source code must retain the above copyright notice,
8  this list of conditions and the following disclaimer.
9 
10  - Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation and/or
12  other materials provided with the distribution.
13 
14  - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors
15  may be used to endorse or promote products derived from this software without specific
16  prior written permission.
17 
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
20 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
27 */
28 #ifndef __CASEMAPHORE__
29 #define __CASEMAPHORE__
30 
31 #ifdef USE_SEMAPHORE
32 class CASemaphore
33  {
34  public:
35  CASemaphore()
36  {
37  m_pSemaphore=new sem_t;
38  sem_init(m_pSemaphore,0,0);
39  }
40 
41  CASemaphore(int iInitialValue)
42  {
43  m_pSemaphore=new sem_t;
44  sem_init(m_pSemaphore,0,iInitialValue);
45  }
46 
47  ~CASemaphore()
48  {
49  sem_destroy(m_pSemaphore);
50  delete m_pSemaphore;
51  m_pSemaphore = NULL;
52  }
53 
54  SINT32 up()
55  {
56  if(sem_post(m_pSemaphore)>=0)
57  return E_SUCCESS;
58  return E_UNKNOWN;
59  }
60 
61  SINT32 down()
62  {
63  SINT32 ret;
64  while((ret=sem_wait(m_pSemaphore))==E_AGAIN);
65  if(ret==0)
66  return E_SUCCESS;
67  return E_UNKNOWN;
68  }
69 
70  private:
71  sem_t* m_pSemaphore;
72  };
73 #endif
74 #endif
signed int SINT32
Definition: basetypedefs.h:132
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
#define E_AGAIN
Definition: errorcodes.hpp:9
#define E_UNKNOWN
Definition: errorcodes.hpp:3