Skip to content

Commit d2dc8f9

Browse files
committed
Test for joinable needs to be done first.
Testing for joinable will make sure that if a timer is re-used that a 2nd start() command will have to wait till the timer has finished.
1 parent 6e94616 commit d2dc8f9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

CppTimer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class CppTimer
4444
* @param type Either PERIODIC or ONESHOT
4545
**/
4646
virtual void startns(long nanosecs, cppTimerType_t t = PERIODIC) {
47-
if (running) return;
4847
if (uthread.joinable()) uthread.join();
48+
if (running) return;
4949
timerType = t;
5050
if (fd < 0)
5151
throw("Could not start timer");
@@ -81,8 +81,8 @@ class CppTimer
8181
* @param type Either PERIODIC or ONESHOT
8282
**/
8383
virtual void startms(long millisecs, cppTimerType_t t = PERIODIC) {
84-
if (running) return;
8584
if (uthread.joinable()) uthread.join();
85+
if (running) return;
8686
timerType = t;
8787
if (fd < 0)
8888
throw("Could not start timer");

0 commit comments

Comments
 (0)