threads: fix race in stopping periodic thread

This commit is contained in:
Andre Puschmann 2021-05-27 21:15:20 +02:00
parent 312b5a241c
commit 1ef3cb7e5d
1 changed files with 5 additions and 4 deletions

View File

@ -35,6 +35,7 @@ void threads_print_self();
#ifdef __cplusplus #ifdef __cplusplus
} }
#include <atomic>
#include <string> #include <string>
namespace srsran { namespace srsran {
@ -129,10 +130,10 @@ protected:
virtual void run_period() = 0; virtual void run_period() = 0;
private: private:
int wakeups_missed; int wakeups_missed = 0;
int timer_fd; int timer_fd = 0;
int period_us; int period_us = 0;
bool run_enable; std::atomic<bool> run_enable = {false};
void run_thread() void run_thread()
{ {