mirror of https://github.com/trapexit/mergerfs.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
669 B
52 lines
669 B
#pragma once
|
|
|
|
#ifdef DEBUG
|
|
#include "mutex_debug.hpp"
|
|
#else
|
|
#include "mutex_ndebug.hpp"
|
|
#endif
|
|
|
|
typedef pthread_mutex_t mutex_t;
|
|
|
|
// Simple mutex_t wrapper to provide RAII
|
|
// Because macros are needed to get location in the code a lock is
|
|
// called not making it std::mutex compatible.
|
|
class Mutex
|
|
{
|
|
private:
|
|
mutex_t _mutex;
|
|
|
|
public:
|
|
Mutex()
|
|
{
|
|
mutex_init(_mutex);
|
|
}
|
|
|
|
~Mutex()
|
|
{
|
|
mutex_destroy(_mutex);
|
|
}
|
|
|
|
operator mutex_t&()
|
|
{
|
|
return _mutex;
|
|
}
|
|
};
|
|
|
|
class LockGuard
|
|
{
|
|
private:
|
|
mutex_t &_mutex;
|
|
|
|
public:
|
|
LockGuard(mutex_t &mutex_)
|
|
: _mutex(mutex_)
|
|
{
|
|
mutex_lock(_mutex);
|
|
}
|
|
|
|
~LockGuard()
|
|
{
|
|
mutex_unlock(_mutex);
|
|
}
|
|
};
|