styyx-util 1.0
Utility Header for SKSE Plugin development
Loading...
Searching...
No Matches
st-debug.h
Go to the documentation of this file.
1//
2// Created by styyx on 11/03/2026.
3//
4
5#pragma once
6#include <shared_mutex>
7#include <windows.h>
8
9
11{
12
13
14#ifdef NDEBUG
15
17{
18 explicit ScopedSharedLock(std::shared_mutex& mtx)
19 : lock(mtx)
20 {
21 }
22 void unlock() { lock.unlock(); }
23 void close() { lock.lock(); }
24
25 private:
26 std::shared_lock<std::shared_mutex> lock;
27};
28
30{
31 explicit ScopedUniqueLock(std::shared_mutex& mtx)
32 : lock(mtx)
33 {
34 }
35 void unlock() { lock.unlock(); }
36 void close() { lock.lock(); }
37
38 private:
39 std::unique_lock<std::shared_mutex> lock;
40};
41
42#else
43
45{
46 explicit ScopedSharedLock(std::shared_timed_mutex& mtx)
47 : lock(mtx, std::defer_lock)
48 {
49 if (!lock.try_lock_for(std::chrono::seconds(5)))
50 {
51 SKSE::log::critical("DEADLOCK DETECTED");
52 DebugBreak();
53 }
54 }
55 void unlock() { lock.unlock(); }
56 void close() { lock.lock(); }
57
58 private:
59 std::shared_lock<std::shared_timed_mutex> lock;
60};
61
63{
64 explicit ScopedUniqueLock(std::shared_timed_mutex& mtx)
65 : lock(mtx, std::defer_lock)
66 {
67 if (!lock.try_lock_for(std::chrono::seconds(5)))
68 {
69 SKSE::log::critical("DEADLOCK DETECTED");
70 DebugBreak();
71 }
72 }
73 void unlock() { lock.unlock(); }
74 void close() { lock.lock(); }
75
76 private:
77 std::unique_lock<std::shared_timed_mutex> lock;
78};
79
80#endif
81} // namespace StyyxUtil::DBGUtil
Definition st-debug.h:11
Definition st-debug.h:45
void unlock()
Definition st-debug.h:55
std::shared_lock< std::shared_timed_mutex > lock
Definition st-debug.h:59
void close()
Definition st-debug.h:56
ScopedSharedLock(std::shared_timed_mutex &mtx)
Definition st-debug.h:46
Definition st-debug.h:63
ScopedUniqueLock(std::shared_timed_mutex &mtx)
Definition st-debug.h:64
std::unique_lock< std::shared_timed_mutex > lock
Definition st-debug.h:77
void unlock()
Definition st-debug.h:73
void close()
Definition st-debug.h:74