Skip to content

Commit c67fb3d

Browse files
author
test
committed
适配vs2013未实现steady_clock的问题
1 parent ee5283b commit c67fb3d

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

libgo/config.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
// VS2013不支持thread_local
66
#if defined(_MSC_VER) && _MSC_VER < 1900
7-
#define thread_local __declspec(thread)
7+
# define thread_local __declspec(thread)
8+
# define UNSUPPORT_STEADY_TIME
89
#endif
910

1011
#if __linux__

libgo/timer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "timer.h"
22
#include <mutex>
33
#include <limits>
4+
#include <algorithm>
45

56
namespace co
67
{
@@ -65,6 +66,8 @@ CoTimerPtr CoTimerMgr::ExpireAt(SystemTimePoint const& time_point,
6566
sptr->system_token_ = system_deadlines_.insert(std::make_pair(time_point, sptr));
6667
return sptr;
6768
}
69+
70+
#ifndef UNSUPPORT_STEADY_TIME
6871
CoTimerPtr CoTimerMgr::ExpireAt(SteadyTimePoint const& time_point,
6972
CoTimer::fn_t const& fn)
7073
{
@@ -76,6 +79,7 @@ CoTimerPtr CoTimerMgr::ExpireAt(SteadyTimePoint const& time_point,
7679
sptr->steady_token_ = steady_deadlines_.insert(std::make_pair(time_point, sptr));
7780
return sptr;
7881
}
82+
#endif
7983

8084
bool CoTimerMgr::Cancel(CoTimerPtr co_timer_ptr)
8185
{
@@ -188,9 +192,11 @@ void CoTimerMgr::SetNextTriggerTime(SystemTimePoint const& sys_tp)
188192
system_next_trigger_time_ = std::chrono::time_point_cast<std::chrono::milliseconds>(sys_tp).time_since_epoch().count();
189193
}
190194

195+
#ifndef UNSUPPORT_STEADY_TIME
191196
void CoTimerMgr::SetNextTriggerTime(SteadyTimePoint const& sdy_tp)
192197
{
193198
steady_next_trigger_time_ = std::chrono::time_point_cast<std::chrono::milliseconds>(sdy_tp).time_since_epoch().count();
194199
}
200+
#endif
195201

196202
} //namespace co

libgo/timer.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
#include <vector>
77
#include <list>
88
#include "spinlock.h"
9+
#include "config.h"
910

1011
namespace co
1112
{
1213

1314
class CoTimer;
1415
typedef std::shared_ptr<CoTimer> CoTimerPtr;
1516

16-
typedef std::chrono::time_point<std::chrono::system_clock> SystemTimePoint;
17-
typedef std::chrono::time_point<std::chrono::steady_clock> SteadyTimePoint;
17+
typedef std::chrono::system_clock::time_point SystemTimePoint;
18+
typedef std::chrono::steady_clock::time_point SteadyTimePoint;
1819

1920
class CoTimer
2021
{
@@ -64,7 +65,9 @@ class CoTimerMgr
6465

6566
CoTimerPtr ExpireAt(SystemTimePoint const& time_point, CoTimer::fn_t const& fn);
6667

68+
#ifndef UNSUPPORT_STEADY_TIME
6769
CoTimerPtr ExpireAt(SteadyTimePoint const& time_point, CoTimer::fn_t const& fn);
70+
#endif
6871

6972
template <typename Duration>
7073
CoTimerPtr ExpireAt(Duration const& duration, CoTimer::fn_t const& fn)
@@ -89,7 +92,10 @@ class CoTimerMgr
8992
long long GetNextTriggerTime();
9093

9194
void SetNextTriggerTime(SystemTimePoint const& sys_tp);
95+
96+
#ifndef UNSUPPORT_STEADY_TIME
9297
void SetNextTriggerTime(SteadyTimePoint const& sdy_tp);
98+
#endif
9399

94100
private:
95101
SystemDeadLines system_deadlines_;

0 commit comments

Comments
 (0)