Files
ss/include/nw4r/ut/ut_lock.h
T
Elijah Thomas 26af4db82d update from dtk-template - clangd :) (#66)
* update from dtk-template and start work towards using clangd

* include <a> -> "a"

* Update build.yml

* remove/add non-trivial class in union warning
2024-10-16 15:36:02 -04:00

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