Mixe for Privacy and Anonymity in the Internet
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
CALockAble Class Reference

From this class other classes could be derived, which need some kind from "locking" in memory. More...

#include <CALockAble.hpp>

Inheritance diagram for CALockAble:
Collaboration diagram for CALockAble:

Public Member Functions

 CALockAble ()
 
virtual ~CALockAble ()
 
SINT32 lock ()
 Locks the lockable object by threadsafe incrementing a reference counter. More...
 
SINT32 unlock ()
 Unlocks the lockable object by threadsafe decrementing a reference counter. More...
 

Protected Member Functions

SINT32 waitForDestroy ()
 If called checks if the reference counter equals zero. More...
 

Private Attributes

CAConditionVariable m_ConVar
 A conditional variable, which would be signaled if the rerference counter reaches zero. More...
 
UINT32 m_nLockCount
 The reference counter. More...
 

Detailed Description

From this class other classes could be derived, which need some kind from "locking" in memory.

Imagine for instance that thread t1 creates an object o of class c and uses it. During that a second thread t2 destroies o by calling delete o. Clearly this would be desasterous. To solve this problem cc should be derived from CALockAble. Than t1 calls o.lock() before using o and o.unlock() if t1 finsihed using o. If t2 calls delete o between the lock() / unlock() calls, it would block until all references of o are unlocked. Probablly this class is usefull for other tings, too...

Definition at line 40 of file CALockAble.hpp.

Constructor & Destructor Documentation

◆ CALockAble()

CALockAble::CALockAble ( )
inline

Definition at line 43 of file CALockAble.hpp.

44  {
45  m_nLockCount=1;
46  }
UINT32 m_nLockCount
The reference counter.
Definition: CALockAble.hpp:95

References m_nLockCount.

◆ ~CALockAble()

virtual CALockAble::~CALockAble ( )
inlinevirtual

Definition at line 48 of file CALockAble.hpp.

49  {
50  }

Member Function Documentation

◆ lock()

SINT32 CALockAble::lock ( )
inline

Locks the lockable object by threadsafe incrementing a reference counter.

Return values
E_SUCCESS

Definition at line 55 of file CALockAble.hpp.

56  {
57  m_ConVar.lock();
58  m_nLockCount++;
59  m_ConVar.unlock();
60  return E_SUCCESS;
61  }
CAConditionVariable m_ConVar
A conditional variable, which would be signaled if the rerference counter reaches zero.
Definition: CALockAble.hpp:93
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2

References E_SUCCESS, CAMutex::lock(), m_ConVar, m_nLockCount, and CAMutex::unlock().

Referenced by CAMiddleMixChannelList::getInToOut(), CAMiddleMixChannelList::getOutToIn_intern_without_lock(), and CAFirstMixA::loop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unlock()

SINT32 CALockAble::unlock ( )
inline

Unlocks the lockable object by threadsafe decrementing a reference counter.

The counter would never become less than zero. Every thread, which waits in waitForDestroy() will be signaled.

Return values
E_SUCCESS

Definition at line 67 of file CALockAble.hpp.

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  }
SINT32 signal()
Signals this object.

References E_SUCCESS, CAMutex::lock(), m_ConVar, m_nLockCount, CAConditionVariable::signal(), and CAMutex::unlock().

Here is the call graph for this function:

◆ waitForDestroy()

SINT32 CALockAble::waitForDestroy ( )
inlineprotected

If called checks if the reference counter equals zero.

If the reference counter is greater than zero, the call blocks.

Return values
E_SUCCESS

Definition at line 82 of file CALockAble.hpp.

83  {
84  m_ConVar.lock();
85  while(m_nLockCount>1)
86  m_ConVar.wait();
87  m_ConVar.unlock();
88  return E_SUCCESS;
89  }
SINT32 wait()
Waits for a signal or for a timeout.

References E_SUCCESS, CAMutex::lock(), m_ConVar, m_nLockCount, CAMutex::unlock(), and CAConditionVariable::wait().

Referenced by CASymCipher::~CASymCipher(), CASymCipherCTR::~CASymCipherCTR(), CASymCipherGCM::~CASymCipherGCM(), CASymCipherNull::~CASymCipherNull(), and CASymCipherOFB::~CASymCipherOFB().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_ConVar

CAConditionVariable CALockAble::m_ConVar
private

A conditional variable, which would be signaled if the rerference counter reaches zero.

Definition at line 93 of file CALockAble.hpp.

Referenced by lock(), unlock(), and waitForDestroy().

◆ m_nLockCount

UINT32 CALockAble::m_nLockCount
private

The reference counter.

Definition at line 95 of file CALockAble.hpp.

Referenced by CALockAble(), lock(), unlock(), and waitForDestroy().


The documentation for this class was generated from the following file: