From daa3c820878f8e189120cf9359caf8b2359d61ca Mon Sep 17 00:00:00 2001 From: ipkn Date: Sun, 17 Aug 2014 05:35:21 -0400 Subject: improve performance by 2x change to io_service per CPU model --- include/dumb_timer_queue.h | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'include/dumb_timer_queue.h') diff --git a/include/dumb_timer_queue.h b/include/dumb_timer_queue.h index ebb8bb1..86ec7c1 100644 --- a/include/dumb_timer_queue.h +++ b/include/dumb_timer_queue.h @@ -29,19 +29,17 @@ namespace crow k.first = nullptr; if (!self) return; - self->mutex_.lock(); + unsigned int index = (unsigned int)(k.second - self->step_); if (index < self->dq_.size()) self->dq_[index].second = nullptr; - self->mutex_.unlock(); } key add(std::function f) { - mutex_.lock(); dq_.emplace_back(std::chrono::steady_clock::now(), std::move(f)); int ret = step_+dq_.size()-1; - mutex_.unlock(); + CROW_LOG_DEBUG << "timer add inside: " << this << ' ' << ret ; return {this, ret}; } @@ -50,7 +48,7 @@ namespace crow { if (!io_service_) return; - mutex_.lock(); + auto now = std::chrono::steady_clock::now(); while(!dq_.empty()) { @@ -60,13 +58,12 @@ namespace crow if (x.second) { CROW_LOG_DEBUG << "timer call: " << this << ' ' << step_; - //io_service_->post(std::move(x.second)); + // we know that timer handlers are very simple currenty; call here x.second(); } dq_.pop_front(); step_++; } - mutex_.unlock(); } void set_io_service(boost::asio::io_service& io_service) @@ -82,7 +79,6 @@ namespace crow int tick{5}; boost::asio::io_service* io_service_{}; std::deque>> dq_; - std::mutex mutex_; int step_{}; }; } -- cgit v1.2.3-54-g00ecf