fix(simu): restarting timer_queue (#6232)
This commit is contained in:
@@ -80,7 +80,8 @@ void task_shutdown_all()
|
|||||||
pthread_join(task, nullptr);
|
pthread_join(task, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
timer_queue::instance().stop();
|
timer_queue::destroy();
|
||||||
|
_stop_tasks = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct run_context {
|
struct run_context {
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
static timer_queue* _instance = nullptr;
|
||||||
|
static std::mutex _instance_mut;
|
||||||
|
|
||||||
bool _timer_cmp(timer_handle_t *lh, timer_handle_t *rh) {
|
bool _timer_cmp(timer_handle_t *lh, timer_handle_t *rh) {
|
||||||
return lh->next_trigger < rh->next_trigger;
|
return lh->next_trigger < rh->next_trigger;
|
||||||
}
|
}
|
||||||
@@ -22,8 +25,21 @@ void timer_queue::sort_timers() {
|
|||||||
|
|
||||||
timer_queue& timer_queue::instance()
|
timer_queue& timer_queue::instance()
|
||||||
{
|
{
|
||||||
static timer_queue _instance;
|
std::lock_guard<std::mutex> lock(_instance_mut);
|
||||||
return _instance;
|
if (!_instance) {
|
||||||
|
_instance = new timer_queue();
|
||||||
|
}
|
||||||
|
return *_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void timer_queue::destroy()
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(_instance_mut);
|
||||||
|
if (_instance) {
|
||||||
|
_instance->stop();
|
||||||
|
delete _instance;
|
||||||
|
_instance = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void timer_queue::start()
|
void timer_queue::start()
|
||||||
|
|||||||
@@ -41,5 +41,5 @@ struct timer_handle_t {
|
|||||||
std::atomic_bool active;
|
std::atomic_bool active;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define TIMER_INITIALIZER {}
|
#define TIMER_INITIALIZER {0}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ struct timer_req_t {
|
|||||||
class timer_queue {
|
class timer_queue {
|
||||||
|
|
||||||
std::unique_ptr<std::thread> _thread;
|
std::unique_ptr<std::thread> _thread;
|
||||||
bool _running;
|
bool _running = false;
|
||||||
|
|
||||||
std::deque<timer_req_t> _cmds;
|
std::deque<timer_req_t> _cmds;
|
||||||
std::mutex _cmds_mutex;
|
std::mutex _cmds_mutex;
|
||||||
@@ -54,18 +54,19 @@ class timer_queue {
|
|||||||
void async_calls();
|
void async_calls();
|
||||||
void process_cmds();
|
void process_cmds();
|
||||||
void send_cmd(timer_req_t&& req);
|
void send_cmd(timer_req_t&& req);
|
||||||
|
void stop();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
timer_queue(timer_queue const &) = delete;
|
timer_queue(timer_queue const &) = delete;
|
||||||
void operator=(timer_queue const &) = delete;
|
void operator=(timer_queue const &) = delete;
|
||||||
|
|
||||||
static timer_queue &instance();
|
static timer_queue &instance();
|
||||||
|
static void destroy();
|
||||||
|
|
||||||
static void create_timer(timer_handle_t *timer, timer_func_t func, const char *name,
|
static void create_timer(timer_handle_t *timer, timer_func_t func, const char *name,
|
||||||
unsigned period, bool repeat);
|
unsigned period, bool repeat);
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
|
||||||
|
|
||||||
void start_timer(timer_handle_t *timer);
|
void start_timer(timer_handle_t *timer);
|
||||||
void stop_timer(timer_handle_t *timer);
|
void stop_timer(timer_handle_t *timer);
|
||||||
|
|||||||
Reference in New Issue
Block a user