A class which provides a simple way to implement a Critical Section. More...
#include "system-mutex.h"
Public Member Functions | |
CriticalSection (SystemMutex &mutex) | |
Construct with the required SystemMutex. More... | |
~CriticalSection () | |
Destructor. More... | |
Private Attributes | |
SystemMutex & | m_mutex |
The mutex. More... | |
A class which provides a simple way to implement a Critical Section.
When more than one SystemThread needs to access a shared resource, we control access by acquiring a SystemMutex. The CriticalSection class uses the C++ scoping rules to automatically perform the required Lock and Unlock operations on the shared SystemMutex to implement a Critical Section.
If one wants to treat an entire method call as a critical section, one would do something like,
In this case, the critical section is entered when the CriticalSection object is created, and the critical section is exited when the CriticalSection object goes out of scope at the end of the method.
Finer granularity is achieved by using local scope blocks.
Here, the critical section is entered partway through the method when the CriticalSection object is created in the local scope block (the braces). The critical section is exited when the CriticalSection object goes out of scope at the end of block.
Definition at line 118 of file system-mutex.h.
ns3::CriticalSection::CriticalSection | ( | SystemMutex & | mutex | ) |
Construct with the required SystemMutex.
[in] | mutex | The mutex. |
Definition at line 135 of file unix-system-mutex.cc.
References ns3::SystemMutex::Lock(), m_mutex, and NS_LOG_FUNCTION.
ns3::CriticalSection::~CriticalSection | ( | ) |
Destructor.
Definition at line 142 of file unix-system-mutex.cc.
References m_mutex, NS_LOG_FUNCTION, and ns3::SystemMutex::Unlock().
|
private |
The mutex.
Definition at line 130 of file system-mutex.h.
Referenced by CriticalSection(), and ~CriticalSection().