Add cond_variable::wait_unlock

This commit is contained in:
Nekotekina 2018-10-02 17:50:22 +03:00
parent 4bef0f8dab
commit bc87c5808c
2 changed files with 11 additions and 18 deletions

View file

@ -2,6 +2,7 @@
#include "types.h"
#include "Atomic.h"
#include <shared_mutex>
// Lightweight condition variable
class cond_variable
@ -32,6 +33,15 @@ public:
return res;
}
// Unlock all specified objects but don't lock them again
template <typename... Locks>
bool wait_unlock(u64 usec_timeout, Locks&&... locks)
{
const u32 _old = m_value.fetch_add(1); // Increment waiter counter
(..., std::forward<Locks>(locks).unlock());
return imp_wait(_old, usec_timeout);
}
// Wake one thread
void notify_one() noexcept
{