Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
14acce29
Commit
14acce29
authored
Jan 16, 2018
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
1e2ea13f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
2 deletions
+45
-2
CMakeLists.txt
CMakeLists.txt
+10
-2
time.cpp
src/butil/time.cpp
+10
-0
time.h
src/butil/time.h
+25
-0
No files found.
CMakeLists.txt
View file @
14acce29
...
...
@@ -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"
)
...
...
src/butil/time.cpp
View file @
14acce29
...
...
@@ -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
;
}
...
...
src/butil/time.h
View file @
14acce29
...
...
@@ -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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment