New ConditionVariableNotifier (implementation of NotifierInterface, using an std::condition_variable)
This commit is contained in:
44
src/Helpers/ConditionVariableNotifier.hpp
Normal file
44
src/Helpers/ConditionVariableNotifier.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#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;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user