A Mutex wrapper. Based on pthread calls.
More...
#include <SysHelper.h>
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>
{
printf("%d\n", Singleton::Instance().example_data);
return 0;
}
◆ CMutex()
dds::misc::CMutex::CMutex |
( |
| ) |
|
|
inline |
◆ Lock()
void dds::misc::CMutex::Lock |
( |
| ) |
|
|
inline |
◆ Unlock()
void dds::misc::CMutex::Unlock |
( |
| ) |
|
|
inline |
The documentation for this class was generated from the following file: