Commit fdef7ff33f675d12b132bf9fcfaee1a4ea81a13f
1 parent
b18af18a
Mutex callbacks vector in timer
This is theoretical, because I never called addCallback() after having started the timer.
Showing
2 changed files
with
6 additions
and
0 deletions
timer.cpp
| ... | ... | @@ -82,6 +82,8 @@ void Timer::addCallback(std::function<void ()> f, uint64_t interval_ms, const st |
| 82 | 82 | { |
| 83 | 83 | logger->logf(LOG_DEBUG, "Adding event '%s' to the timer with an interval of %ld ms.", name.c_str(), interval_ms); |
| 84 | 84 | |
| 85 | + std::lock_guard<std::mutex> locker(this->callbacksMutex); | |
| 86 | + | |
| 85 | 87 | CallbackEntry c; |
| 86 | 88 | c.f = f; |
| 87 | 89 | c.interval = interval_ms; |
| ... | ... | @@ -137,6 +139,9 @@ void Timer::process() |
| 137 | 139 | } |
| 138 | 140 | |
| 139 | 141 | logger->logf(LOG_DEBUG, "Calling timed event '%s'.", callbacks.front().name.c_str()); |
| 142 | + | |
| 143 | + std::lock_guard<std::mutex> locker(this->callbacksMutex); | |
| 144 | + | |
| 140 | 145 | CallbackEntry &c = callbacks.front(); |
| 141 | 146 | c.updateExectedAt(); |
| 142 | 147 | c.f(); | ... | ... |