@@ -117,6 +117,8 @@ manapi::error::status manapi::timerpool::again_timer(std::shared_ptr<manapi::tim
117117 if (!res.second )
118118 return error::status_internal (" timerpool:insert failed" );
119119
120+ if (res.first == this ->data_ ->sorted_tasks .begin ())
121+ reinit_timer_ (this ->data_ );
120122
121123 if (res.first ->second ->flags & TIMER_TASK_IMPORTANT) {
122124 this ->data_ ->importants ++;
@@ -130,9 +132,6 @@ manapi::error::status manapi::timerpool::again_timer(std::shared_ptr<manapi::tim
130132 }
131133 }
132134
133- if (res.first == this ->data_ ->sorted_tasks .begin ())
134- reinit_timer_ (this ->data_ );
135-
136135 return error::status_ok ();
137136 }
138137 catch (std::bad_alloc const &) {
@@ -216,10 +215,10 @@ void manapi::timerpool::erase_task_(const std::shared_ptr<data_t> &data_,sorted_
216215}
217216
218217void manapi::timerpool::start_ (const std::shared_ptr<data_t > &data) MANAPIHTTP_NOEXCEPT {
219- // if (data->flags & TIMERPOOL_FLAG_RUNNING) {
220- // /* it is already running */
221- // return;
222- // }
218+ if (data->flags & TIMERPOOL_FLAG_RUNNING) {
219+ /* it is already running */
220+ return ;
221+ }
223222
224223 auto now = std::chrono::steady_clock::now ();
225224 data->flags |= TIMERPOOL_FLAG_RUNNING;
@@ -293,14 +292,10 @@ int64_t manapi::timerpool::calculate_repeat_(const std::shared_ptr<data_t> &data
293292
294293bool manapi::timerpool::reinit_timer_ (const std::shared_ptr<data_t > &data_) MANAPIHTTP_NOEXCEPT {
295294 if (data_->timer ) {
296- data_->timer ->stop ();
297-
298- auto delay = calculate_repeat_ (data_);
299- // manapi_log_trace(manapi::debug::LOG_TRACE_LOW, "reinit_timer:delay=%llu now=%llu", delay, std::chrono::steady_clock::now().time_since_epoch());
300-
295+ auto const delay = calculate_repeat_ (data_);
301296 if (delay >= 0 ) {
302297 if (data_->timer ->is_active ()) {
303- data_->timer ->start (delay, 1 );
298+ data_->timer ->repeat (delay);
304299 if (data_->timer ->again ()) {
305300 manapi_log_error (" set the timerpool again failed" );
306301 return false ;
@@ -310,6 +305,9 @@ bool manapi::timerpool::reinit_timer_(const std::shared_ptr<data_t> &data_) MANA
310305 data_->timer ->start (delay, 1 );
311306 }
312307 }
308+ else {
309+ data_->timer ->stop ();
310+ }
313311 }
314312
315313 return true ;
@@ -359,7 +357,7 @@ manapi::error::status manapi::timerpool::update_interval_state_(const std::share
359357 data_->importants ++;
360358 }
361359
362- if (data_->sorted_tasks .begin ()-> second == data ) {
360+ if (data_->sorted_tasks .begin () == res. first ) {
363361 reinit_timer_ (data_);
364362 }
365363
0 commit comments