mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 12:43:09 +00:00
Don't support old MacOSX
This commit is contained in:
@@ -12,11 +12,12 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
#ifdef __APPLE__
|
||||||
#include <AvailabilityMacros.h>
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <mach/task.h>
|
#include <mach/task.h>
|
||||||
#include <mach/mach.h>
|
#include <mach/mach.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef void (*timer_execute_func)(void *ud,void *arg);
|
typedef void (*timer_execute_func)(void *ud,void *arg);
|
||||||
@@ -233,33 +234,19 @@ skynet_timeout(uint32_t handle, int time, int session) {
|
|||||||
// centisecond: 1/100 second
|
// centisecond: 1/100 second
|
||||||
static void
|
static void
|
||||||
systime(uint32_t *sec, uint32_t *cs) {
|
systime(uint32_t *sec, uint32_t *cs) {
|
||||||
#if !defined(__APPLE__) || defined(AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER)
|
|
||||||
struct timespec ti;
|
struct timespec ti;
|
||||||
clock_gettime(CLOCK_REALTIME, &ti);
|
clock_gettime(CLOCK_REALTIME, &ti);
|
||||||
*sec = (uint32_t)ti.tv_sec;
|
*sec = (uint32_t)ti.tv_sec;
|
||||||
*cs = (uint32_t)(ti.tv_nsec / 10000000);
|
*cs = (uint32_t)(ti.tv_nsec / 10000000);
|
||||||
#else
|
|
||||||
struct timeval tv;
|
|
||||||
gettimeofday(&tv, NULL);
|
|
||||||
*sec = tv.tv_sec;
|
|
||||||
*cs = tv.tv_usec / 10000;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t
|
static uint64_t
|
||||||
gettime() {
|
gettime() {
|
||||||
uint64_t t;
|
uint64_t t;
|
||||||
#if !defined(__APPLE__) || defined(AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER)
|
|
||||||
struct timespec ti;
|
struct timespec ti;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ti);
|
clock_gettime(CLOCK_MONOTONIC, &ti);
|
||||||
t = (uint64_t)ti.tv_sec * 100;
|
t = (uint64_t)ti.tv_sec * 100;
|
||||||
t += ti.tv_nsec / 10000000;
|
t += ti.tv_nsec / 10000000;
|
||||||
#else
|
|
||||||
struct timeval tv;
|
|
||||||
gettimeofday(&tv, NULL);
|
|
||||||
t = (uint64_t)tv.tv_sec * 100;
|
|
||||||
t += tv.tv_usec / 10000;
|
|
||||||
#endif
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,18 +293,8 @@ skynet_timer_init(void) {
|
|||||||
|
|
||||||
uint64_t
|
uint64_t
|
||||||
skynet_thread_time(void) {
|
skynet_thread_time(void) {
|
||||||
#if !defined(__APPLE__) || defined(AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER)
|
|
||||||
struct timespec ti;
|
struct timespec ti;
|
||||||
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ti);
|
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ti);
|
||||||
|
|
||||||
return (uint64_t)ti.tv_sec * MICROSEC + (uint64_t)ti.tv_nsec / (NANOSEC / MICROSEC);
|
return (uint64_t)ti.tv_sec * MICROSEC + (uint64_t)ti.tv_nsec / (NANOSEC / MICROSEC);
|
||||||
#else
|
|
||||||
struct task_thread_times_info aTaskInfo;
|
|
||||||
mach_msg_type_number_t aTaskInfoCount = TASK_THREAD_TIMES_INFO_COUNT;
|
|
||||||
if (KERN_SUCCESS != task_info(mach_task_self(), TASK_THREAD_TIMES_INFO, (task_info_t )&aTaskInfo, &aTaskInfoCount)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (uint64_t)(aTaskInfo.user_time.seconds) + (uint64_t)aTaskInfo.user_time.microseconds;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user