Skip to content

Commit

Permalink
Merge pull request #2774 from STEllAR-GROUP/boost_date_time
Browse files Browse the repository at this point in the history
Removing dependency on Boost.Date_Time
  • Loading branch information
hkaiser committed Jul 22, 2017
2 parents aa739b7 + 0d9d74d commit 8e258e5
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 168 deletions.
1 change: 0 additions & 1 deletion cmake/HPX_SetupBoost.cmake
Expand Up @@ -64,7 +64,6 @@ endif()
set(__boost_libraries
${__boost_libraries}
atomic
date_time
filesystem
program_options
regex
Expand Down
16 changes: 6 additions & 10 deletions hpx/runtime/threads/detail/periodic_maintenance.hpp
Expand Up @@ -11,10 +11,10 @@
#include <hpx/runtime_fwd.hpp>
#include <hpx/state.hpp>
#include <hpx/util/bind.hpp>
#include <hpx/util/chrono_traits.hpp>
#include <hpx/util/io_service_pool.hpp>
#include <hpx/util/steady_clock.hpp>

#include <boost/asio/basic_deadline_timer.hpp>
#include <boost/asio/basic_waitable_timer.hpp>
#include <boost/atomic.hpp>

#include <chrono>
Expand Down Expand Up @@ -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<util::steady_clock>
> deadline_timer;
typedef boost::asio::basic_waitable_timer<
util::steady_clock> deadline_timer;

deadline_timer t(
get_thread_pool("timer-thread")->get_io_service(),
Expand Down Expand Up @@ -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<util::steady_clock>
> deadline_timer;
typedef boost::asio::basic_waitable_timer<
util::steady_clock> deadline_timer;

deadline_timer t (
get_thread_pool("io-thread")->get_io_service(),
Expand Down
9 changes: 3 additions & 6 deletions hpx/runtime/threads/detail/set_thread_state.hpp
Expand Up @@ -17,12 +17,11 @@
#include <hpx/runtime_fwd.hpp>
#include <hpx/throw_exception.hpp>
#include <hpx/util/bind.hpp>
#include <hpx/util/chrono_traits.hpp>
#include <hpx/util/io_service_pool.hpp>
#include <hpx/util/logging.hpp>
#include <hpx/util/steady_clock.hpp>

#include <boost/asio/basic_deadline_timer.hpp>
#include <boost/asio/basic_waitable_timer.hpp>
#include <boost/atomic.hpp>

#include <chrono>
Expand Down Expand Up @@ -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<util::steady_clock>
> 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);
Expand Down
57 changes: 0 additions & 57 deletions hpx/util/chrono_traits.hpp

This file was deleted.

86 changes: 47 additions & 39 deletions hpx/util/logging/format/formatter/high_precision_time.hpp
Expand Up @@ -27,10 +27,17 @@
#include <hpx/util/logging/detail/manipulator.hpp> // is_generic
#include <hpx/util/logging/detail/time_format_holder.hpp>

#include <boost/date_time/microsec_time_clock.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/date_time/posix_time/ptime.hpp>

#include <chrono>
#include <cstdint>
#include <ctime>

#if defined(__linux) || defined(linux) || defined(__linux__) || defined(__FreeBSD__)
#elif defined(HPX_MSVC)
#else
#include <hpx/lcos/local/spinlock.hpp>
#include <mutex>
hpx::lcos::local::spinlock gmtime_call_mutex;
#endif

namespace hpx { namespace util { namespace logging { namespace formatter {

Expand Down Expand Up @@ -83,48 +90,49 @@ template<class convert = do_convert_format::prepend> struct high_precision_time_
: non_const_context_base(format) {}

template<class msg_type>
void write_high_precision_time(msg_type & msg, ::boost::posix_time::ptime val)
const {
char_type buffer[64];

int nanosecs = static_cast<int>(val.time_of_day().fractional_seconds()); //-V807
int digits = static_cast<int>(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<std::chrono::system_clock> 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<hpx::lcos::local::spinlock> 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<class msg_type> 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 {
Expand Down
13 changes: 6 additions & 7 deletions hpx/util/logging/profile.hpp
Expand Up @@ -31,9 +31,7 @@

#include <hpx/util/function.hpp>

#include <boost/date_time/microsec_time_clock.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/date_time/posix_time/ptime.hpp>
#include <chrono>
#include <cstdint>
#include <sstream>
#include <string>
Expand Down Expand Up @@ -179,14 +177,15 @@ struct scoped_compute {
compute& m_comp;
compute::type m_type;

::boost::posix_time::ptime m_start, m_end;
std::chrono::time_point<std::chrono::system_clock> m_start, m_end;

scoped_compute(compute& comp, compute::type type) : m_comp(comp), m_type(type) {
m_start = ::boost::posix_time::microsec_clock::local_time();
m_start = std::chrono::system_clock::now();
}
~scoped_compute() {
m_end = ::boost::posix_time::microsec_clock::local_time();
m_comp.add_period( (m_end - m_start).total_microseconds() , m_type);
m_end = std::chrono::system_clock::now();
m_comp.add_period(std::chrono::duration_cast<std::chrono::microseconds>(
m_end - m_start).count(), m_type);
}

};
Expand Down
8 changes: 3 additions & 5 deletions hpx/util/logging/tag/high_precision_time.hpp
Expand Up @@ -22,9 +22,6 @@
#endif

#include <hpx/util/logging/detail/fwd.hpp>
#include <boost/date_time/posix_time/ptime.hpp>
#include <boost/date_time/microsec_time_clock.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>

#include <hpx/util/logging/detail/manipulator.hpp> // is_generic
#include <hpx/util/logging/format/formatter/tags.hpp> // uses_tag
Expand All @@ -33,6 +30,7 @@
#include <hpx/util/logging/format/formatter/convert_format.hpp>
// do_convert_format

#include <chrono>

namespace hpx { namespace util { namespace logging {

Expand All @@ -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::system_clock::time_point val;
};

}
Expand Down
10 changes: 3 additions & 7 deletions src/runtime/threads/executors/service_executor.cpp
Expand Up @@ -11,13 +11,12 @@
#include <hpx/runtime_fwd.hpp>
#include <hpx/runtime/threads/thread_enums.hpp>
#include <hpx/util/bind.hpp>
#include <hpx/util/chrono_traits.hpp>
#include <hpx/util/io_service_pool.hpp>
#include <hpx/util/steady_clock.hpp>
#include <hpx/util/thread_description.hpp>
#include <hpx/util/unique_function.hpp>

#include <boost/asio/basic_deadline_timer.hpp>
#include <boost/asio/basic_waitable_timer.hpp>

#include <chrono>
#include <cstddef>
Expand Down Expand Up @@ -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<util::steady_clock>
> steady_clock_deadline_timer;
typedef boost::asio::basic_waitable_timer<util::steady_clock> deadline_timer;

struct delayed_add_helper
{
Expand All @@ -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
Expand Down
9 changes: 3 additions & 6 deletions src/util/pool_timer.cpp
Expand Up @@ -10,15 +10,14 @@
#include <hpx/runtime/shutdown_function.hpp>
#include <hpx/util/assert.hpp>
#include <hpx/util/bind.hpp>
#include <hpx/util/chrono_traits.hpp>
#include <hpx/util/function.hpp>
#include <hpx/util/io_service_pool.hpp>
#include <hpx/util/pool_timer.hpp>
#include <hpx/util/steady_clock.hpp>
#include <hpx/util/unlock_guard.hpp>
#include <hpx/lcos/local/spinlock.hpp>

#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/basic_waitable_timer.hpp>

#include <chrono>
#include <memory>
Expand Down Expand Up @@ -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<util::steady_clock>
> deadline_timer;
typedef boost::asio::basic_waitable_timer<
util::steady_clock> deadline_timer;

mutable mutex_type mtx_;
util::function_nonser<bool()> f_; ///< function to call
Expand Down
13 changes: 8 additions & 5 deletions tests/performance/local/coroutines_call_overhead.cpp
Expand Up @@ -9,12 +9,13 @@
#include <hpx/hpx.hpp>

#include <boost/format.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/random.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>

#include <chrono>
#include <cstdint>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
Expand All @@ -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<std::chrono::system_clock> 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(&current_time);
ts.resize(ts.size()-1); // remove trailing '\n'
return ts;
}

///////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 8e258e5

Please sign in to comment.