diff --git a/libgo/config.h b/libgo/config.h index 3ae9d579..e97dd01d 100644 --- a/libgo/config.h +++ b/libgo/config.h @@ -4,7 +4,8 @@ // VS2013²»Ö§³Öthread_local #if defined(_MSC_VER) && _MSC_VER < 1900 -#define thread_local __declspec(thread) +# define thread_local __declspec(thread) +# define UNSUPPORT_STEADY_TIME #endif #if __linux__ diff --git a/libgo/timer.cpp b/libgo/timer.cpp index 45dd2683..16b199f1 100644 --- a/libgo/timer.cpp +++ b/libgo/timer.cpp @@ -1,6 +1,7 @@ #include "timer.h" #include #include +#include namespace co { @@ -65,6 +66,8 @@ CoTimerPtr CoTimerMgr::ExpireAt(SystemTimePoint const& time_point, sptr->system_token_ = system_deadlines_.insert(std::make_pair(time_point, sptr)); return sptr; } + +#ifndef UNSUPPORT_STEADY_TIME CoTimerPtr CoTimerMgr::ExpireAt(SteadyTimePoint const& time_point, CoTimer::fn_t const& fn) { @@ -76,6 +79,7 @@ CoTimerPtr CoTimerMgr::ExpireAt(SteadyTimePoint const& time_point, sptr->steady_token_ = steady_deadlines_.insert(std::make_pair(time_point, sptr)); return sptr; } +#endif bool CoTimerMgr::Cancel(CoTimerPtr co_timer_ptr) { @@ -188,9 +192,11 @@ void CoTimerMgr::SetNextTriggerTime(SystemTimePoint const& sys_tp) system_next_trigger_time_ = std::chrono::time_point_cast(sys_tp).time_since_epoch().count(); } +#ifndef UNSUPPORT_STEADY_TIME void CoTimerMgr::SetNextTriggerTime(SteadyTimePoint const& sdy_tp) { steady_next_trigger_time_ = std::chrono::time_point_cast(sdy_tp).time_since_epoch().count(); } +#endif } //namespace co diff --git a/libgo/timer.h b/libgo/timer.h index fb17933d..796049d0 100644 --- a/libgo/timer.h +++ b/libgo/timer.h @@ -6,6 +6,7 @@ #include #include #include "spinlock.h" +#include "config.h" namespace co { @@ -13,8 +14,8 @@ namespace co class CoTimer; typedef std::shared_ptr CoTimerPtr; -typedef std::chrono::time_point SystemTimePoint; -typedef std::chrono::time_point SteadyTimePoint; +typedef std::chrono::system_clock::time_point SystemTimePoint; +typedef std::chrono::steady_clock::time_point SteadyTimePoint; class CoTimer { @@ -64,7 +65,9 @@ class CoTimerMgr CoTimerPtr ExpireAt(SystemTimePoint const& time_point, CoTimer::fn_t const& fn); +#ifndef UNSUPPORT_STEADY_TIME CoTimerPtr ExpireAt(SteadyTimePoint const& time_point, CoTimer::fn_t const& fn); +#endif template CoTimerPtr ExpireAt(Duration const& duration, CoTimer::fn_t const& fn) @@ -89,7 +92,10 @@ class CoTimerMgr long long GetNextTriggerTime(); void SetNextTriggerTime(SystemTimePoint const& sys_tp); + +#ifndef UNSUPPORT_STEADY_TIME void SetNextTriggerTime(SteadyTimePoint const& sdy_tp); +#endif private: SystemDeadLines system_deadlines_;