DDS  ver. 3.5.3.8.g5fe284b
Public Member Functions | List of all members
MiscCommon::CMutex Class Reference

A Mutex wrapper. Based on pthread calls. More...

#include <SysHelper.h>

Public Member Functions

 CMutex ()
 
void Lock ()
 
void Unlock ()
 

Detailed Description

A Mutex wrapper. Based on pthread calls.

Note
Using this implementation one can create a thread -safe singleton:
class Singleton
{
public:
static Singleton& Instance();
int example_data;
~Singleton() { }
protected:
Singleton(): example_data(42) { }
private:
static std::auto_ptr<Singleton> theSingleInstance;
static Mutex m;
};
Singleton& Singleton::Instance()
{
MutexLocker obtain_lock(m);
if (theSingleInstance.get() == 0)
theSingleInstance.reset(new Singleton);
return *theSingleInstance;
}
std::auto_ptr<Singleton> Singleton::theSingleInstance;
Mutex Singleton::m;
#include <cstdio>
int main()
{
printf("%d\n", Singleton::Instance().example_data);
return 0;
}

Constructor & Destructor Documentation

◆ CMutex()

MiscCommon::CMutex::CMutex ( )
inline

Member Function Documentation

◆ Lock()

void MiscCommon::CMutex::Lock ( )
inline

◆ Unlock()

void MiscCommon::CMutex::Unlock ( )
inline

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