diff options
Diffstat (limited to 'src/common/thread.h')
| -rw-r--r-- | src/common/thread.h | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/common/thread.h b/src/common/thread.h index e17a7850f..8ae169b4e 100644 --- a/src/common/thread.h +++ b/src/common/thread.h | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | #include <mutex> | 11 | #include <mutex> |
| 12 | #include <thread> | 12 | #include <thread> |
| 13 | #include "common/common_types.h" | 13 | #include "common/common_types.h" |
| 14 | #include "common/polyfill_thread.h" | ||
| 14 | 15 | ||
| 15 | namespace Common { | 16 | namespace Common { |
| 16 | 17 | ||
| @@ -69,7 +70,7 @@ public: | |||
| 69 | explicit Barrier(std::size_t count_) : count(count_) {} | 70 | explicit Barrier(std::size_t count_) : count(count_) {} |
| 70 | 71 | ||
| 71 | /// Blocks until all "count" threads have called Sync() | 72 | /// Blocks until all "count" threads have called Sync() |
| 72 | void Sync() { | 73 | bool Sync(std::stop_token token = {}) { |
| 73 | std::unique_lock lk{mutex}; | 74 | std::unique_lock lk{mutex}; |
| 74 | const std::size_t current_generation = generation; | 75 | const std::size_t current_generation = generation; |
| 75 | 76 | ||
| @@ -77,14 +78,16 @@ public: | |||
| 77 | generation++; | 78 | generation++; |
| 78 | waiting = 0; | 79 | waiting = 0; |
| 79 | condvar.notify_all(); | 80 | condvar.notify_all(); |
| 81 | return true; | ||
| 80 | } else { | 82 | } else { |
| 81 | condvar.wait(lk, | 83 | CondvarWait(condvar, lk, token, |
| 82 | [this, current_generation] { return current_generation != generation; }); | 84 | [this, current_generation] { return current_generation != generation; }); |
| 85 | return !token.stop_requested(); | ||
| 83 | } | 86 | } |
| 84 | } | 87 | } |
| 85 | 88 | ||
| 86 | private: | 89 | private: |
| 87 | std::condition_variable condvar; | 90 | std::condition_variable_any condvar; |
| 88 | std::mutex mutex; | 91 | std::mutex mutex; |
| 89 | std::size_t count; | 92 | std::size_t count; |
| 90 | std::size_t waiting = 0; | 93 | std::size_t waiting = 0; |