1919 */
2020
2121#include " logging.hpp"
22+ #include " util.hpp"
2223
2324#include < osmium/thread/function_wrapper.hpp>
2425#include < osmium/thread/queue.hpp>
@@ -41,7 +42,7 @@ class task_result_t
4142 * Initialize this result with the future obtained from the
4243 * thread_pool_t::submit() function.
4344 */
44- void set (std::future<std::chrono::milliseconds > &&future)
45+ void set (std::future<std::chrono::microseconds > &&future)
4546 {
4647 m_future = std::move (future);
4748 }
@@ -52,17 +53,17 @@ class task_result_t
5253 * \return The runtime of the task.
5354 * \throws Any exception the task has thrown.
5455 */
55- std::chrono::milliseconds wait ();
56+ std::chrono::microseconds wait ();
5657
5758 /* *
5859 * Return the run-time of this task. Will be 0 if the task has not
5960 * yet finished or >0 if the task has finished.
6061 */
61- std::chrono::milliseconds runtime () const noexcept { return m_result; }
62+ std::chrono::microseconds runtime () const noexcept { return m_result; }
6263
6364private:
64- std::future<std::chrono::milliseconds > m_future{};
65- std::chrono::milliseconds m_result{};
65+ std::future<std::chrono::microseconds > m_future{};
66+ std::chrono::microseconds m_result{};
6667}; // class task_result_t
6768
6869/* *
@@ -96,23 +97,21 @@ class thread_pool_t
9697 * of the task can be queried.
9798 */
9899 template <typename TFunction>
99- std::future<std::chrono::milliseconds > submit (TFunction &&func)
100+ std::future<std::chrono::microseconds > submit (TFunction &&func)
100101 {
101- std::packaged_task<std::chrono::milliseconds ()> task{
102+ std::packaged_task<std::chrono::microseconds ()> task{
102103 [f = std::forward<TFunction>(func)]() {
103104 log_debug (" Starting task..." );
104- auto const start_time = std::chrono::steady_clock::now () ;
105+ util:: timer_t timer ;
105106 f ();
106- auto const end_time = std::chrono::steady_clock::now ();
107- auto const run_time =
108- std::chrono::duration_cast<std::chrono::milliseconds>(
109- end_time - start_time );
107+ timer. stop ();
108+ log_debug ( " Done task in {}. " ,
109+ std::chrono::duration_cast<std::chrono::milliseconds>(
110+ timer. elapsed ()) );
110111
111- log_debug (" Done task in {}." , run_time);
112-
113- return run_time;
112+ return timer.elapsed ();
114113 }};
115- std::future<std::chrono::milliseconds > future_result{task.get_future ()};
114+ std::future<std::chrono::microseconds > future_result{task.get_future ()};
116115 m_work_queue.push (std::move (task));
117116
118117 return future_result;
0 commit comments