diff options
| author | bunnei <bunneidev@gmail.com> | 2018-05-03 00:16:12 -0400 |
|---|---|---|
| committer | bunnei <bunneidev@gmail.com> | 2018-05-10 19:34:47 -0400 |
| commit | cba69fdcd439c5f225bbddf1dad70e6326edd0dc (patch) | |
| tree | b608addf14d16c634cbe99a04e7931adfb2dbf31 /src/core/core_cpu.h | |
| parent | a434fdcb102e96ddf564dc0973d7073d49bf19fc (diff) | |
core: Support session close with multicore.
Diffstat (limited to 'src/core/core_cpu.h')
| -rw-r--r-- | src/core/core_cpu.h | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/core/core_cpu.h b/src/core/core_cpu.h index 06784c4ab..243f0b5e7 100644 --- a/src/core/core_cpu.h +++ b/src/core/core_cpu.h @@ -4,6 +4,7 @@ #pragma once +#include <atomic> #include <condition_variable> #include <memory> #include <mutex> @@ -22,23 +23,19 @@ constexpr unsigned NUM_CPU_CORES{4}; class CpuBarrier { public: - void Rendezvous() { - std::unique_lock<std::mutex> lock(mutex); + bool IsAlive() const { + return !end; + } - --cores_waiting; - if (!cores_waiting) { - cores_waiting = NUM_CPU_CORES; - condition.notify_all(); - return; - } + void NotifyEnd(); - condition.wait(lock); - } + bool Rendezvous(); private: unsigned cores_waiting{NUM_CPU_CORES}; std::mutex mutex; std::condition_variable condition; + std::atomic<bool> end{}; }; class Cpu { |
