mirror of
https://github.com/zeldaret/ss
synced 2026-05-24 23:21:41 -04:00
26af4db82d
* update from dtk-template and start work towards using clangd * include <a> -> "a" * Update build.yml * remove/add non-trivial class in union warning
49 lines
858 B
C++
49 lines
858 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" // IWYU pragma: export
|
|
|
|
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
|