diff --git a/cmake/HPX_SetupBoost.cmake b/cmake/HPX_SetupBoost.cmake index 3d606e7bab94..299d89b8a0ee 100644 --- a/cmake/HPX_SetupBoost.cmake +++ b/cmake/HPX_SetupBoost.cmake @@ -64,7 +64,6 @@ endif() set(__boost_libraries ${__boost_libraries} atomic - date_time filesystem program_options regex diff --git a/hpx/runtime/threads/detail/periodic_maintenance.hpp b/hpx/runtime/threads/detail/periodic_maintenance.hpp index aee29c06c885..c8125b1ee8e6 100644 --- a/hpx/runtime/threads/detail/periodic_maintenance.hpp +++ b/hpx/runtime/threads/detail/periodic_maintenance.hpp @@ -11,10 +11,10 @@ #include #include #include -#include #include +#include -#include +#include #include #include @@ -46,10 +46,8 @@ namespace hpx { namespace threads { namespace detail if (running) { // create timer firing in correspondence with given time - typedef boost::asio::basic_deadline_timer< - util::steady_clock - , util::chrono_traits - > deadline_timer; + typedef boost::asio::basic_waitable_timer< + util::steady_clock> deadline_timer; deadline_timer t( get_thread_pool("timer-thread")->get_io_service(), @@ -77,10 +75,8 @@ namespace hpx { namespace threads { namespace detail scheduler.periodic_maintenance(is_running_state(global_state.load())); // create timer firing in correspondence with given time - typedef boost::asio::basic_deadline_timer< - util::steady_clock - , util::chrono_traits - > deadline_timer; + typedef boost::asio::basic_waitable_timer< + util::steady_clock> deadline_timer; deadline_timer t ( get_thread_pool("io-thread")->get_io_service(), diff --git a/hpx/runtime/threads/detail/set_thread_state.hpp b/hpx/runtime/threads/detail/set_thread_state.hpp index 9399ab3be91d..dfad442d1933 100644 --- a/hpx/runtime/threads/detail/set_thread_state.hpp +++ b/hpx/runtime/threads/detail/set_thread_state.hpp @@ -17,12 +17,11 @@ #include #include #include -#include #include #include #include -#include +#include #include #include @@ -307,10 +306,8 @@ namespace hpx { namespace threads { namespace detail create_thread(&scheduler, data, wake_id, suspended); // create timer firing in correspondence with given time - typedef boost::asio::basic_deadline_timer< - util::steady_clock - , util::chrono_traits - > deadline_timer; + typedef boost::asio::basic_waitable_timer< + util::steady_clock> deadline_timer; deadline_timer t ( get_thread_pool("timer-pool")->get_io_service(), abs_time); diff --git a/hpx/util/chrono_traits.hpp b/hpx/util/chrono_traits.hpp deleted file mode 100644 index bd09bfe3e513..000000000000 --- a/hpx/util/chrono_traits.hpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2007-2012 Hartmut Kaiser -// Copyright (c) 2014 Agustin Berge -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -#ifndef HPX_UTIL_CHRONO_TRAITS_HPP -#define HPX_UTIL_CHRONO_TRAITS_HPP - -#include - -#include - -#include - -namespace hpx { namespace util -{ - template - struct chrono_traits - { - typedef typename Clock::duration duration_type; - typedef typename Clock::time_point time_type; - - static time_type now() noexcept - { - return Clock::now(); - } - - static time_type add(time_type t, duration_type d) - { - return t + d; - } - - static duration_type subtract(time_type t1, time_type t2) - { - return t1 - t2; - } - - static bool less_than(time_type t1, time_type t2) - { - return t1 < t2; - } - - static boost::posix_time::time_duration to_posix_duration(duration_type d) - { -#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS - return boost::posix_time::nanoseconds( - std::chrono::duration_cast(d).count()); -#else - return boost::posix_time::microseconds( - std::chrono::duration_cast(d).count()); -#endif - } - }; -}} - -#endif /*HPX_UTIL_CHRONO_TRAITS_HPP*/ diff --git a/hpx/util/logging/format/formatter/high_precision_time.hpp b/hpx/util/logging/format/formatter/high_precision_time.hpp index 9e590b9c97f3..a680b204970f 100644 --- a/hpx/util/logging/format/formatter/high_precision_time.hpp +++ b/hpx/util/logging/format/formatter/high_precision_time.hpp @@ -27,10 +27,17 @@ #include // is_generic #include -#include -#include -#include - +#include +#include +#include + +#if defined(__linux) || defined(linux) || defined(__linux__) || defined(__FreeBSD__) +#elif defined(HPX_MSVC) +#else +#include +#include +hpx::lcos::local::spinlock gmtime_call_mutex; +#endif namespace hpx { namespace util { namespace logging { namespace formatter { @@ -83,48 +90,49 @@ template struct high_precision_time_ : non_const_context_base(format) {} template - void write_high_precision_time(msg_type & msg, ::boost::posix_time::ptime val) - const { - char_type buffer[64]; - - int nanosecs = static_cast(val.time_of_day().fractional_seconds()); //-V807 - int digits = static_cast(val.time_of_day().num_fractional_digits()); - switch ( digits) { - case 0: break; // no high precision at all - case 1: nanosecs *= 100000000; break; - case 2: nanosecs *= 10000000; break; - case 3: nanosecs *= 1000000; break; - case 4: nanosecs *= 100000; break; - case 5: nanosecs *= 10000; break; - case 6: nanosecs *= 1000; break; - case 7: nanosecs *= 100; break; - case 8: nanosecs *= 10; break; - case 9: break; - default: - while ( digits > 9) { - nanosecs /= 10; digits--; - } - break; + void write_high_precision_time(msg_type & msg, + std::chrono::time_point val) const + { + std::time_t tt = std::chrono::system_clock::to_time_t(val); + +#if defined(__linux) || defined(linux) || defined(__linux__) || defined(__FreeBSD__) + std::tm local_tm; + localtime_r(&tt, &local_tm); +#elif defined(HPX_MSVC) + std::tm local_tm; + localtime_s(&local_tm, &tt); +#else + // fall back to non-thread-safe version on other platforms + std::tm local_tm; + { + std::unique_lock ul(gmtime_call_mutex); + local_tm = *std::localtime(&tt); } +#endif + + std::chrono::nanoseconds nanosecs = std::chrono::duration_cast< + std::chrono::nanoseconds + >(val.time_since_epoch()); + std::chrono::microseconds microsecs = std::chrono::duration_cast< + std::chrono::microseconds + >(val.time_since_epoch()); + std::chrono::milliseconds millisecs = std::chrono::duration_cast< + std::chrono::milliseconds + >(val.time_since_epoch()); + + char_type buffer[64]; - non_const_context_base::context().write_time( buffer, - val.date().day(), //-V807 - val.date().month(), - val.date().year(), - val.time_of_day().hours(), - val.time_of_day().minutes(), - val.time_of_day().seconds(), - nanosecs / 1000000, - nanosecs / 1000, - nanosecs - ); + non_const_context_base::context().write_time(buffer, + local_tm.tm_mday, local_tm.tm_mon + 1, local_tm.tm_year + 1900, + local_tm.tm_hour, local_tm.tm_min, local_tm.tm_sec, + millisecs.count() % 1000, microsecs.count() % 1000, + nanosecs.count() % 1000); convert::write(buffer, msg); } template void operator()(msg_type & msg) const { - write_high_precision_time(msg, - ::boost::posix_time::microsec_clock::local_time() ); + write_high_precision_time(msg, std::chrono::system_clock::now()); } bool operator==(const high_precision_time_t & other) const { diff --git a/hpx/util/logging/profile.hpp b/hpx/util/logging/profile.hpp index 650c7cd2ddd4..fce3fc8a09d0 100644 --- a/hpx/util/logging/profile.hpp +++ b/hpx/util/logging/profile.hpp @@ -31,9 +31,7 @@ #include -#include -#include -#include +#include #include #include #include diff --git a/hpx/util/logging/tag/high_precision_time.hpp b/hpx/util/logging/tag/high_precision_time.hpp index fd40cdb3600e..ee63ead5cf4b 100644 --- a/hpx/util/logging/tag/high_precision_time.hpp +++ b/hpx/util/logging/tag/high_precision_time.hpp @@ -22,9 +22,6 @@ #endif #include -#include -#include -#include #include // is_generic #include // uses_tag @@ -33,6 +30,7 @@ #include // do_convert_format +#include namespace hpx { namespace util { namespace logging { @@ -48,8 +46,8 @@ namespace tag { See @ref hpx::util::logging::tag "how to use tags". */ struct high_precision_time { - high_precision_time() : val( ::boost::posix_time::microsec_clock::local_time() ) {} - ::boost::posix_time::ptime val; + high_precision_time() : val(std::chrono::system_clock::now()) {} + std::chrono::time_point val; }; } diff --git a/src/runtime/threads/executors/service_executor.cpp b/src/runtime/threads/executors/service_executor.cpp index 7593293ad157..f1fd5a55227a 100644 --- a/src/runtime/threads/executors/service_executor.cpp +++ b/src/runtime/threads/executors/service_executor.cpp @@ -11,13 +11,12 @@ #include #include #include -#include #include #include #include #include -#include +#include #include #include @@ -103,10 +102,7 @@ namespace hpx { namespace threads { namespace executors { namespace detail util::bind(&thread_wrapper_helper::invoke, wfp)); } - typedef boost::asio::basic_deadline_timer< - util::steady_clock - , util::chrono_traits - > steady_clock_deadline_timer; + typedef boost::asio::basic_waitable_timer deadline_timer; struct delayed_add_helper { @@ -129,7 +125,7 @@ namespace hpx { namespace threads { namespace executors { namespace detail service_executor* exec_; service_executor::closure_type f_; - steady_clock_deadline_timer timer_; + deadline_timer timer_; }; // Schedule given function for execution in this executor no sooner diff --git a/src/util/pool_timer.cpp b/src/util/pool_timer.cpp index 46cf8170a123..28fdb51f09fd 100644 --- a/src/util/pool_timer.cpp +++ b/src/util/pool_timer.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -18,7 +17,7 @@ #include #include -#include +#include #include #include @@ -57,10 +56,8 @@ namespace hpx { namespace util { namespace detail bool stop_locked(); private: - typedef boost::asio::basic_deadline_timer< - util::steady_clock, - util::chrono_traits - > deadline_timer; + typedef boost::asio::basic_waitable_timer< + util::steady_clock> deadline_timer; mutable mutex_type mtx_; util::function_nonser f_; ///< function to call diff --git a/tests/performance/local/coroutines_call_overhead.cpp b/tests/performance/local/coroutines_call_overhead.cpp index 590d048c3d3b..48384bd81fee 100644 --- a/tests/performance/local/coroutines_call_overhead.cpp +++ b/tests/performance/local/coroutines_call_overhead.cpp @@ -9,12 +9,13 @@ #include #include -#include #include #include #include +#include #include +#include #include #include #include @@ -39,12 +40,14 @@ bool header = true; /////////////////////////////////////////////////////////////////////////////// std::string format_build_date(std::string timestamp) { - boost::gregorian::date d = boost::gregorian::from_us_string(timestamp); + std::chrono::time_point now = + std::chrono::system_clock::now(); - char const* fmt = "%02i-%02i-%04i"; + std::time_t current_time = std::chrono::system_clock::to_time_t(now); - return boost::str(boost::format(fmt) - % d.month().as_number() % d.day() % d.year()); + std::string ts = std::ctime(¤t_time); + ts.resize(ts.size()-1); // remove trailing '\n' + return ts; } /////////////////////////////////////////////////////////////////////////////// diff --git a/tests/performance/local/delay_baseline.cpp b/tests/performance/local/delay_baseline.cpp index bd39bb99e743..6d53424747dd 100644 --- a/tests/performance/local/delay_baseline.cpp +++ b/tests/performance/local/delay_baseline.cpp @@ -11,13 +11,14 @@ #include +#include #include +#include #include #include #include #include -#include #include char const* benchmark_name = "Delay Baseline"; @@ -41,12 +42,14 @@ bool header = true; /////////////////////////////////////////////////////////////////////////////// std::string format_build_date(std::string timestamp) { - boost::gregorian::date d = boost::gregorian::from_us_string(timestamp); + std::chrono::time_point now = + std::chrono::system_clock::now(); - char const* fmt = "%02i-%02i-%04i"; + std::time_t current_time = std::chrono::system_clock::to_time_t(now); - return boost::str(boost::format(fmt) - % d.month().as_number() % d.day() % d.year()); + std::string ts = std::ctime(¤t_time); + ts.resize(ts.size()-1); // remove trailing '\n' + return ts; } /////////////////////////////////////////////////////////////////////////////// diff --git a/tests/performance/local/delay_baseline_threaded.cpp b/tests/performance/local/delay_baseline_threaded.cpp index 27ed405ebd2d..c7c9c10ccc50 100644 --- a/tests/performance/local/delay_baseline_threaded.cpp +++ b/tests/performance/local/delay_baseline_threaded.cpp @@ -11,7 +11,9 @@ #include #include +#include #include +#include #include #include #include @@ -19,7 +21,6 @@ #include #include -#include #include char const* benchmark_name = "Delay Baseline"; @@ -45,12 +46,14 @@ bool header = true; /////////////////////////////////////////////////////////////////////////////// std::string format_build_date(std::string timestamp) { - boost::gregorian::date d = boost::gregorian::from_us_string(timestamp); + std::chrono::time_point now = + std::chrono::system_clock::now(); - char const* fmt = "%02i-%02i-%04i"; + std::time_t current_time = std::chrono::system_clock::to_time_t(now); - return boost::str(boost::format(fmt) - % d.month().as_number() % d.day() % d.year()); + std::string ts = std::ctime(¤t_time); + ts.resize(ts.size()-1); // remove trailing '\n' + return ts; } /////////////////////////////////////////////////////////////////////////////// diff --git a/tests/performance/local/nonconcurrent_fifo_overhead.cpp b/tests/performance/local/nonconcurrent_fifo_overhead.cpp index 87ca90e52ed9..02cf64d87f51 100644 --- a/tests/performance/local/nonconcurrent_fifo_overhead.cpp +++ b/tests/performance/local/nonconcurrent_fifo_overhead.cpp @@ -15,10 +15,11 @@ #include #include -#include #include +#include #include +#include #include #include #include @@ -49,12 +50,14 @@ bool header = true; /////////////////////////////////////////////////////////////////////////////// std::string format_build_date(std::string timestamp) { - boost::gregorian::date d = boost::gregorian::from_us_string(timestamp); + std::chrono::time_point now = + std::chrono::system_clock::now(); - char const* fmt = "%02i-%02i-%04i"; + std::time_t current_time = std::chrono::system_clock::to_time_t(now); - return boost::str(boost::format(fmt) - % d.month().as_number() % d.day() % d.year()); + std::string ts = std::ctime(¤t_time); + ts.resize(ts.size()-1); // remove trailing '\n' + return ts; } /////////////////////////////////////////////////////////////////////////////// diff --git a/tests/performance/local/nonconcurrent_lifo_overhead.cpp b/tests/performance/local/nonconcurrent_lifo_overhead.cpp index 063a6d2ed889..0ad294027e6d 100644 --- a/tests/performance/local/nonconcurrent_lifo_overhead.cpp +++ b/tests/performance/local/nonconcurrent_lifo_overhead.cpp @@ -15,10 +15,11 @@ #include #include -#include #include +#include #include +#include #include #include #include @@ -49,12 +50,14 @@ bool header = true; /////////////////////////////////////////////////////////////////////////////// std::string format_build_date(std::string timestamp) { - boost::gregorian::date d = boost::gregorian::from_us_string(timestamp); + std::chrono::time_point now = + std::chrono::system_clock::now(); - char const* fmt = "%02i-%02i-%04i"; + std::time_t current_time = std::chrono::system_clock::to_time_t(now); - return boost::str(boost::format(fmt) - % d.month().as_number() % d.day() % d.year()); + std::string ts = std::ctime(¤t_time); + ts.resize(ts.size()-1); // remove trailing '\n' + return ts; } /////////////////////////////////////////////////////////////////////////////// diff --git a/tests/performance/local/timed_task_spawn.cpp b/tests/performance/local/timed_task_spawn.cpp index 4173560cc46c..fa4f73f09439 100644 --- a/tests/performance/local/timed_task_spawn.cpp +++ b/tests/performance/local/timed_task_spawn.cpp @@ -17,11 +17,12 @@ #include #include -#include #include #include +#include #include +#include #include #include #include @@ -70,12 +71,14 @@ std::uint64_t no_suspend_step = 1; /////////////////////////////////////////////////////////////////////////////// std::string format_build_date(std::string timestamp) { - boost::gregorian::date d = boost::gregorian::from_us_string(timestamp); + std::chrono::time_point now = + std::chrono::system_clock::now(); - char const* fmt = "%02i-%02i-%04i"; + std::time_t current_time = std::chrono::system_clock::to_time_t(now); - return boost::str(boost::format(fmt) - % d.month().as_number() % d.day() % d.year()); + std::string ts = std::ctime(¤t_time); + ts.resize(ts.size()-1); // remove trailing '\n' + return ts; } ///////////////////////////////////////////////////////////////////////////////