From 23ae468189b32e04557e3449e70b656eb4a1298b Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Thu, 3 Mar 2016 15:46:15 +0100 Subject: use chrono calls for time handling in core (nw) --- src/osd/osdcore.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/osd/osdcore.cpp') diff --git a/src/osd/osdcore.cpp b/src/osd/osdcore.cpp index 632124e2e7c..206cb5ed642 100644 --- a/src/osd/osdcore.cpp +++ b/src/osd/osdcore.cpp @@ -2,6 +2,8 @@ // copyright-holders:Aaron Giles #include "osdcore.h" +#include +#include static const int MAXSTACK = 10; static osd_output *m_stack[MAXSTACK]; @@ -141,3 +143,41 @@ void CLIB_DECL osd_printf_log(const char *format, ...) va_end(argptr); } #endif + +//============================================================ +// osd_ticks +//============================================================ + +osd_ticks_t osd_ticks(void) +{ + return std::chrono::high_resolution_clock::now().time_since_epoch().count(); +} + + +//============================================================ +// osd_ticks_per_second +//============================================================ + +osd_ticks_t osd_ticks_per_second(void) +{ + return std::chrono::high_resolution_clock::period::den; +} + +//============================================================ +// osd_sleep +//============================================================ + +void osd_sleep(osd_ticks_t duration) +{ + std::this_thread::sleep_for(std::chrono::high_resolution_clock::duration(duration)); +} + +//============================================================ +// osd_num_processors +//============================================================ + +int osd_get_num_processors(void) +{ + // max out at 4 for now since scaling above that seems to do poorly + return MIN(std::thread::hardware_concurrency(), 4); +} -- cgit v1.2.3-70-g09d2 From ccc12869fdf38e2373d2b34c0adb4359dcc3bb89 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Thu, 3 Mar 2016 19:30:37 +0100 Subject: these are constexpr so calculation does not cost (nw) --- src/osd/osdcore.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/osd/osdcore.cpp') diff --git a/src/osd/osdcore.cpp b/src/osd/osdcore.cpp index 206cb5ed642..fef7d0d0f7a 100644 --- a/src/osd/osdcore.cpp +++ b/src/osd/osdcore.cpp @@ -160,7 +160,7 @@ osd_ticks_t osd_ticks(void) osd_ticks_t osd_ticks_per_second(void) { - return std::chrono::high_resolution_clock::period::den; + return std::chrono::high_resolution_clock::period::den / std::chrono::high_resolution_clock::period::num; } //============================================================ -- cgit v1.2.3-70-g09d2