A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ns3::CriticalSection Class Reference

A class which provides a simple way to implement a Critical Section. More...

#include <system-mutex.h>

+ Collaboration diagram for ns3::CriticalSection:

Public Member Functions

 CriticalSection (SystemMutex &mutex)
 
 ~CriticalSection ()
 

Private Attributes

SystemMutexm_mutex
 

Detailed Description

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 to implement a Critical Section.

If one wants to treat an entire method call as a critical section, one would do something like,

Class::Method () { CriticalSection cs (mutex); ... }

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.

Class::Method () { ... { CriticalSection cs (mutex); } ... }

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.

See also
SystemMutex

Definition at line 109 of file system-mutex.h.

Constructor & Destructor Documentation

ns3::CriticalSection::CriticalSection ( SystemMutex mutex)

Definition at line 128 of file unix-system-mutex.cc.

References ns3::SystemMutex::Lock(), m_mutex, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

ns3::CriticalSection::~CriticalSection ( )

Definition at line 135 of file unix-system-mutex.cc.

References m_mutex, NS_LOG_FUNCTION, and ns3::SystemMutex::Unlock().

+ Here is the call graph for this function:

Member Data Documentation

SystemMutex& ns3::CriticalSection::m_mutex
private

Definition at line 115 of file system-mutex.h.

Referenced by CriticalSection(), and ~CriticalSection().


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