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
2d6535b6
Commit
2d6535b6
authored
Apr 16, 2018
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimize some time-related codes
parent
a264483a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
19 additions
and
41 deletions
+19
-41
time.h
src/butil/time.h
+2
-1
CMakeLists.txt
test/CMakeLists.txt
+1
-1
bthread_butex_unittest.cpp
test/bthread_butex_unittest.cpp
+2
-8
bthread_timer_thread_unittest.cpp
test/bthread_timer_thread_unittest.cpp
+6
-24
popen_unittest.cpp
test/popen_unittest.cpp
+0
-1
rpc_replay.cpp
tools/rpc_replay/rpc_replay.cpp
+8
-6
No files found.
src/butil/time.h
View file @
2d6535b6
...
...
@@ -28,7 +28,7 @@
#include <mach/clock.h>
#include <mach/mach.h>
inline
void
clock_gettime
(
clock_id_t
id
,
timespec
*
time
)
{
inline
int
clock_gettime
(
clock_id_t
id
,
timespec
*
time
)
{
// clock_gettime is not available in MacOS, use clock_get_time instead
clock_serv_t
cclock
;
mach_timespec_t
mts
;
...
...
@@ -37,6 +37,7 @@ inline void clock_gettime(clock_id_t id, timespec* time) {
mach_port_deallocate
(
mach_task_self
(),
cclock
);
time
->
tv_sec
=
mts
.
tv_sec
;
time
->
tv_nsec
=
mts
.
tv_nsec
;
return
0
;
}
#endif
...
...
test/CMakeLists.txt
View file @
2d6535b6
...
...
@@ -35,7 +35,7 @@ endif()
set
(
CMAKE_CPP_FLAGS
"-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 -
g -
pipe -Wall -W -fPIC -fstrict-aliasing -Wno-invalid-offsetof -Wno-unused-parameter -fno-omit-frame-pointer"
)
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
()
if
(
CMAKE_CXX_COMPILER_ID STREQUAL
"GNU"
)
...
...
test/bthread_butex_unittest.cpp
View file @
2d6535b6
...
...
@@ -25,14 +25,8 @@ TEST(ButexTest, wait_on_already_timedout_butex) {
uint32_t
*
butex
=
bthread
::
butex_create_checked
<
uint32_t
>
();
ASSERT_TRUE
(
butex
);
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
);
ASSERT_EQ
(
0
,
clock_get_time
(
cclock
,
&
mts
));
mach_port_deallocate
(
mach_task_self
(),
cclock
);
now
.
tv_sec
=
mts
.
tv_sec
;
now
.
tv_nsec
=
mts
.
tv_nsec
;
#if defined(OS_MACOSX)
ASSERT_EQ
(
0
,
clock_gettime
(
CALENDAR_CLOCK
,
&
now
));
#else
ASSERT_EQ
(
0
,
clock_gettime
(
CLOCK_REALTIME
,
&
now
));
#endif
...
...
test/bthread_timer_thread_unittest.cpp
View file @
2d6535b6
...
...
@@ -34,14 +34,8 @@ public:
void
run
()
{
timespec
current_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
);
current_time
.
tv_sec
=
mts
.
tv_sec
;
current_time
.
tv_nsec
=
mts
.
tv_nsec
;
#if defined(OS_MACOSX)
clock_gettime
(
CALENDAR_CLOCK
,
&
current_time
);
#else
clock_gettime
(
CLOCK_REALTIME
,
&
current_time
);
#endif
...
...
@@ -181,14 +175,8 @@ public:
void
run
()
{
#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
);
_running_time
.
tv_sec
=
mts
.
tv_sec
;
_running_time
.
tv_nsec
=
mts
.
tv_nsec
;
#if defined(OS_MACOSX)
clock_gettime
(
CALENDAR_CLOCK
,
&
_running_time
);
#else
clock_gettime
(
CLOCK_REALTIME
,
&
_running_time
);
#endif
...
...
@@ -251,14 +239,8 @@ TEST(TimerThreadTest, schedule_and_unschedule_in_task) {
timer_thread
.
stop_and_join
();
timespec
finish_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
);
finish_time
.
tv_sec
=
mts
.
tv_sec
;
finish_time
.
tv_nsec
=
mts
.
tv_nsec
;
#if defined(OS_MACOSX)
clock_gettime
(
CALENDAR_CLOCK
,
&
finish_time
);
#else
clock_gettime
(
CLOCK_REALTIME
,
&
finish_time
);
#endif
...
...
test/popen_unittest.cpp
View file @
2d6535b6
...
...
@@ -8,7 +8,6 @@
#include "butil/strings/string_piece.h"
#include "butil/build_config.h"
#include <gtest/gtest.h>
#include <fstream>
namespace
butil
{
extern
int
read_command_output_through_clone
(
std
::
ostream
&
,
const
char
*
);
...
...
tools/rpc_replay/rpc_replay.cpp
View file @
2d6535b6
...
...
@@ -232,19 +232,21 @@ int main(int argc, char* argv[]) {
}
}
std
::
vector
<
bthread_t
>
t
ids
;
tids
.
resize
(
FLAGS_thread_num
)
;
std
::
vector
<
bthread_t
>
b
ids
;
std
::
vector
<
pthread_t
>
pids
;
if
(
!
FLAGS_use_bthread
)
{
pids
.
resize
(
FLAGS_thread_num
);
for
(
int
i
=
0
;
i
<
FLAGS_thread_num
;
++
i
)
{
if
(
pthread_create
(
(
pthread_t
*
)
&
t
ids
[
i
],
NULL
,
replay_thread
,
&
chan_group
)
!=
0
)
{
if
(
pthread_create
(
&
p
ids
[
i
],
NULL
,
replay_thread
,
&
chan_group
)
!=
0
)
{
LOG
(
ERROR
)
<<
"Fail to create pthread"
;
return
-
1
;
}
}
}
else
{
bids
.
resize
(
FLAGS_thread_num
);
for
(
int
i
=
0
;
i
<
FLAGS_thread_num
;
++
i
)
{
if
(
bthread_start_background
(
&
t
ids
[
i
],
NULL
,
replay_thread
,
&
chan_group
)
!=
0
)
{
&
b
ids
[
i
],
NULL
,
replay_thread
,
&
chan_group
)
!=
0
)
{
LOG
(
ERROR
)
<<
"Fail to create bthread"
;
return
-
1
;
}
...
...
@@ -263,9 +265,9 @@ int main(int argc, char* argv[]) {
for
(
int
i
=
0
;
i
<
FLAGS_thread_num
;
++
i
)
{
if
(
!
FLAGS_use_bthread
)
{
pthread_join
(
(
pthread_t
)
t
ids
[
i
],
NULL
);
pthread_join
(
p
ids
[
i
],
NULL
);
}
else
{
bthread_join
(
t
ids
[
i
],
NULL
);
bthread_join
(
b
ids
[
i
],
NULL
);
}
}
info_thr
.
stop
();
...
...
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