mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-04 05:51:27 +12:00
Improve clock_gettime on osx
and some clean up
This commit is contained in:
parent
009370f73c
commit
d0283265cc
3 changed files with 60 additions and 17 deletions
|
@ -1,16 +1,52 @@
|
||||||
#include "GNU.h"
|
#include "GNU.h"
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include <time.h>
|
#include <sys/types.h>
|
||||||
#include <sys/time.h>
|
#include <sys/_types/_timespec.h>
|
||||||
|
#include <mach/mach.h>
|
||||||
|
#include <mach/clock.h>
|
||||||
|
#include <mach/mach_time.h>
|
||||||
|
#undef CPU_STATE_MAX
|
||||||
|
|
||||||
int clock_gettime(int foo, struct timespec *ts) {
|
#define MT_NANO (+1.0E-9)
|
||||||
struct timeval tv;
|
#define MT_GIGA UINT64_C(1000000000)
|
||||||
|
|
||||||
gettimeofday(&tv, NULL);
|
// TODO create a list of timers,
|
||||||
ts->tv_sec = tv.tv_sec;
|
static double mt_timebase = 0.0;
|
||||||
ts->tv_nsec = tv.tv_usec * 1000;
|
static uint64_t mt_timestart = 0;
|
||||||
return(0);
|
|
||||||
|
// TODO be more careful in a multithreaded environement
|
||||||
|
int clock_gettime(clockid_t clk_id, struct timespec *tp)
|
||||||
|
{
|
||||||
|
kern_return_t retval = KERN_SUCCESS;
|
||||||
|
if( clk_id == TIMER_ABSTIME)
|
||||||
|
{
|
||||||
|
if (!mt_timestart) { // only one timer, initilized on the first call to the TIMER
|
||||||
|
mach_timebase_info_data_t tb = { 0 };
|
||||||
|
mach_timebase_info(&tb);
|
||||||
|
mt_timebase = tb.numer;
|
||||||
|
mt_timebase /= tb.denom;
|
||||||
|
mt_timestart = mach_absolute_time();
|
||||||
|
}
|
||||||
|
|
||||||
|
double diff = (mach_absolute_time() - mt_timestart) * mt_timebase;
|
||||||
|
tp->tv_sec = diff * MT_NANO;
|
||||||
|
tp->tv_nsec = diff - (tp->tv_sec * MT_GIGA);
|
||||||
|
}
|
||||||
|
else // other clk_ids are mapped to the coresponding mach clock_service
|
||||||
|
{
|
||||||
|
clock_serv_t cclock;
|
||||||
|
mach_timespec_t mts;
|
||||||
|
|
||||||
|
host_get_clock_service(mach_host_self(), clk_id, &cclock);
|
||||||
|
retval = clock_get_time(cclock, &mts);
|
||||||
|
mach_port_deallocate(mach_task_self(), cclock);
|
||||||
|
|
||||||
|
tp->tv_sec = mts.tv_sec;
|
||||||
|
tp->tv_nsec = mts.tv_nsec;
|
||||||
|
}
|
||||||
|
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
#endif /* __APPLE__ */
|
#endif /* __APPLE__ */
|
||||||
#if defined(__GNUG__)
|
#if defined(__GNUG__)
|
||||||
|
|
|
@ -68,12 +68,21 @@ inline int64_t __mulh(int64_t a, int64_t b)
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
|
||||||
int clock_gettime(int foo, struct timespec *ts);
|
// XXX only supports a single timer
|
||||||
#define wxIsNaN(x) ((x) != (x))
|
#define TIMER_ABSTIME -1
|
||||||
|
/* The opengroup spec isn't clear on the mapping from REALTIME to CALENDAR
|
||||||
|
being appropriate or not.
|
||||||
|
http://pubs.opengroup.org/onlinepubs/009695299/basedefs/time.h.html */
|
||||||
|
#define CLOCK_REALTIME 1 // #define CALENDAR_CLOCK 1 from mach/clock_types.h
|
||||||
|
#define CLOCK_MONOTONIC 0 // #define SYSTEM_CLOCK 0
|
||||||
|
|
||||||
#ifndef CLOCK_MONOTONIC
|
typedef int clockid_t;
|
||||||
#define CLOCK_MONOTONIC 0
|
|
||||||
#endif /* !CLOCK_MONOTONIC */
|
/* the mach kernel uses struct mach_timespec, so struct timespec
|
||||||
|
is loaded from <sys/_types/_timespec.h> for compatability */
|
||||||
|
// struct timespec { time_t tv_sec; long tv_nsec; };
|
||||||
|
|
||||||
|
int clock_gettime(clockid_t clk_id, struct timespec *tp);
|
||||||
|
|
||||||
#endif /* __APPLE__ */
|
#endif /* __APPLE__ */
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
cmake_minimum_required(VERSION 2.8.12)
|
cmake_minimum_required(VERSION 2.8.12)
|
||||||
|
|
||||||
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")
|
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")
|
||||||
set(CMAKE_VERBOSE_MAKEFILE ON)
|
|
||||||
include(cotire)
|
include(cotire)
|
||||||
|
|
||||||
project(rpcs3)
|
project(rpcs3)
|
||||||
|
@ -21,7 +20,7 @@ if(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
add_compile_options(-Wno-attributes -Wno-enum-compare -Wno-invalid-offsetof)
|
add_compile_options(-Wno-attributes -Wno-enum-compare -Wno-invalid-offsetof)
|
||||||
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
add_compile_options(-stdlib=libc++) # TODO: stdlib?
|
add_compile_options(-stdlib=libc++)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -47,7 +46,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||||
elseif(UNIX)
|
elseif(UNIX)
|
||||||
#it seems like glibc includes the iconv functions we use but other libc
|
#it seems like glibc includes the iconv functions we use but other libc
|
||||||
#implementations like the one on OSX don't seem implement them
|
#implementations like the one on OSX don't seem implement them
|
||||||
set(ADDITIONAL_LIBS "iconv")
|
set(ADDITIONAL_LIBS "iconv" "z")
|
||||||
else()
|
else()
|
||||||
set(ADDITIONAL_LIBS "")
|
set(ADDITIONAL_LIBS "")
|
||||||
endif()
|
endif()
|
||||||
|
@ -81,7 +80,6 @@ if(NOT WIN32)
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
find_package(GLEW REQUIRED)
|
find_package(GLEW REQUIRED)
|
||||||
message("${GLEW_LIBRARY} AND ${GLEW_INCLUDE_DIR}")
|
|
||||||
endif()
|
endif()
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
find_package(OpenAL REQUIRED)
|
find_package(OpenAL REQUIRED)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue