libcruft-util/thread/condition_variable_win32.cpp
Danny Robson 01094611eb thread: add minimal thread primitives for win32
This allows us to get around the lack of these types under MinGW
2019-06-22 15:46:34 +10:00

43 lines
1.0 KiB
C++

#include "condition_variable_win32.hpp"
#include <synchapi.h>
using cruft::thread::win32::condition_variable;
///////////////////////////////////////////////////////////////////////////////
condition_variable::condition_variable ()
: m_native (CONDITION_VARIABLE_INIT)
{
InitializeConditionVariable (&m_native);
}
//-----------------------------------------------------------------------------
condition_variable::~condition_variable ()
{ ; }
///////////////////////////////////////////////////////////////////////////////
void
condition_variable::wait (std::unique_lock<cruft::thread::mutex> &lock)
{
SleepConditionVariableCS (
&m_native, &lock.mutex ()->native_handle (), INFINITE
);
}
///////////////////////////////////////////////////////////////////////////////
void condition_variable::notify_one (void) noexcept
{
WakeConditionVariable (&m_native);
}
//-----------------------------------------------------------------------------
void condition_variable::notify_all () noexcept
{
WakeAllConditionVariable (&m_native);
}