Fixes #143 Implement a clock_gettime replacement (#144)

This commit is contained in:
Stefan Arentz 2017-03-13 15:01:06 -04:00 committed by GitHub
parent e0943d051a
commit be01db6393
6 changed files with 45 additions and 3 deletions

View File

@ -30,7 +30,7 @@ EWM_OBJECTS=$(EWM_SOURCES:.c=.o)
EWM_LIBS=-lSDL2
CPU_TEST_EXECUTABLE=cpu_test
CPU_TEST_SOURCES=cpu.c ins.c mem.c fmt.c cpu_test.c
CPU_TEST_SOURCES=cpu.c ins.c mem.c fmt.c utl.c cpu_test.c
CPU_TEST_OBJECTS=$(CPU_TEST_SOURCES:.c=.o)
CPU_TEST_LIBS=
@ -40,12 +40,12 @@ SCR_TEST_OBJECTS=$(SCR_TEST_SOURCES:.c=.o)
SCR_TEST_LIBS=-lSDL2
CPU_BENCH=cpu_bench
CPU_BENCH_SOURCES=cpu.c ins.c mem.c fmt.c cpu_bench.c
CPU_BENCH_SOURCES=cpu.c ins.c mem.c fmt.c utl.c cpu_bench.c
CPU_BENCH_OBJECTS=$(CPU_BENCH_SOURCES:.c=.o)
CPU_BENCH_LIBS=
MEM_BENCH=mem_bench
MEM_BENCH_SOURCES=cpu.c ins.c mem.c fmt.c mem_bench.c
MEM_BENCH_SOURCES=cpu.c ins.c mem.c fmt.c utl.c mem_bench.c
MEM_BENCH_OBJECTS=$(MEM_BENCH_SOURCES:.c=.o)
MEM_BENCH_LIBS=

View File

@ -27,6 +27,7 @@
#include "cpu.h"
#include "ins.h"
#include "mem.h"
#include "utl.h"
#define CPU_BENCH_ITERATIONS (100 * 1000 * 1000)

View File

@ -29,6 +29,7 @@
#include "cpu.h"
#include "mem.h"
#include "utl.h"
int test(int model, uint16_t start_addr, uint16_t success_addr, char *rom_path) {
struct cpu_t *cpu = cpu_create(model);

View File

@ -26,6 +26,7 @@
#include "cpu.h"
#include "mem.h"
#include "utl.h"
#define MEM_BENCH_ITERATIONS (100 * 1000 * 1000)

View File

@ -23,6 +23,12 @@
#include <stddef.h>
#include <string.h>
#if __APPLE__ && __MACH__
#include <sys/_types/_timespec.h>
#include <mach/mach.h>
#include <mach/clock.h>
#endif
#include "utl.h"
bool ewm_utl_endswith(char *s, char *suffix) {
@ -33,3 +39,25 @@ bool ewm_utl_endswith(char *s, char *suffix) {
}
return false;
}
#if (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200)
int clock_gettime(clockid_t clk_id, struct timespec *tp) {
if (clk_id != CLOCK_REALTIME) {
return -1;
}
kern_return_t result = KERN_SUCCESS;
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), clk_id, &cclock);
result = 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 result;
}
#endif

View File

@ -25,6 +25,17 @@
#include <stdbool.h>
#if __APPLE__ && __MACH__
#include <mach/clock.h>
#include <Availability.h>
#endif
bool ewm_utl_endswith(char *s, char *suffix);
#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200
#define CLOCK_REALTIME CALENDAR_CLOCK
typedef int clockid_t;
int clock_gettime(clockid_t clk_id, struct timespec *tp);
#endif
#endif // EWM_UTL_H