diff --git a/openVulkanoCpp/Base/PauseCV.hpp b/openVulkanoCpp/Base/PauseCV.hpp new file mode 100644 index 0000000..1d23247 --- /dev/null +++ b/openVulkanoCpp/Base/PauseCV.hpp @@ -0,0 +1,41 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include +#include + +namespace OpenVulkano +{ + class PauseCV final + { + std::mutex m_mutex; + std::condition_variable m_condVar; + bool m_paused = false; + + public: + void Pause() { m_paused = true; } + + void Resume() + { + { + std::unique_lock lock(m_mutex); + m_paused = false; + } + m_condVar.notify_all(); + } + + void Check() + { + while (m_paused) + { + std::unique_lock l(m_mutex); + m_condVar.wait(l, [this]{ return !m_paused; }); + } + } + }; +}