1
1
// License: Apache 2.0. See LICENSE file in root directory.
2
- // Copyright(c) 2024 Intel Corporation. All Rights Reserved.
2
+ // Copyright(c) 2025 Intel Corporation. All Rights Reserved.
3
3
#pragma once
4
4
5
5
#include < chrono>
@@ -20,8 +20,8 @@ class event
20
20
bool _is_set;
21
21
22
22
public:
23
- event ()
24
- : _is_set( false )
23
+ event ( bool is_set = false )
24
+ : _is_set( is_set )
25
25
{
26
26
}
27
27
@@ -47,16 +47,19 @@ class event
47
47
48
48
// Untrigger the event
49
49
// Does not affect any threads
50
- void clear ()
50
+ // Returns the previous state
51
+ bool clear ()
51
52
{
52
53
std::unique_lock< std::mutex > lock ( _m );
54
+ bool was_set = _is_set;
53
55
_is_set = false ;
56
+ return was_set;
54
57
}
55
58
56
59
// Block until the event is set()
57
60
// If already set, returns immediately
58
61
// The event remains set when returning: it needs to be cleared...
59
- void wait () const
62
+ void wait ()
60
63
{
61
64
std::unique_lock< std::mutex > lock ( _m );
62
65
if ( ! _is_set )
@@ -75,11 +78,11 @@ class event
75
78
// If already set, returns immediately
76
79
// Returns true unless a timeout occurred
77
80
template < class Rep , class Period >
78
- bool wait ( std::chrono::duration< Rep, Period > const & timeout ) const
81
+ bool wait ( std::chrono::duration< Rep, Period > const & timeout )
79
82
{
80
83
std::unique_lock< std::mutex > lock ( _m );
81
84
if ( ! _is_set )
82
- _is_set = ( std::cv_status::timeout != _cv.wait ( lock, timeout ) );
85
+ _is_set = ( std::cv_status::timeout != _cv.wait_for ( lock, timeout ) );
83
86
return _is_set;
84
87
}
85
88
@@ -90,7 +93,7 @@ class event
90
93
{
91
94
std::unique_lock< std::mutex > lock ( _m );
92
95
_is_set = false ;
93
- _is_set = ( std::cv_status::timeout != _cv.wait ( lock, timeout ) );
96
+ _is_set = ( std::cv_status::timeout != _cv.wait_for ( lock, timeout ) );
94
97
return _is_set;
95
98
}
96
99
};
0 commit comments