libcruft-util/thread/flag_std.cpp
Danny Robson b60aaccf6f build; fix compilation errors under win32
win32 builds are still totally unsupported, untested, and functionally
broken.
2018-08-13 14:52:40 +10:00

45 lines
923 B
C++

#include "flag.hpp"
#include "../win32/except.hpp"
#include <synchapi.h>
#include <windows.h>
using cruft::thread::flag;
///////////////////////////////////////////////////////////////////////////////
flag::flag ():
fired (false)
{ ; }
///////////////////////////////////////////////////////////////////////////////
void
flag::wait (void)
{
while (!fired) {
std::unique_lock lk (m_mutex);
m_condition.wait (lk, [this] () { return !!fired; });
}
}
///////////////////////////////////////////////////////////////////////////////
void
flag::notify_one (void)
{
std::unique_lock lk (m_mutex);
fired = true;
m_condition.notify_one ();
}
//-----------------------------------------------------------------------------
void
flag::notify_all (void)
{
std::unique_lock lk (m_mutex);
fired = true;
m_condition.notify_all ();
}