aboutsummaryrefslogtreecommitdiffstats
path: root/amalgamate/crow_all.h
diff options
context:
space:
mode:
Diffstat (limited to 'amalgamate/crow_all.h')
-rw-r--r--amalgamate/crow_all.h183
1 files changed, 94 insertions, 89 deletions
diff --git a/amalgamate/crow_all.h b/amalgamate/crow_all.h
index de3b1c9..9e40013 100644
--- a/amalgamate/crow_all.h
+++ b/amalgamate/crow_all.h
@@ -1941,94 +1941,6 @@ namespace crow
-#pragma once
-
-#include <boost/asio.hpp>
-#include <deque>
-#include <functional>
-#include <chrono>
-#include <thread>
-
-namespace crow
-{
- namespace detail
- {
- // fast timer queue for fixed tick value.
- class dumb_timer_queue
- {
- public:
- // tls based queue to avoid locking
- static dumb_timer_queue& get_current_dumb_timer_queue()
- {
- thread_local dumb_timer_queue q;
- return q;
- }
-
- using key = std::pair<dumb_timer_queue*, int>;
-
- void cancel(key& k)
- {
- auto self = k.first;
- k.first = nullptr;
- if (!self)
- return;
-
- unsigned int index = (unsigned int)(k.second - self->step_);
- if (index < self->dq_.size())
- self->dq_[index].second = nullptr;
- }
-
- key add(std::function<void()> f)
- {
- dq_.emplace_back(std::chrono::steady_clock::now(), std::move(f));
- int ret = step_+dq_.size()-1;
-
- CROW_LOG_DEBUG << "timer add inside: " << this << ' ' << ret ;
- return {this, ret};
- }
-
- void process()
- {
- if (!io_service_)
- return;
-
- auto now = std::chrono::steady_clock::now();
- while(!dq_.empty())
- {
- auto& x = dq_.front();
- if (now - x.first < std::chrono::seconds(tick))
- break;
- if (x.second)
- {
- CROW_LOG_DEBUG << "timer call: " << this << ' ' << step_;
- // we know that timer handlers are very simple currenty; call here
- x.second();
- }
- dq_.pop_front();
- step_++;
- }
- }
-
- void set_io_service(boost::asio::io_service& io_service)
- {
- io_service_ = &io_service;
- }
-
- private:
- dumb_timer_queue() noexcept
- {
- }
-
- int tick{5};
- boost::asio::io_service* io_service_{};
- std::deque<std::pair<decltype(std::chrono::steady_clock::now()), std::function<void()>>> dq_;
- int step_{};
- };
- }
-}
-
-
-
/* merged revision: 5b951d74bd66ec9d38448e0a85b1cf8b85d97db3 */
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
*
@@ -4803,8 +4715,10 @@ namespace crow
WARNING = 2
ERROR = 3
CRITICAL = 4
+
+ default to INFO
*/
-#define CROW_LOG_LEVEL 0
+#define CROW_LOG_LEVEL 1
@@ -4941,6 +4855,97 @@ namespace crow
#pragma once
+#include <boost/asio.hpp>
+#include <deque>
+#include <functional>
+#include <chrono>
+#include <thread>
+
+
+
+
+namespace crow
+{
+ namespace detail
+ {
+ // fast timer queue for fixed tick value.
+ class dumb_timer_queue
+ {
+ public:
+ // tls based queue to avoid locking
+ static dumb_timer_queue& get_current_dumb_timer_queue()
+ {
+ thread_local dumb_timer_queue q;
+ return q;
+ }
+
+ using key = std::pair<dumb_timer_queue*, int>;
+
+ void cancel(key& k)
+ {
+ auto self = k.first;
+ k.first = nullptr;
+ if (!self)
+ return;
+
+ unsigned int index = (unsigned int)(k.second - self->step_);
+ if (index < self->dq_.size())
+ self->dq_[index].second = nullptr;
+ }
+
+ key add(std::function<void()> f)
+ {
+ dq_.emplace_back(std::chrono::steady_clock::now(), std::move(f));
+ int ret = step_+dq_.size()-1;
+
+ CROW_LOG_DEBUG << "timer add inside: " << this << ' ' << ret ;
+ return {this, ret};
+ }
+
+ void process()
+ {
+ if (!io_service_)
+ return;
+
+ auto now = std::chrono::steady_clock::now();
+ while(!dq_.empty())
+ {
+ auto& x = dq_.front();
+ if (now - x.first < std::chrono::seconds(tick))
+ break;
+ if (x.second)
+ {
+ CROW_LOG_DEBUG << "timer call: " << this << ' ' << step_;
+ // we know that timer handlers are very simple currenty; call here
+ x.second();
+ }
+ dq_.pop_front();
+ step_++;
+ }
+ }
+
+ void set_io_service(boost::asio::io_service& io_service)
+ {
+ io_service_ = &io_service;
+ }
+
+ private:
+ dumb_timer_queue() noexcept
+ {
+ }
+
+ int tick{5};
+ boost::asio::io_service* io_service_{};
+ std::deque<std::pair<decltype(std::chrono::steady_clock::now()), std::function<void()>>> dq_;
+ int step_{};
+ };
+ }
+}
+
+
+
+#pragma once
+
#include <cstdint>
#include <stdexcept>
#include <tuple>