Mixe for Privacy and Anonymity in the Internet
CALockAble.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 __CALOCKABLE__
29 #define __CALOCKABLE__
30 
31 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_MIDDLE_MIX
32 #include "CAConditionVariable.hpp"
41  {
42  public:
44  {
45  m_nLockCount=1;
46  }
47 
48  virtual ~CALockAble()
49  {
50  }
51 
56  {
57  m_ConVar.lock();
58  m_nLockCount++;
59  m_ConVar.unlock();
60  return E_SUCCESS;
61  }
62 
68  {
69  m_ConVar.lock();
70  if(m_nLockCount>0)
71  m_nLockCount--;
72  m_ConVar.unlock();
73  m_ConVar.signal();
74  return E_SUCCESS;
75  }
76 
77  protected:
83  {
84  m_ConVar.lock();
85  while(m_nLockCount>1)
86  m_ConVar.wait();
87  m_ConVar.unlock();
88  return E_SUCCESS;
89  }
90 
91  private:
96  };
97 #endif //ONLY_LOCAL_PROXY
98 
99 #endif //__CALOCABLE__
signed int SINT32
Definition: basetypedefs.h:132
unsigned int UINT32
Definition: basetypedefs.h:131
SINT32 signal()
Signals this object.
SINT32 wait()
Waits for a signal or for a timeout.
From this class other classes could be derived, which need some kind from "locking" in memory.
Definition: CALockAble.hpp:41
UINT32 m_nLockCount
The reference counter.
Definition: CALockAble.hpp:95
SINT32 waitForDestroy()
If called checks if the reference counter equals zero.
Definition: CALockAble.hpp:82
SINT32 unlock()
Unlocks the lockable object by threadsafe decrementing a reference counter.
Definition: CALockAble.hpp:67
CAConditionVariable m_ConVar
A conditional variable, which would be signaled if the rerference counter reaches zero.
Definition: CALockAble.hpp:93
virtual ~CALockAble()
Definition: CALockAble.hpp:48
SINT32 lock()
Locks the lockable object by threadsafe incrementing a reference counter.
Definition: CALockAble.hpp:55
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2