Files CCore/inc/task/FastMutex.h CCore/src/task/FastMutex.cpp
FastMutexBase is a class, providing simplified mutex locking abilities.
struct FastMutexBase : NoCopy
{
....
class Lock : NoCopy
{
....
public:
explicit Lock(FastMutexBase &obj);
~Lock();
};
};
You can use this class as a base class to implement an execution serialization in derived class methods.
class SomeClass : FastMutexBase { public: void method() { Lock lock(*this); .... } };
The inner class Lock is the only way to lock the FastMutexBase. Locks must not be recursive. And the code inside a locked region must be fast, in particular, it cannot make any blocking calls. Use this class to serialize simple operations, like list manipulations.
HCore FastMutexBase is implemented using the class FastMutex.
class FastMutex : NoCopy
{
....
public:
explicit FastMutex(unsigned spin_count=MutexSpinCount());
~FastMutex();
void lock();
void unlock();
using Lock = LockObject<FastMutex> ;
};
This class is a simplified version of the class Mutex.
struct FastMutexBase : NoCopy
{
FastMutex mutex;
class Lock : NoCopy
{
FastMutex &mutex;
public:
explicit Lock(FastMutexBase &obj) : mutex(obj.mutex) { mutex.lock(); }
~Lock() { mutex.unlock(); }
};
};
There is no class FastMutex in XCore and the class FastMutexBase is stateless. It is just the IntLock.
struct FastMutexBase : NoCopy
{
class Lock : NoCopy
{
Dev::IntLock lock;
public:
explicit Lock(FastMutexBase &) {}
~Lock() {}
};
};
The code inside a locked region runs without interruption, so there is no priority inversion problem here.