mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 04:33:05 +00:00
_POSIX_TIMERS & _POSIX_THREAD_CPUTIME 在 unistd.h
头文件定义,但并未包含。之前写法不正确,可以工作只是巧合。 现改为,默认使用 clock_gettime,当为 Max OSX 平台时,使用兼容方法。
This commit is contained in:
@@ -32,9 +32,9 @@ struct stat {
|
||||
static void
|
||||
_stat_begin(struct stat *S, struct timespec *ti) {
|
||||
S->count++;
|
||||
#if defined(_POSIX_TIMERS) && defined(_POSIX_THREAD_CPUTIME)
|
||||
#if !defined(__APPLE__)
|
||||
clock_gettime(CLOCK_THREAD_CPUTIME_ID, ti);
|
||||
#elif defined(__APPLE__)
|
||||
#else
|
||||
struct task_thread_times_info aTaskInfo;
|
||||
mach_msg_type_number_t aTaskInfoCount = TASK_THREAD_TIMES_INFO_COUNT;
|
||||
assert(KERN_SUCCESS == task_info(mach_task_self(), TASK_THREAD_TIMES_INFO, (task_info_t )&aTaskInfo, &aTaskInfoCount));
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
void
|
||||
diff_time(struct timespec *ti, uint32_t *sec, uint32_t *nsec) {
|
||||
struct timespec end;
|
||||
#if defined(_POSIX_TIMERS) && defined(_POSIX_THREAD_CPUTIME)
|
||||
#if !defined(__APPLE__)
|
||||
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end);
|
||||
#elif defined(__APPLE__)
|
||||
#else
|
||||
struct task_thread_times_info aTaskInfo;
|
||||
mach_msg_type_number_t aTaskInfoCount = TASK_THREAD_TIMES_INFO_COUNT;
|
||||
assert(KERN_SUCCESS == task_info(mach_task_self(), TASK_THREAD_TIMES_INFO, (task_info_t )&aTaskInfo, &aTaskInfoCount));
|
||||
@@ -89,9 +89,9 @@ trace_new(struct trace_pool *p) {
|
||||
t->next = NULL;
|
||||
t->ti_sec = 0;
|
||||
t->ti_nsec = 0;
|
||||
#if defined(_POSIX_TIMERS) && defined(_POSIX_THREAD_CPUTIME)
|
||||
#if !defined(__APPLE__)
|
||||
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &t->ti);
|
||||
#elif defined(__APPLE__)
|
||||
#else
|
||||
struct task_thread_times_info aTaskInfo;
|
||||
mach_msg_type_number_t aTaskInfoCount = TASK_THREAD_TIMES_INFO_COUNT;
|
||||
assert(KERN_SUCCESS == task_info(mach_task_self(), TASK_THREAD_TIMES_INFO, (task_info_t )&aTaskInfo, &aTaskInfoCount));
|
||||
@@ -151,9 +151,9 @@ trace_switch(struct trace_pool *p, int session) {
|
||||
if (t->next) {
|
||||
t->next->prev = prev;
|
||||
}
|
||||
#if defined(_POSIX_TIMERS) && defined(_POSIX_THREAD_CPUTIME)
|
||||
#if !defined(__APPLE__)
|
||||
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &t->ti);
|
||||
#elif defined(__APPLE__)
|
||||
#else
|
||||
struct task_thread_times_info aTaskInfo;
|
||||
mach_msg_type_number_t aTaskInfoCount = TASK_THREAD_TIMES_INFO_COUNT;
|
||||
assert(KERN_SUCCESS == task_info(mach_task_self(), TASK_THREAD_TIMES_INFO, (task_info_t )&aTaskInfo, &aTaskInfoCount));
|
||||
|
||||
Reference in New Issue
Block a user