42 lines
716 B
C++
42 lines
716 B
C++
/*
|
|
* 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 <condition_variable>
|
|
#include <mutex>
|
|
|
|
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; });
|
|
}
|
|
}
|
|
};
|
|
}
|