1
0
Fork 0
mirror of https://gitlab.com/niansa/libcrosscoro.git synced 2025-03-06 20:53:32 +01:00
libcrosscoro/src/sync_wait.cpp
Josh Baldwin 76b41a6ca0
Scheduler now correctly co_await's the user tasks from cleanup task (#14)
Previously it set the continuation manually, which sort of works but
is not canonical.
2020-10-28 17:35:23 -06:00

31 lines
No EOL
577 B
C++

#include "coro/sync_wait.hpp"
namespace coro::detail
{
sync_wait_event::sync_wait_event(bool initially_set) : m_set(initially_set)
{
}
auto sync_wait_event::set() noexcept -> void
{
{
std::lock_guard<std::mutex> g{m_mutex};
m_set = true;
}
m_cv.notify_all();
}
auto sync_wait_event::reset() noexcept -> void
{
std::lock_guard<std::mutex> g{m_mutex};
m_set = false;
}
auto sync_wait_event::wait() noexcept -> void
{
std::unique_lock<std::mutex> lk{m_mutex};
m_cv.wait(lk, [this] { return m_set; });
}
} // namespace coro::detail