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
081b4648
Commit
081b4648
authored
Apr 28, 2018
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Put Impl of get_clocktime into butil/time.cpp
parent
ace912ba
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
55 additions
and
44 deletions
+55
-44
CMakeLists.txt
CMakeLists.txt
+9
-1
time.cpp
src/butil/time.cpp
+40
-0
time.h
src/butil/time.h
+3
-40
CMakeLists.txt
test/CMakeLists.txt
+1
-1
bthread_butex_unittest.cpp
test/bthread_butex_unittest.cpp
+1
-1
CMakeLists.txt
tools/CMakeLists.txt
+1
-1
No files found.
CMakeLists.txt
View file @
081b4648
...
...
@@ -63,7 +63,15 @@ execute_process(
OUTPUT_VARIABLE BRPC_REVISION
)
set
(
CMAKE_CPP_FLAGS
"-DBRPC_WITH_GLOG=
${
WITH_GLOG_VAL
}
-DGFLAGS_NS=
${
GFLAGS_NS
}
"
)
if
(
CMAKE_SYSTEM_NAME STREQUAL
"Darwin"
)
include
(
CheckFunctionExists
)
CHECK_FUNCTION_EXISTS
(
clock_gettime HAVE_CLOCK_GETTIME
)
if
(
NOT HAVE_CLOCK_GETTIME
)
set
(
DEFINE_CLOCK_GETTIME
"-DNO_CLOCK_GETTIME_IN_MAC"
)
endif
()
endif
()
set
(
CMAKE_CPP_FLAGS
"
${
DEFINE_CLOCK_GETTIME
}
-DBRPC_WITH_GLOG=
${
WITH_GLOG_VAL
}
-DGFLAGS_NS=
${
GFLAGS_NS
}
"
)
set
(
CMAKE_CPP_FLAGS
"
${
CMAKE_CPP_FLAGS
}
-DBTHREAD_USE_FAST_PTHREAD_MUTEX -D__const__= -D_GNU_SOURCE -DUSE_SYMBOLIZE -DNO_TCMALLOC -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -DBRPC_REVISION=
\\\"
${
BRPC_REVISION
}
\\\"
-D__STRICT_ANSI__"
)
set
(
CMAKE_CPP_FLAGS
"
${
CMAKE_CPP_FLAGS
}
${
DEBUG_SYMBOL
}
"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CPP_FLAGS
}
-O2 -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-invalid-offsetof -Wno-unused-parameter -fno-omit-frame-pointer"
)
...
...
src/butil/time.cpp
View file @
081b4648
...
...
@@ -28,6 +28,46 @@
#include "butil/time.h"
#if defined(NO_CLOCK_GETTIME_IN_MAC)
#include <mach/clock.h> // mach_absolute_time
#include <mach/mach_time.h> // mach_timebase_info
#include <pthread.h> // pthread_once
#include <stdlib.h> // exit
static
mach_timebase_info_data_t
s_timebase
;
static
timespec
s_init_time
;
static
uint64_t
s_init_ticks
;
static
pthread_once_t
s_init_clock_once
=
PTHREAD_ONCE_INIT
;
static
void
InitClock
()
{
if
(
mach_timebase_info
(
&
s_timebase
)
!=
0
)
{
exit
(
1
);
}
timeval
now
;
if
(
gettimeofday
(
&
now
,
NULL
)
!=
0
)
{
exit
(
1
);
}
s_init_time
.
tv_sec
=
now
.
tv_sec
;
s_init_time
.
tv_nsec
=
now
.
tv_usec
*
1000L
;
s_init_ticks
=
mach_absolute_time
();
}
int
clock_gettime
(
clockid_t
id
,
timespec
*
time
)
{
if
(
pthread_once
(
&
s_init_clock_once
,
InitClock
)
!=
0
)
{
exit
(
1
);
}
uint64_t
clock
=
mach_absolute_time
()
-
s_init_ticks
;
uint64_t
elapsed
=
clock
*
(
uint64_t
)
s_timebase
.
numer
/
(
uint64_t
)
s_timebase
.
denom
;
*
time
=
s_init_time
;
time
->
tv_sec
+=
elapsed
/
1000000000L
;
time
->
tv_nsec
+=
elapsed
%
1000000000L
;
time
->
tv_sec
+=
time
->
tv_nsec
/
1000000000L
;
time
->
tv_nsec
=
time
->
tv_nsec
%
1000000000L
;
return
0
;
}
#endif
namespace
butil
{
int64_t
monotonic_time_ns
()
{
...
...
src/butil/time.h
View file @
081b4648
...
...
@@ -24,53 +24,16 @@
#include <sys/time.h> // timeval, gettimeofday
#include <stdint.h> // int64_t, uint64_t
#ifdef __MACH__
#include <mach/clock.h>
#if defined(NO_CLOCK_GETTIME_IN_MAC)
#include <mach/mach.h>
#include <mach/mach_time.h>
# ifndef clock_gettime
# define CLOCK_REALTIME CALENDAR_CLOCK
# define CLOCK_MONOTONIC SYSTEM_CLOCK
#include <pthread.h>
#include <stdlib.h> // exit
typedef
int
clockid_t
;
static
mach_timebase_info_data_t
timebase
;
static
timespec
inittime
;
static
uint64_t
initticks
;
static
pthread_once_t
init_clock_once
=
PTHREAD_ONCE_INIT
;
static
void
InitClock
()
{
if
(
mach_timebase_info
(
&
timebase
)
!=
0
)
{
exit
(
1
);
}
timeval
micro
;
if
(
gettimeofday
(
&
micro
,
NULL
)
!=
0
)
{
exit
(
1
);
}
inittime
.
tv_sec
=
micro
.
tv_sec
;
inittime
.
tv_nsec
=
micro
.
tv_usec
*
1000L
;
initticks
=
mach_absolute_time
();
}
// clock_gettime is not available in MacOS < 10.12
inline
int
clock_gettime
(
clockid_t
id
,
timespec
*
time
)
{
if
(
pthread_once
(
&
init_clock_once
,
InitClock
)
!=
0
)
{
exit
(
1
);
}
uint64_t
clock
=
mach_absolute_time
()
-
initticks
;
uint64_t
elapsed
=
clock
*
(
uint64_t
)
timebase
.
numer
/
(
uint64_t
)
timebase
.
denom
;
*
time
=
inittime
;
time
->
tv_sec
+=
elapsed
/
1000000000L
;
time
->
tv_nsec
+=
elapsed
%
1000000000L
;
time
->
tv_sec
+=
time
->
tv_nsec
/
1000000000L
;
time
->
tv_nsec
=
time
->
tv_nsec
%
1000000000L
;
return
0
;
}
# endif
int
clock_gettime
(
clockid_t
id
,
timespec
*
time
);
#endif
namespace
butil
{
...
...
test/CMakeLists.txt
View file @
081b4648
...
...
@@ -33,7 +33,7 @@ else()
message
(
FATAL_ERROR
"Googletest is not available"
)
endif
()
set
(
CMAKE_CPP_FLAGS
"-DBRPC_WITH_GLOG=
${
WITH_GLOG_VAL
}
-DGFLAGS_NS=
${
GFLAGS_NS
}
"
)
set
(
CMAKE_CPP_FLAGS
"
${
DEFINE_CLOCK_GETTIME
}
-DBRPC_WITH_GLOG=
${
WITH_GLOG_VAL
}
-DGFLAGS_NS=
${
GFLAGS_NS
}
"
)
set
(
CMAKE_CPP_FLAGS
"
${
CMAKE_CPP_FLAGS
}
-DBTHREAD_USE_FAST_PTHREAD_MUTEX -D__const__= -D_GNU_SOURCE -DUSE_SYMBOLIZE -DNO_TCMALLOC -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -DUNIT_TEST -Dprivate=public -Dprotected=public -DBVAR_NOT_LINK_DEFAULT_VARIABLES -D__STRICT_ANSI__ -include
${
CMAKE_SOURCE_DIR
}
/test/sstream_workaround.h"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CPP_FLAGS
}
-O2 -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-invalid-offsetof -Wno-unused-parameter -fno-omit-frame-pointer"
)
use_cxx11
()
...
...
test/bthread_butex_unittest.cpp
View file @
081b4648
...
...
@@ -295,7 +295,7 @@ TEST(ButexTest, join_cant_be_wakeup) {
ASSERT_EQ
(
0
,
bthread_join
(
th2
,
NULL
));
ASSERT_EQ
(
0
,
bthread_join
(
th
,
NULL
));
tm
.
stop
();
ASSERT_LT
(
tm
.
m_elapsed
(),
WAIT_MSEC
+
1
0
);
ASSERT_LT
(
tm
.
m_elapsed
(),
WAIT_MSEC
+
1
5
);
ASSERT_EQ
(
EINVAL
,
bthread_stop
(
th
));
ASSERT_EQ
(
EINVAL
,
bthread_stop
(
th2
));
}
...
...
tools/CMakeLists.txt
View file @
081b4648
set
(
CMAKE_CPP_FLAGS
"-DGFLAGS_NS=
${
GFLAGS_NS
}
"
)
set
(
CMAKE_CPP_FLAGS
"
${
DEFINE_CLOCK_GETTIME
}
-DGFLAGS_NS=
${
GFLAGS_NS
}
"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CPP_FLAGS
}
-DNDEBUG -O2 -D__const__= -D__STRICT_ANSI__ -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer"
)
use_cxx11
()
set
(
EXECUTABLE_OUTPUT_PATH
${
CMAKE_BINARY_DIR
}
/output/bin
)
...
...
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