python312Packages.llm-gguf: init at 0.2 (#364926)
[NixPkgs.git] / pkgs / by-name / dx / dxvk_1 / darwin-thread-primitives.patch
blobc008099407c574bbe0bd73bc6228f066549e0e23
1 diff --git a/src/util/thread.h b/src/util/thread.h
2 index 28aeca8a..db5c9913 100644
3 --- a/src/util/thread.h
4 +++ b/src/util/thread.h
5 @@ -149,178 +149,8 @@ namespace dxvk {
10 - /**
11 - * \brief SRW-based mutex implementation
12 - *
13 - * Drop-in replacement for \c std::mutex that uses Win32
14 - * SRW locks, which are implemented with \c futex in wine.
15 - */
16 - class mutex {
18 - public:
20 - using native_handle_type = PSRWLOCK;
22 - mutex() { }
24 - mutex(const mutex&) = delete;
25 - mutex& operator = (const mutex&) = delete;
27 - void lock() {
28 - AcquireSRWLockExclusive(&m_lock);
29 - }
31 - void unlock() {
32 - ReleaseSRWLockExclusive(&m_lock);
33 - }
35 - bool try_lock() {
36 - return TryAcquireSRWLockExclusive(&m_lock);
37 - }
39 - native_handle_type native_handle() {
40 - return &m_lock;
41 - }
43 - private:
45 - SRWLOCK m_lock = SRWLOCK_INIT;
47 - };
50 - /**
51 - * \brief Recursive mutex implementation
52 - *
53 - * Drop-in replacement for \c std::recursive_mutex that
54 - * uses Win32 critical sections.
55 - */
56 - class recursive_mutex {
58 - public:
60 - using native_handle_type = PCRITICAL_SECTION;
62 - recursive_mutex() {
63 - InitializeCriticalSection(&m_lock);
64 - }
66 - ~recursive_mutex() {
67 - DeleteCriticalSection(&m_lock);
68 - }
70 - recursive_mutex(const recursive_mutex&) = delete;
71 - recursive_mutex& operator = (const recursive_mutex&) = delete;
73 - void lock() {
74 - EnterCriticalSection(&m_lock);
75 - }
77 - void unlock() {
78 - LeaveCriticalSection(&m_lock);
79 - }
81 - bool try_lock() {
82 - return TryEnterCriticalSection(&m_lock);
83 - }
85 - native_handle_type native_handle() {
86 - return &m_lock;
87 - }
89 - private:
91 - CRITICAL_SECTION m_lock;
93 - };
96 - /**
97 - * \brief SRW-based condition variable implementation
98 - *
99 - * Drop-in replacement for \c std::condition_variable that
100 - * uses Win32 condition variables on SRW locks.
101 - */
102 - class condition_variable {
104 - public:
106 - using native_handle_type = PCONDITION_VARIABLE;
108 - condition_variable() {
109 - InitializeConditionVariable(&m_cond);
112 - condition_variable(condition_variable&) = delete;
114 - condition_variable& operator = (condition_variable&) = delete;
116 - void notify_one() {
117 - WakeConditionVariable(&m_cond);
120 - void notify_all() {
121 - WakeAllConditionVariable(&m_cond);
124 - void wait(std::unique_lock<dxvk::mutex>& lock) {
125 - auto srw = lock.mutex()->native_handle();
126 - SleepConditionVariableSRW(&m_cond, srw, INFINITE, 0);
129 - template<typename Predicate>
130 - void wait(std::unique_lock<dxvk::mutex>& lock, Predicate pred) {
131 - while (!pred())
132 - wait(lock);
135 - template<typename Clock, typename Duration>
136 - std::cv_status wait_until(std::unique_lock<dxvk::mutex>& lock, const std::chrono::time_point<Clock, Duration>& time) {
137 - auto now = Clock::now();
139 - return (now < time)
140 - ? wait_for(lock, now - time)
141 - : std::cv_status::timeout;
144 - template<typename Clock, typename Duration, typename Predicate>
145 - bool wait_until(std::unique_lock<dxvk::mutex>& lock, const std::chrono::time_point<Clock, Duration>& time, Predicate pred) {
146 - if (pred())
147 - return true;
149 - auto now = Clock::now();
150 - return now < time && wait_for(lock, now - time, pred);
153 - template<typename Rep, typename Period>
154 - std::cv_status wait_for(std::unique_lock<dxvk::mutex>& lock, const std::chrono::duration<Rep, Period>& timeout) {
155 - auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(timeout);
156 - auto srw = lock.mutex()->native_handle();
158 - return SleepConditionVariableSRW(&m_cond, srw, ms.count(), 0)
159 - ? std::cv_status::no_timeout
160 - : std::cv_status::timeout;
163 - template<typename Rep, typename Period, typename Predicate>
164 - bool wait_for(std::unique_lock<dxvk::mutex>& lock, const std::chrono::duration<Rep, Period>& timeout, Predicate pred) {
165 - bool result = pred();
167 - if (!result && wait_for(lock, timeout) == std::cv_status::no_timeout)
168 - result = pred();
170 - return result;
173 - native_handle_type native_handle() {
174 - return &m_cond;
177 - private:
179 - CONDITION_VARIABLE m_cond;
181 - };
182 + using mutex = std::mutex;
183 + using recursive_mutex = std::recursive_mutex;
184 + using condition_variable = std::condition_variable;