mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-22 13:14:32 +02:00
Add IsLockable method to WaitGroup
This commit is contained in:
parent
b27310fb6c
commit
157e3750e3
@ -26,6 +26,11 @@ void StoppableWaitGroup::unlock_shared()
|
||||
}
|
||||
}
|
||||
|
||||
bool StoppableWaitGroup::IsLockable() const
|
||||
{
|
||||
return !m_Stopped.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disallow new shared locks, wait for all existing ones.
|
||||
*/
|
||||
@ -33,6 +38,6 @@ void StoppableWaitGroup::Join()
|
||||
{
|
||||
std::unique_lock lock (m_Mutex);
|
||||
|
||||
m_Stopped = true;
|
||||
m_Stopped.store(true, std::memory_order_relaxed);
|
||||
m_CV.wait(lock, [this] { return !m_SharedLocks; });
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "base/object.hpp"
|
||||
#include "base/atomic.hpp"
|
||||
#include <condition_variable>
|
||||
#include <cstdint>
|
||||
#include <mutex>
|
||||
@ -22,6 +23,8 @@ public:
|
||||
|
||||
virtual bool try_lock_shared() = 0;
|
||||
virtual void unlock_shared() = 0;
|
||||
|
||||
virtual bool IsLockable() const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -42,13 +45,16 @@ public:
|
||||
|
||||
bool try_lock_shared() override;
|
||||
void unlock_shared() override;
|
||||
|
||||
bool IsLockable() const override;
|
||||
|
||||
void Join();
|
||||
|
||||
private:
|
||||
std::mutex m_Mutex;
|
||||
std::condition_variable m_CV;
|
||||
uint_fast32_t m_SharedLocks = 0;
|
||||
bool m_Stopped = false;
|
||||
Atomic<bool> m_Stopped = false;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user