MT#62181 wheeltimer: add shutdown procedure

Add flag to stop the thread and then wait for it to actually stop.

Change-Id: Ibdcf68b7e574301dec3abcf1c2ac57182503214c
mr13.3.1
Richard Fuchs 1 year ago
parent 7e59c46309
commit eb377da959

@ -74,7 +74,7 @@ void _wheeltimer::remove_timer(timer* t)
void _wheeltimer::run()
{
while(true){
while(!stopped){
// figure out whether there's anything to run, and for how long to sleep
@ -112,6 +112,8 @@ void _wheeltimer::run()
// all done, remove bucket
buckets.erase(beg);
}
shutdown_finished.set(true);
}
void _wheeltimer::process_current_timers(timer_list& list, std::unique_lock<std::mutex>& lock)

@ -124,6 +124,9 @@ class _wheeltimer:
// future (or if no timers exist). Needed not to miss the shutdown flag being set.
const uint64_t max_sleep_time = 500000; // half a second
atomic_bool stopped;
AmCondition shutdown_finished;
void place_timer(timer* t, uint64_t, uint64_t);
void add_timer_to_bucket(timer* t, uint64_t);
@ -135,15 +138,18 @@ class _wheeltimer:
protected:
void run();
void on_stop(){}
void on_stop(){
stopped = true;
shutdown_finished.wait_for();
}
_wheeltimer()
: resolution(20000) // 20 ms == 20000 us
{}
: resolution(20000), // 20 ms == 20000 us
stopped(false), shutdown_finished(false) {}
_wheeltimer(uint64_t _resolution)
: resolution(_resolution)
{}
: resolution(_resolution),
stopped(false), shutdown_finished(false) {}
public:
//clock reference

Loading…
Cancel
Save