Skip to content

Commit

Permalink
Thread local without num limit
Browse files Browse the repository at this point in the history
  • Loading branch information
chenBright committed Jul 2, 2023
1 parent dc5a8ce commit 4c9f1de
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/butil/thread_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include "thread_key.h"
#include "pthread.h"
#include <errno.h>
#include <deque>
#include "butil/thread_local.h"

Expand Down
1 change: 0 additions & 1 deletion src/butil/thread_key.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ T* ThreadLocal<T>::get() {
}
int rc = thread_setspecific(_key, ptr);
if (rc != 0) {
errno = rc;
DefaultDtor(ptr);
return NULL;
}
Expand Down
11 changes: 3 additions & 8 deletions test/thread_key_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ TEST(ThreadLocalTest, sanity) {
std::unique_ptr<int> data(new int(1));
int *raw_data = data.get();
ASSERT_EQ(0, butil::thread_key_create(key, NULL));
ASSERT_NE(0, butil::thread_key_create(key, NULL));

ASSERT_EQ(NULL, butil::thread_getspecific(key));
ASSERT_EQ(0, butil::thread_setspecific(key, (void *)raw_data));
Expand Down Expand Up @@ -130,7 +129,7 @@ TEST(ThreadLocalTest, thread_key_create_and_delete) {
}
}

void* ThreadLocalFun(void* arg) {
void* ThreadLocalFunc(void* arg) {
auto thread_locals = (std::vector<ThreadLocal<int>*>*)arg;
std::vector<int> expects(thread_locals->size(), 0);
for (auto tl : *thread_locals) {
Expand All @@ -148,7 +147,7 @@ void* ThreadLocalFun(void* arg) {
}
}

void TestThreadLocalMultiThread() {
TEST(ThreadLocalTest, thread_local_multi_thread) {
g_stopped = false;
int thread_local_num = 20480;
std::vector<ThreadLocal<int>*> args(thread_local_num, NULL);
Expand All @@ -159,7 +158,7 @@ void TestThreadLocalMultiThread() {
const int thread_num = 8;
pthread_t threads[thread_num];
for (int i = 0; i < thread_num; ++i) {
ASSERT_EQ(0, pthread_create(&threads[i], NULL, ThreadLocalFun, &args));
ASSERT_EQ(0, pthread_create(&threads[i], NULL, ThreadLocalFunc, &args));
}

sleep(5);
Expand All @@ -172,10 +171,6 @@ void TestThreadLocalMultiThread() {
}
}

TEST(ThreadLocalTest, thread_local_multi_thread) {
TestThreadLocalMultiThread();
}

struct BAIDU_CACHELINE_ALIGNMENT ThreadKeyArg {
std::vector<ThreadKey*> thread_keys;
bool ready_delete = false;
Expand Down

0 comments on commit 4c9f1de

Please sign in to comment.