diff options
-rw-r--r-- | include/gras/CMakeLists.txt | 1 | ||||
-rw-r--r-- | include/gras/chrono.hpp | 77 | ||||
-rw-r--r-- | lib/gras_impl/block_actor.hpp | 1 |
3 files changed, 79 insertions, 0 deletions
diff --git a/include/gras/CMakeLists.txt b/include/gras/CMakeLists.txt index f0b0d3a..0ec3c98 100644 --- a/include/gras/CMakeLists.txt +++ b/include/gras/CMakeLists.txt @@ -3,6 +3,7 @@ ######################################################################## install(FILES + chrono.hpp block.hpp block.i element.hpp diff --git a/include/gras/chrono.hpp b/include/gras/chrono.hpp new file mode 100644 index 0000000..dc013cc --- /dev/null +++ b/include/gras/chrono.hpp @@ -0,0 +1,77 @@ +// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. + +//Boost chrono has awesome high res timer! +//But its only in very recent boosts, +//so we have this little wrapper... + +#ifndef INCLUDED_GRAS_CHRONO_HPP +#define INCLUDED_GRAS_CHRONO_HPP + +#include <gras/gras.hpp> +#include <boost/version.hpp> + +#if BOOST_VERSION >= 104700 +#include <boost/chrono.hpp> + +namespace gras +{ + +namespace chrono +{ + +typedef boost::chrono::time_point TimePoint; +typedef boost::chrono::nanoseconds Duration; + +GRAS_FORCE_INLINE TimePoint high_res_now(void) +{ + return boost::posix_time::microsec_clock::universal_time(); +} + +GRAS_FORCE_INLINE long long duration_to_ticks(const Duration &d) +{ + return d.count(); +} + +GRAS_FORCE_INLINE unsigned long long tps(void) +{ + return (unsigned long long)(1e9); +} + +} //namespace chrono + +} //namespace gras + +#else +#include <boost/date_time/posix_time/posix_time.hpp> + +namespace gras +{ + +namespace chrono +{ + +typedef boost::posix_time::ptime TimePoint; +typedef boost::posix_time::time_duration Duration; + +GRAS_FORCE_INLINE TimePoint high_res_now(void) +{ + return boost::posix_time::microsec_clock::universal_time(); +} + +GRAS_FORCE_INLINE long long duration_to_ticks(const Duration &d) +{ + return d.ticks(); +} + +GRAS_FORCE_INLINE unsigned long long tps(void) +{ + return boost::posix_time::time_duration::ticks_per_second(); +} + +} //namespace chrono + +} //namespace gras + +#endif + +#endif /*INCLUDED_GRAS_CHRONO_HPP*/ diff --git a/lib/gras_impl/block_actor.hpp b/lib/gras_impl/block_actor.hpp index dca21e6..cec68be 100644 --- a/lib/gras_impl/block_actor.hpp +++ b/lib/gras_impl/block_actor.hpp @@ -6,6 +6,7 @@ #include <gras_impl/debug.hpp> #include <gras_impl/bitset.hpp> #include <gras/gras.hpp> +#include <gras/chrono.hpp> #include <gras/block.hpp> #include <gras/top_block.hpp> #include <gras/thread_pool.hpp> |