Fixes to compile on mingw32

This commit is contained in:
Eduardo Bart 2017-11-04 11:05:25 -02:00
parent c9bc9e327d
commit aa19f45d94
2 changed files with 5 additions and 17 deletions

View File

@ -195,7 +195,7 @@ message(STATUS "Build revision: ${BUILD_REVISION}")
add_definitions(-D"BUILD_REVISION=\\\"${BUILD_REVISION}\\\"") add_definitions(-D"BUILD_REVISION=\\\"${BUILD_REVISION}\\\"")
# find boost # find boost
set(REQUIRED_BOOST_COMPONENTS system thread filesystem chrono) set(REQUIRED_BOOST_COMPONENTS system thread filesystem)
if(WIN32) if(WIN32)
set(Boost_THREADAPI win32) set(Boost_THREADAPI win32)
set(framework_DEFINITIONS ${framework_DEFINITIONS} -DBOOST_THREAD_USE_LIB) # fix boost thread linkage set(framework_DEFINITIONS ${framework_DEFINITIONS} -DBOOST_THREAD_USE_LIB) # fix boost thread linkage

View File

@ -21,16 +21,12 @@
*/ */
#include "time.h" #include "time.h"
#include <boost/chrono.hpp> #include <chrono>
#ifdef _MSC_VER
#include <thread> #include <thread>
#else
#include <unistd.h>
#endif
namespace stdext { namespace stdext {
const static auto startup_time = boost::chrono::high_resolution_clock::now(); const static auto startup_time = std::chrono::high_resolution_clock::now();
ticks_t time() { ticks_t time() {
return std::time(NULL); return std::time(NULL);
@ -38,28 +34,20 @@ ticks_t time() {
ticks_t millis() ticks_t millis()
{ {
return boost::chrono::duration_cast<boost::chrono::milliseconds>(boost::chrono::high_resolution_clock::now() - startup_time).count(); return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - startup_time).count();
} }
ticks_t micros() { ticks_t micros() {
return boost::chrono::duration_cast<boost::chrono::microseconds>(boost::chrono::high_resolution_clock::now() - startup_time).count(); return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - startup_time).count();
} }
void millisleep(size_t ms) void millisleep(size_t ms)
{ {
#ifdef _MSC_VER
std::this_thread::sleep_for(std::chrono::milliseconds(ms)); std::this_thread::sleep_for(std::chrono::milliseconds(ms));
#else
usleep(ms * 1000);
#endif
}; };
void microsleep(size_t us) void microsleep(size_t us)
{ {
#ifdef _MSC_VER
std::this_thread::sleep_for(std::chrono::microseconds(us)); std::this_thread::sleep_for(std::chrono::microseconds(us));
#else
usleep(us);
#endif
}; };
} }