@ -4,6 +4,7 @@
# pragma once
# pragma once
# include <atomic>
# include <chrono>
# include <chrono>
# include <condition_variable>
# include <condition_variable>
# include <cstddef>
# include <cstddef>
@ -24,14 +25,14 @@ public:
void Wait ( ) {
void Wait ( ) {
std : : unique_lock lk { mutex } ;
std : : unique_lock lk { mutex } ;
condvar . wait ( lk , [ & ] { return is_set ; } ) ;
condvar . wait ( lk , [ & ] { return is_set .load ( ) ; } ) ;
is_set = false ;
is_set = false ;
}
}
template < class Duration >
template < class Duration >
bool WaitFor ( const std : : chrono : : duration < Duration > & time ) {
bool WaitFor ( const std : : chrono : : duration < Duration > & time ) {
std : : unique_lock lk { mutex } ;
std : : unique_lock lk { mutex } ;
if ( ! condvar . wait_for ( lk , time , [ this ] { return is_set ; } ) )
if ( ! condvar . wait_for ( lk , time , [ this ] { return is_set .load ( ) ; } ) )
return false ;
return false ;
is_set = false ;
is_set = false ;
return true ;
return true ;
@ -40,7 +41,7 @@ public:
template < class Clock , class Duration >
template < class Clock , class Duration >
bool WaitUntil ( const std : : chrono : : time_point < Clock , Duration > & time ) {
bool WaitUntil ( const std : : chrono : : time_point < Clock , Duration > & time ) {
std : : unique_lock lk { mutex } ;
std : : unique_lock lk { mutex } ;
if ( ! condvar . wait_until ( lk , time , [ this ] { return is_set ; } ) )
if ( ! condvar . wait_until ( lk , time , [ this ] { return is_set .load ( ) ; } ) )
return false ;
return false ;
is_set = false ;
is_set = false ;
return true ;
return true ;
@ -54,9 +55,9 @@ public:
}
}
private :
private :
bool is_set = false ;
std : : condition_variable condvar ;
std : : condition_variable condvar ;
std : : mutex mutex ;
std : : mutex mutex ;
std : : atomic_bool is_set { false } ;
} ;
} ;
class Barrier {
class Barrier {