summaryrefslogtreecommitdiff
path: root/src/common/thread.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/thread.h')
-rw-r--r--src/common/thread.h22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/common/thread.h b/src/common/thread.h
index 2fc071685..a8c17c71a 100644
--- a/src/common/thread.h
+++ b/src/common/thread.h
@@ -4,11 +4,13 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <atomic>
7#include <chrono> 8#include <chrono>
8#include <condition_variable> 9#include <condition_variable>
9#include <cstddef> 10#include <cstddef>
10#include <mutex> 11#include <mutex>
11#include <thread> 12#include <thread>
13#include "common/common_types.h"
12 14
13namespace Common { 15namespace Common {
14 16
@@ -24,14 +26,13 @@ public:
24 26
25 void Wait() { 27 void Wait() {
26 std::unique_lock lk{mutex}; 28 std::unique_lock lk{mutex};
27 condvar.wait(lk, [&] { return is_set; }); 29 condvar.wait(lk, [&] { return is_set.load(); });
28 is_set = false; 30 is_set = false;
29 } 31 }
30 32
31 template <class Duration> 33 bool WaitFor(const std::chrono::nanoseconds& time) {
32 bool WaitFor(const std::chrono::duration<Duration>& time) {
33 std::unique_lock lk{mutex}; 34 std::unique_lock lk{mutex};
34 if (!condvar.wait_for(lk, time, [this] { return is_set; })) 35 if (!condvar.wait_for(lk, time, [this] { return is_set.load(); }))
35 return false; 36 return false;
36 is_set = false; 37 is_set = false;
37 return true; 38 return true;
@@ -40,7 +41,7 @@ public:
40 template <class Clock, class Duration> 41 template <class Clock, class Duration>
41 bool WaitUntil(const std::chrono::time_point<Clock, Duration>& time) { 42 bool WaitUntil(const std::chrono::time_point<Clock, Duration>& time) {
42 std::unique_lock lk{mutex}; 43 std::unique_lock lk{mutex};
43 if (!condvar.wait_until(lk, time, [this] { return is_set; })) 44 if (!condvar.wait_until(lk, time, [this] { return is_set.load(); }))
44 return false; 45 return false;
45 is_set = false; 46 is_set = false;
46 return true; 47 return true;
@@ -54,9 +55,9 @@ public:
54 } 55 }
55 56
56private: 57private:
57 bool is_set = false;
58 std::condition_variable condvar; 58 std::condition_variable condvar;
59 std::mutex mutex; 59 std::mutex mutex;
60 std::atomic_bool is_set{false};
60}; 61};
61 62
62class Barrier { 63class Barrier {
@@ -86,6 +87,15 @@ private:
86 std::size_t generation = 0; // Incremented once each time the barrier is used 87 std::size_t generation = 0; // Incremented once each time the barrier is used
87}; 88};
88 89
90enum class ThreadPriority : u32 {
91 Low = 0,
92 Normal = 1,
93 High = 2,
94 VeryHigh = 3,
95};
96
97void SetCurrentThreadPriority(ThreadPriority new_priority);
98
89void SetCurrentThreadName(const char* name); 99void SetCurrentThreadName(const char* name);
90 100
91} // namespace Common 101} // namespace Common