Commit 14acce29 authored by zhujiashun's avatar zhujiashun

update

parent 1e2ea13f
......@@ -177,7 +177,6 @@ set(BUTIL_SOURCES
${CMAKE_SOURCE_DIR}/src/butil/files/scoped_file.cc
${CMAKE_SOURCE_DIR}/src/butil/files/scoped_temp_dir.cc
${CMAKE_SOURCE_DIR}/src/butil/file_util.cc
${CMAKE_SOURCE_DIR}/src/butil/file_util_linux.cc
${CMAKE_SOURCE_DIR}/src/butil/file_util_posix.cc
${CMAKE_SOURCE_DIR}/src/butil/guid.cc
${CMAKE_SOURCE_DIR}/src/butil/guid_posix.cc
......@@ -215,7 +214,6 @@ set(BUTIL_SOURCES
${CMAKE_SOURCE_DIR}/src/butil/synchronization/condition_variable_posix.cc
${CMAKE_SOURCE_DIR}/src/butil/synchronization/waitable_event_posix.cc
${CMAKE_SOURCE_DIR}/src/butil/threading/non_thread_safe_impl.cc
${CMAKE_SOURCE_DIR}/src/butil/threading/platform_thread_linux.cc
${CMAKE_SOURCE_DIR}/src/butil/threading/platform_thread_posix.cc
${CMAKE_SOURCE_DIR}/src/butil/threading/simple_thread.cc
${CMAKE_SOURCE_DIR}/src/butil/threading/thread_checker_impl.cc
......@@ -253,6 +251,16 @@ set(BUTIL_SOURCES
${CMAKE_SOURCE_DIR}/src/butil/popen.cpp
)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(BUTIL_SOURCES ${BUTIL_SOURCES}
${CMAKE_SOURCE_DIR}/src/butil/file_util_linux.cc
${CMAKE_SOURCE_DIR}/src/butil/threading/platform_thread_linux.cc)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(BUTIL_SOURCES ${BUTIL_SOURCES}
${CMAKE_SOURCE_DIR}/src/butil/mac/bundle_locations.mm
${CMAKE_SOURCE_DIR}/src/butil/mac/foundation_util.mm)
endif()
file(GLOB_RECURSE BVAR_SOURCES "${CMAKE_SOURCE_DIR}/src/bvar/*.cpp")
file(GLOB_RECURSE BTHREAD_SOURCES "${CMAKE_SOURCE_DIR}/src/bthread/*.cpp")
file(GLOB_RECURSE JSON2PB_SOURCES "${CMAKE_SOURCE_DIR}/src/json2pb/*.cpp")
......
......@@ -35,7 +35,17 @@ int64_t monotonic_time_ns() {
// use the RAW version does not make sense anymore.
// NOTE: Not inline to keep ABI-compatible with previous versions.
timespec now;
#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
now.tv_sec = mts.tv_sec;
now.tv_nsec = mts.tv_nsec;
#else
clock_gettime(CLOCK_MONOTONIC, &now);
#endif
return now.tv_sec * 1000000000L + now.tv_nsec;
}
......
......@@ -20,6 +20,11 @@
#ifndef BUTIL_BAIDU_TIME_H
#define BUTIL_BAIDU_TIME_H
#ifdef __MACH__
#include <mach/clock.h>
#include <mach/mach.h>
#endif
#include <time.h> // timespec, clock_gettime
#include <sys/time.h> // timeval, gettimeofday
#include <stdint.h> // int64_t, uint64_t
......@@ -87,7 +92,17 @@ inline timespec seconds_from(timespec start_time, int64_t seconds) {
// --------------------------------------------------------------------
inline timespec nanoseconds_from_now(int64_t nanoseconds) {
timespec time;
#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
time.tv_sec = mts.tv_sec;
time.tv_nsec = mts.tv_nsec;
#else
clock_gettime(CLOCK_REALTIME, &time);
#endif
return nanoseconds_from(time, nanoseconds);
}
......@@ -105,7 +120,17 @@ inline timespec seconds_from_now(int64_t seconds) {
inline timespec timespec_from_now(const timespec& span) {
timespec time;
#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
time.tv_sec = mts.tv_sec;
time.tv_nsec = mts.tv_nsec;
#else
clock_gettime(CLOCK_REALTIME, &time);
#endif
timespec_add(&time, span);
return time;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment