YSTest: Timer.cpp 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

Timer.cpp
浏览该文件的文档.
1 /*
2 © 2012-2014 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #include "YCLib/YModules.h"
29 #include YFM_YCLib_Timer
30 #include YFM_YCLib_NativeAPI
31 #include <system_error>
32 #if !YCL_DS
33 # include <chrono>
34 #endif
35
36 namespace platform
37 {
38
39 namespace
40 {
41
42 #if YCL_DS
43 bool bUninitializedTimers(true);
44 volatile std::uint32_t system_tick;
45
46 void
47 timer_callback()
48 {
49 ++system_tick;
50 }
51
53 void
54 start_ticks() ynothrow
55 {
56 if(YB_UNLIKELY(bUninitializedTimers))
57 {
58 // f = 33.513982MHz, BUS_CLOCK = 33513982 = 2*311*53881;
59 #if 0
60 ::irqSet(IRQ_TIMER(2), timer_callback);
61 ::irqEnable(IRQ_TIMER(2));
62 TIMER2_DATA = 0;
63 TIMER2_CR = TIMER_ENABLE | ::ClockDivider_1;
64 #endif
65 ::timerStart(2, ::ClockDivider_1, u16(TIMER_FREQ(1000)),
66 timer_callback);
67 };
68 bUninitializedTimers = {};
69 }
70
71 #endif
72
73 } // unnamed namespace;
74
75 std::uint32_t
76 GetTicks() ynothrow
77 {
78 #if YCL_DS
79 start_ticks();
80 return system_tick;
81 #else
82 return std::uint32_t(std::chrono::duration_cast<std::chrono::milliseconds>(
83 std::chrono::steady_clock::now().time_since_epoch()).count());
84 #endif
85 }
86
87 std::uint64_t
88 GetHighResolutionTicks() ynothrow
89 {
90 #if YCL_DS
91 start_ticks();
92 return system_tick * 1000000ULL + TIMER2_DATA * 1000000ULL / BUS_CLOCK;
93 #else
94 return std::uint64_t(std::chrono::duration_cast<std::chrono::nanoseconds>(
95 std::chrono::steady_clock::now().time_since_epoch()).count());
96 #endif
97 }
98
99 }
100
platform
默认平台命名空间。
Definition: Container.h:47
YB_UNLIKELY
#define YB_UNLIKELY(_expr)
分支预测提示。
Definition: ydef.h:464
platform::GetHighResolutionTicks
YF_API std::uint64_t GetHighResolutionTicks() ynothrow
取高精度 tick 数。
Definition: Timer.cpp:88
YModules.h
platform::GetTicks
YF_API std::uint32_t GetTicks() ynothrow
取 tick 数。
Definition: Timer.cpp:76
platform::ynothrow
const _tString &path ynothrow
Definition: YCLib/FileSystem.h:274