Files
ss/include/nw4r/ut/ut_lock.h
T
2023-12-24 11:35:03 -05:00

49 lines
835 B
C++

#ifndef NW4R_UT_LOCK_H
#define NW4R_UT_LOCK_H
#include <nw4r/types_nw4r.h>
#include <nw4r/ut/ut_NonCopyable.h>
#include <rvl/OS.h>
namespace nw4r {
namespace ut {
namespace detail {
inline void Lock(OSMutex &mutex) {
OSLockMutex(&mutex);
}
inline void Unlock(OSMutex &mutex) {
OSUnlockMutex(&mutex);
}
template <typename T>
class AutoLock : private NonCopyable {
public:
AutoLock(T &obj) : mMutex(obj) {
Lock(mMutex);
}
~AutoLock() {
Unlock(mMutex);
}
private:
T &mMutex; // at 0x0
};
} // namespace detail
class AutoInterruptLock : private NonCopyable {
public:
AutoInterruptLock() : mEnabled(OSDisableInterrupts()) {}
~AutoInterruptLock() {
OSRestoreInterrupts(mEnabled);
}
private:
BOOL mEnabled; // at 0x0
};
} // namespace ut
} // namespace nw4r
#endif