OSX port, thanks @MatthewEndsley.

This commit is contained in:
bkaradzic
2012-06-25 18:50:26 -07:00
parent 61d110306a
commit f4bd1afb45
3 changed files with 10 additions and 2 deletions

View File

@@ -10,7 +10,7 @@
#include "cpu.h"
#include "sem.h"
#if BX_PLATFORM_NACL || BX_PLATFORM_LINUX || BX_PLATFORM_ANDROID
#if BX_PLATFORM_NACL || BX_PLATFORM_LINUX || BX_PLATFORM_ANDROID || BX_PLATFORM_OSX
# include <pthread.h>
#elif BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360
# include <errno.h>

View File

@@ -8,7 +8,7 @@
#include "bx.h"
#if BX_PLATFORM_NACL || BX_PLATFORM_ANDROID || BX_PLATFORM_LINUX
#if BX_PLATFORM_NACL || BX_PLATFORM_ANDROID || BX_PLATFORM_LINUX || BX_PLATFORM_OSX
# include <sched.h> // sched_yield
# if BX_PLATFORM_NACL
# include <sys/nacl_syscalls.h> // nanosleep

View File

@@ -12,6 +12,8 @@
# include <time.h> // clock, clock_gettime
#elif BX_PLATFORM_NACL | BX_PLATFORM_LINUX
# include <sys/time.h> // gettimeofday
#elif BX_PLATFORM_OSX
# include <mach/mach_time.h> // mach_absolute_time/mach_timebase_info
#endif // BX_PLATFORM_
namespace bx
@@ -26,6 +28,8 @@ namespace bx
int64_t i64 = li.QuadPart;
#elif BX_PLATFORM_ANDROID
int64_t i64 = clock();
#elif BX_PLATFORM_OSX
int64_t i64 = mach_absolute_time();
#else
struct timeval now;
gettimeofday(&now, 0);
@@ -43,6 +47,10 @@ namespace bx
return li.QuadPart;
#elif BX_PLATFORM_ANDROID
return CLOCKS_PER_SEC;
#elif BX_PLATFORM_OSX
mach_timebase_info_data_t info;
mach_timebase_info(&info);
return (int64_t)(info.denom * 1000000) / info.numer;
#else
return 1000000;
#endif // BNET_PLATFORM_