Skip to content

Commit acfd5c3

Browse files
committed
Add pauseLock
1 parent 7f22a3c commit acfd5c3

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

looping_thread.hpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class LoopingThread {
2323
std::timed_mutex waitMutex_;
2424
std::unique_lock<std::timed_mutex> waitLock_;
2525
std::mutex pauseMutex_;
26+
std::unique_lock<std::mutex> pauseLock_;
2627
std::mutex resumeMutex_;
2728
std::unique_lock<std::mutex> resumeLock_;
2829
bool exiting_ = false;
@@ -34,7 +35,6 @@ class LoopingThread {
3435
inline void work()
3536
{
3637
std::chrono::steady_clock::time_point awakenAt = std::chrono::steady_clock::now();
37-
std::unique_lock<std::mutex> pauseLock(pauseMutex_);
3838
while (true) {
3939
bool interrupted = false;
4040
{
@@ -53,9 +53,9 @@ class LoopingThread {
5353

5454
if (interrupted) {
5555
if (exiting_) break;
56-
pauseLock.unlock();
56+
pauseLock_.unlock();
5757
std::unique_lock<std::mutex> lock(resumeMutex_);
58-
pauseLock.lock();
58+
pauseLock_.lock();
5959
} else {
6060
try {
6161
routine_();
@@ -92,6 +92,7 @@ class LoopingThread {
9292
period_(period),
9393
routine_(routine),
9494
waitLock_(waitMutex_, std::defer_lock),
95+
pauseLock_(pauseMutex_),
9596
resumeLock_(resumeMutex_),
9697
paused_(true),
9798
resetTimeOnPause_(false),
@@ -114,6 +115,7 @@ class LoopingThread {
114115
else
115116
waitLock_.unlock();
116117
worker_.join();
118+
pauseLock_.unlock();
117119
}
118120
}
119121

0 commit comments

Comments
 (0)