45 lines
1.2 KiB
C++
45 lines
1.2 KiB
C++
|
|
#pragma once
|
||
|
|
|
||
|
|
#include <mutex>
|
||
|
|
#include <condition_variable>
|
||
|
|
|
||
|
|
#include "NotifierInterface.hpp"
|
||
|
|
|
||
|
|
namespace Bloom
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* The ConditionVariableNotifier class is an implementation of the NotifierInterface, using an
|
||
|
|
* std::condition_variable.
|
||
|
|
*/
|
||
|
|
class ConditionVariableNotifier: public NotifierInterface
|
||
|
|
{
|
||
|
|
public:
|
||
|
|
ConditionVariableNotifier() = default;
|
||
|
|
~ConditionVariableNotifier() override = default;
|
||
|
|
|
||
|
|
/*
|
||
|
|
* ConditionVariableNotifier objects should not be copied.
|
||
|
|
*/
|
||
|
|
ConditionVariableNotifier(ConditionVariableNotifier& other) = delete;
|
||
|
|
ConditionVariableNotifier& operator = (ConditionVariableNotifier& other) = delete;
|
||
|
|
|
||
|
|
/*
|
||
|
|
* TODO: Implement this.
|
||
|
|
*/
|
||
|
|
ConditionVariableNotifier(ConditionVariableNotifier&& other) noexcept = delete;
|
||
|
|
ConditionVariableNotifier& operator = (ConditionVariableNotifier&& other) = delete;
|
||
|
|
|
||
|
|
void notify() override;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Blocks until the contained std::conditional_variable is notified.
|
||
|
|
*/
|
||
|
|
void waitForNotification();
|
||
|
|
|
||
|
|
private:
|
||
|
|
std::mutex mutex;
|
||
|
|
std::condition_variable conditionalVariable;
|
||
|
|
bool notified = false;
|
||
|
|
};
|
||
|
|
}
|