17 #ifndef COM_BORA_SOFTWARE__BALAU_CONCURRENT__LAZY_VALUE 18 #define COM_BORA_SOFTWARE__BALAU_CONCURRENT__LAZY_VALUE 42 public:
explicit LazyValue(std::function<
void (T &)> destruct_ = std::function<
void (T &)>())
44 , constructed(false) {}
50 std::lock_guard<std::mutex> lock(mutex);
52 if (constructed && destruct) {
63 if (!constructed.load(std::memory_order_acquire)) {
64 std::lock_guard<std::mutex> lock(mutex);
66 if (!constructed.load(std::memory_order_relaxed)) {
68 constructed.store(
true, std::memory_order_release);
103 private: std::function<void (T &)> destruct;
104 private: std::atomic_bool constructed;
105 private: std::mutex mutex;
111 #endif // COM_BORA_SOFTWARE__BALAU_CONCURRENT__LAZY_VALUE T & operator()(std::function< T()> construct)
Get the value, constructing it by calling the supplied function if necessary.
Definition: LazyValue.hpp:62
LazyValue(std::function< void(T &)> destruct_=std::function< void(T &)>())
Create a lazy value.
Definition: LazyValue.hpp:42
~LazyValue()
Destroy the lazy value instance.
Definition: LazyValue.hpp:49
Member variable style lazy setting of a value.
Definition: LazyValue.hpp:36
Concurrency control classes.
Definition: CyclicBarrier.hpp:26
bool isConstructed() const
Returns true if the value has been constructed.
Definition: LazyValue.hpp:86
std::mutex & getMutex()
Get the internal mutex in order to synchronise on external code.
Definition: LazyValue.hpp:97