Skip to content

Commit d28abe6

Browse files
committed
make thread sanitize happy
1 parent 0695546 commit d28abe6

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

include/behaviortree_cpp/utils/wakeup_signal.hpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <chrono>
55
#include <mutex>
6+
#include <atomic>
67
#include <condition_variable>
78

89
namespace BT
@@ -15,31 +16,28 @@ class WakeUpSignal
1516
/// signal was received.
1617
bool waitFor(std::chrono::microseconds usec)
1718
{
18-
if(usec.count() > 0) {
19-
std::unique_lock<std::mutex> lk(mutex_);
20-
auto res = cv_.wait_for(lk, usec, [this]{
21-
return ready_;
22-
});
23-
ready_ = false;
24-
return res;
19+
if(usec.count() <= 0) {
20+
return ready_.load();
2521
}
26-
return ready_;
22+
std::unique_lock<std::mutex> lk(mutex_);
23+
auto res = cv_.wait_for(lk, usec, [this]{
24+
return ready_.load();
25+
});
26+
ready_ = false;
27+
return res;
2728
}
2829

2930
void emitSignal()
3031
{
31-
{
32-
std::lock_guard<std::mutex> lk(mutex_);
33-
ready_ = true;
34-
}
32+
ready_ = true;
3533
cv_.notify_all();
3634
}
3735

3836
private:
3937

4038
std::mutex mutex_;
4139
std::condition_variable cv_;
42-
bool ready_ = false;
40+
std::atomic_bool ready_ = false;
4341
};
4442

4543
}

0 commit comments

Comments
 (0)