aboutsummaryrefslogtreecommitdiffstats
path: root/include/dumb_timer_queue.h
diff options
context:
space:
mode:
authoripkn <ipknhama@gmail.com>2014-08-17 05:35:21 -0400
committeripkn <ipknhama@gmail.com>2014-08-17 05:35:21 -0400
commitdaa3c820878f8e189120cf9359caf8b2359d61ca (patch)
tree2c8ea578483bc9ef16c539c76ac6f0e9b10df363 /include/dumb_timer_queue.h
parent79bbdfebfaff295f468bd9e2d46e8106693eb113 (diff)
downloadcrow-daa3c820878f8e189120cf9359caf8b2359d61ca.tar.gz
crow-daa3c820878f8e189120cf9359caf8b2359d61ca.zip
improve performance by 2x
change to io_service per CPU model
Diffstat (limited to 'include/dumb_timer_queue.h')
-rw-r--r--include/dumb_timer_queue.h12
1 files changed, 4 insertions, 8 deletions
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<void()> 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<std::pair<decltype(std::chrono::steady_clock::now()), std::function<void()>>> dq_;
- std::mutex mutex_;
int step_{};
};
}