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
5eaf488d
Commit
5eaf488d
authored
Aug 23, 2017
by
zhujiashun
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
ssh://icode.baidu.com:8235/baidu/opensource/baidu-rpc
parents
cacf83c6
27db3d61
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
6 deletions
+16
-6
bthread_setconcurrency_unittest.cpp
test/bthread_setconcurrency_unittest.cpp
+12
-6
type_traits_unittest.cc
test/type_traits_unittest.cc
+4
-0
No files found.
test/bthread_setconcurrency_unittest.cpp
View file @
5eaf488d
...
@@ -40,15 +40,17 @@ TEST(BthreadTest, setconcurrency) {
...
@@ -40,15 +40,17 @@ TEST(BthreadTest, setconcurrency) {
static
base
::
atomic
<
int
>
*
odd
;
static
base
::
atomic
<
int
>
*
odd
;
static
base
::
atomic
<
int
>
*
even
;
static
base
::
atomic
<
int
>
*
even
;
static
base
::
atomic
<
int
>
nthreads
(
0
);
static
base
::
atomic
<
int
>
nbthreads
(
0
);
static
base
::
atomic
<
int
>
npthreads
(
0
);
static
BAIDU_THREAD_LOCAL
bool
counted
=
false
;
static
BAIDU_THREAD_LOCAL
bool
counted
=
false
;
static
base
::
atomic
<
bool
>
stop
(
false
);
static
base
::
atomic
<
bool
>
stop
(
false
);
static
void
*
odd_thread
(
void
*
)
{
static
void
*
odd_thread
(
void
*
)
{
nbthreads
.
fetch_add
(
1
);
while
(
!
stop
)
{
while
(
!
stop
)
{
if
(
!
counted
)
{
if
(
!
counted
)
{
counted
=
true
;
counted
=
true
;
nthreads
.
fetch_add
(
1
);
n
p
threads
.
fetch_add
(
1
);
}
}
bthread
::
butex_wake_all
(
even
);
bthread
::
butex_wake_all
(
even
);
bthread
::
butex_wait
(
odd
,
0
,
NULL
);
bthread
::
butex_wait
(
odd
,
0
,
NULL
);
...
@@ -57,10 +59,11 @@ static void *odd_thread(void *) {
...
@@ -57,10 +59,11 @@ static void *odd_thread(void *) {
}
}
static
void
*
even_thread
(
void
*
)
{
static
void
*
even_thread
(
void
*
)
{
nbthreads
.
fetch_add
(
1
);
while
(
!
stop
)
{
while
(
!
stop
)
{
if
(
!
counted
)
{
if
(
!
counted
)
{
counted
=
true
;
counted
=
true
;
nthreads
.
fetch_add
(
1
);
n
p
threads
.
fetch_add
(
1
);
}
}
bthread
::
butex_wake_all
(
odd
);
bthread
::
butex_wake_all
(
odd
);
bthread
::
butex_wait
(
even
,
0
,
NULL
);
bthread
::
butex_wait
(
even
,
0
,
NULL
);
...
@@ -75,7 +78,7 @@ TEST(BthreadTest, setconcurrency_with_running_bthread) {
...
@@ -75,7 +78,7 @@ TEST(BthreadTest, setconcurrency_with_running_bthread) {
*
odd
=
0
;
*
odd
=
0
;
*
even
=
0
;
*
even
=
0
;
std
::
vector
<
bthread_t
>
tids
;
std
::
vector
<
bthread_t
>
tids
;
const
int
N
=
7
00
;
const
int
N
=
5
00
;
for
(
int
i
=
0
;
i
<
N
;
++
i
)
{
for
(
int
i
=
0
;
i
<
N
;
++
i
)
{
bthread_t
tid
;
bthread_t
tid
;
bthread_start_background
(
&
tid
,
&
BTHREAD_ATTR_SMALL
,
odd_thread
,
NULL
);
bthread_start_background
(
&
tid
,
&
BTHREAD_ATTR_SMALL
,
odd_thread
,
NULL
);
...
@@ -87,7 +90,7 @@ TEST(BthreadTest, setconcurrency_with_running_bthread) {
...
@@ -87,7 +90,7 @@ TEST(BthreadTest, setconcurrency_with_running_bthread) {
ASSERT_EQ
(
0
,
bthread_setconcurrency
(
i
));
ASSERT_EQ
(
0
,
bthread_setconcurrency
(
i
));
ASSERT_EQ
(
i
,
bthread_getconcurrency
());
ASSERT_EQ
(
i
,
bthread_getconcurrency
());
}
}
usleep
(
2
000
*
N
);
usleep
(
1
000
*
N
);
*
odd
=
1
;
*
odd
=
1
;
*
even
=
1
;
*
even
=
1
;
stop
=
true
;
stop
=
true
;
...
@@ -97,6 +100,9 @@ TEST(BthreadTest, setconcurrency_with_running_bthread) {
...
@@ -97,6 +100,9 @@ TEST(BthreadTest, setconcurrency_with_running_bthread) {
bthread_join
(
tids
[
i
],
NULL
);
bthread_join
(
tids
[
i
],
NULL
);
}
}
LOG
(
INFO
)
<<
"All bthreads has quit"
;
LOG
(
INFO
)
<<
"All bthreads has quit"
;
ASSERT_EQ
(
N
,
nthreads
);
ASSERT_EQ
(
2
*
N
,
nbthreads
);
// This is not necessarily true, not all workers need to run sth.
//ASSERT_EQ(N, npthreads);
LOG
(
INFO
)
<<
"Touched pthreads="
<<
npthreads
;
}
}
}
// namespace
}
// namespace
test/type_traits_unittest.cc
View file @
5eaf488d
...
@@ -18,7 +18,11 @@ struct BStruct {
...
@@ -18,7 +18,11 @@ struct BStruct {
int
x
;
int
x
;
};
};
class
BClass
{
class
BClass
{
#if defined(__clang__)
int
ALLOW_UNUSED
_x
;
int
ALLOW_UNUSED
_x
;
#else
int
_x
;
#endif
};
};
class
Parent
{};
class
Parent
{};
...
...
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