Skip to content

Commit c4d8bf6

Browse files
committed
fixes for rsutils event.h
1 parent 4a2bef0 commit c4d8bf6

File tree

1 file changed

+11
-8
lines changed
  • third-party/rsutils/include/rsutils/concurrency

1 file changed

+11
-8
lines changed

third-party/rsutils/include/rsutils/concurrency/event.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// 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.
33
#pragma once
44

55
#include <chrono>
@@ -20,8 +20,8 @@ class event
2020
bool _is_set;
2121

2222
public:
23-
event()
24-
: _is_set( false )
23+
event( bool is_set = false )
24+
: _is_set( is_set )
2525
{
2626
}
2727

@@ -47,16 +47,19 @@ class event
4747

4848
// Untrigger the event
4949
// Does not affect any threads
50-
void clear()
50+
// Returns the previous state
51+
bool clear()
5152
{
5253
std::unique_lock< std::mutex > lock( _m );
54+
bool was_set = _is_set;
5355
_is_set = false;
56+
return was_set;
5457
}
5558

5659
// Block until the event is set()
5760
// If already set, returns immediately
5861
// The event remains set when returning: it needs to be cleared...
59-
void wait() const
62+
void wait()
6063
{
6164
std::unique_lock< std::mutex > lock( _m );
6265
if( ! _is_set )
@@ -75,11 +78,11 @@ class event
7578
// If already set, returns immediately
7679
// Returns true unless a timeout occurred
7780
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 )
7982
{
8083
std::unique_lock< std::mutex > lock( _m );
8184
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 ) );
8386
return _is_set;
8487
}
8588

@@ -90,7 +93,7 @@ class event
9093
{
9194
std::unique_lock< std::mutex > lock( _m );
9295
_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 ) );
9497
return _is_set;
9598
}
9699
};

0 commit comments

Comments
 (0)