PtexImporter/ptex/PtexMutex.h
#ifndef PtexMutex_h
#define PtexMutex_h
namespace PtexInternal {
#ifndef NDEBUG
template <class T>
class DebugLock : public T {
public:
DebugLock() : _locked(0) {}
void lock() { T::lock(); _locked = 1; }
void unlock() { assert(_locked); _locked = 0; T::unlock(); }
bool locked() { return _locked != 0; }
private:
int _locked;
};
#endif
template <class T>
class AutoLock {
public:
AutoLock(T& m) : _m(m) { _m.lock(); }
~AutoLock() { _m.unlock(); }
private:
T& _m;
};
#ifndef NDEBUG
typedef DebugLock<_Mutex> Mutex;
typedef DebugLock<_SpinLock> SpinLock;
#else
typedef _Mutex Mutex;
typedef _SpinLock SpinLock;
#endif
typedef AutoLock<Mutex> AutoMutex;
typedef AutoLock<SpinLock> AutoSpin;
}
#endif