Commit 5eaf488d authored by zhujiashun's avatar zhujiashun
parents cacf83c6 27db3d61
...@@ -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); npthreads.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); npthreads.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 = 700; const int N = 500;
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(2000 * N); usleep(1000 * 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
...@@ -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 {};
......
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