You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
832 B
33 lines
832 B
#pragma once |
|
|
|
#include "application/interfaces/IBlocker.h" |
|
#include <condition_variable> |
|
#include <mutex> |
|
#include <atomic> |
|
|
|
namespace nxl::autostore::infrastructure { |
|
|
|
class CvBlocker : public application::IBlocker |
|
{ |
|
public: |
|
~CvBlocker() override = default; |
|
void block() override; |
|
void blockFor(const std::chrono::milliseconds& duration) override; |
|
void blockUntil(const TimePoint& timePoint) override; |
|
void notify() override; |
|
bool isBlocked() override; |
|
bool wasNotified() override; |
|
|
|
private: |
|
template <class Clock, class Duration> |
|
void blockUntilTimePoint( |
|
const std::chrono::time_point<Clock, Duration>& timePoint); |
|
|
|
private: |
|
std::condition_variable conditionVar; |
|
std::mutex mutex; |
|
std::atomic<bool> notified{false}; |
|
std::atomic<bool> blocked{false}; |
|
}; |
|
|
|
} // namespace nxl::autostore::infrastructure
|