libcruft-util/thread/condition_variable_win32.hpp
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

62 lines
1.7 KiB
C++

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright 2019 Danny Robson <danny@nerdcruft.net>
*/
#pragma once
#include "mutex.hpp"
#include <mutex>
namespace cruft::thread {
inline namespace win32 {
enum class cv_status {
no_timeout,
timeout
};
class condition_variable {
public:
condition_variable ();
condition_variable (condition_variable const&) noexcept = delete;
condition_variable& operator= (condition_variable const&) = delete;
~condition_variable ();
void notify_one (void) noexcept;
void notify_all (void) noexcept;
void wait (std::unique_lock<mutex>&);
template <typename PredicateT>
void wait (
std::unique_lock<mutex> &lock,
PredicateT pred
) {
while (!pred ())
wait (lock);
}
template <class RepT, class PeriodT>
cv_status
wait_for (
std::unique_lock<mutex>& lock,
std::chrono::duration<RepT, PeriodT> const &rel_time
);
template <class RepT, class PeriodT, class PredicateT>
bool wait_for (
std::unique_lock<mutex>& lock,
std::chrono::duration<RepT, PeriodT> const &rel_time,
PredicateT pred
);
private:
CONDITION_VARIABLE m_native;
};
};
}