2222
2323namespace {
2424
25- BAIDU_THREAD_LOCAL int * dummy = NULL ;
25+ BAIDU_THREAD_LOCAL int * dummy = nullptr ;
2626const size_t NTHREAD = 8 ;
2727static bool processed[NTHREAD +1 ];
2828static bool deleted[NTHREAD +1 ];
@@ -70,15 +70,15 @@ void* foo(void* arg) {
7070 x = arg;
7171 usleep (10000 );
7272 printf (" x=%p\n " , x);
73- return NULL ;
73+ return nullptr ;
7474}
7575
7676TEST_F (BaiduThreadLocalTest, thread_local_keyword) {
7777 pthread_t th[2 ];
78- pthread_create (&th[0 ], NULL , foo, (void *)1 );
79- pthread_create (&th[1 ], NULL , foo, (void *)2 );
80- pthread_join (th[0 ], NULL );
81- pthread_join (th[1 ], NULL );
78+ pthread_create (&th[0 ], nullptr , foo, (void *)1 );
79+ pthread_create (&th[1 ], nullptr , foo, (void *)2 );
80+ pthread_join (th[0 ], nullptr );
81+ pthread_join (th[1 ], nullptr );
8282}
8383
8484void * yell (void *) {
@@ -89,7 +89,7 @@ void* yell(void*) {
8989 EXPECT_EQ (p, butil::get_thread_local<YellObj>());
9090 EXPECT_EQ (2 , YellObj::nc);
9191 EXPECT_EQ (0 , YellObj::nd);
92- return NULL ;
92+ return nullptr ;
9393}
9494
9595TEST_F (BaiduThreadLocalTest, get_thread_local) {
@@ -103,8 +103,8 @@ TEST_F(BaiduThreadLocalTest, get_thread_local) {
103103 ASSERT_EQ (1 , YellObj::nc);
104104 ASSERT_EQ (0 , YellObj::nd);
105105 pthread_t th;
106- ASSERT_EQ (0 , pthread_create (&th, NULL , yell, NULL ));
107- pthread_join (th, NULL );
106+ ASSERT_EQ (0 , pthread_create (&th, nullptr , yell, nullptr ));
107+ pthread_join (th, nullptr );
108108 EXPECT_EQ (2 , YellObj::nc);
109109 EXPECT_EQ (1 , YellObj::nd);
110110}
@@ -113,7 +113,7 @@ void delete_dummy(void* arg) {
113113 *(bool *)arg = true ;
114114 if (dummy) {
115115 delete dummy;
116- dummy = NULL ;
116+ dummy = nullptr ;
117117 } else {
118118 printf (" dummy is NULL\n " );
119119 }
@@ -122,15 +122,15 @@ void delete_dummy(void* arg) {
122122void * proc_dummy (void * arg) {
123123 bool *p = (bool *)arg;
124124 *p = true ;
125- EXPECT_TRUE (dummy == NULL );
125+ EXPECT_TRUE (dummy == nullptr );
126126 dummy = new int (p - processed);
127127 butil::thread_atexit (delete_dummy, deleted + (p - processed));
128- return NULL ;
128+ return nullptr ;
129129}
130130
131131TEST_F (BaiduThreadLocalTest, sanity) {
132132 errno = 0 ;
133- ASSERT_EQ (-1 , butil::thread_atexit (NULL ));
133+ ASSERT_EQ (-1 , butil::thread_atexit (nullptr ));
134134 ASSERT_EQ (EINVAL , errno);
135135
136136 processed[NTHREAD ] = false ;
@@ -141,18 +141,18 @@ TEST_F(BaiduThreadLocalTest, sanity) {
141141 for (size_t i = 0 ; i < NTHREAD ; ++i) {
142142 processed[i] = false ;
143143 deleted[i] = false ;
144- ASSERT_EQ (0 , pthread_create (&th[i], NULL , proc_dummy, processed + i));
144+ ASSERT_EQ (0 , pthread_create (&th[i], nullptr , proc_dummy, processed + i));
145145 }
146146 for (size_t i = 0 ; i < NTHREAD ; ++i) {
147- ASSERT_EQ (0 , pthread_join (th[i], NULL ));
147+ ASSERT_EQ (0 , pthread_join (th[i], nullptr ));
148148 ASSERT_TRUE (processed[i]);
149149 ASSERT_TRUE (deleted[i]);
150150 }
151151}
152152
153- static std::ostringstream* oss = NULL ;
153+ static std::ostringstream* oss = nullptr ;
154154inline std::ostringstream& get_oss () {
155- if (oss == NULL ) {
155+ if (oss == nullptr ) {
156156 oss = new std::ostringstream;
157157 }
158158 return *oss;
@@ -181,8 +181,8 @@ static void check_result() {
181181}
182182
183183TEST_F (BaiduThreadLocalTest, call_order_and_cancel) {
184- butil::thread_atexit_cancel (NULL );
185- butil::thread_atexit_cancel (NULL , NULL );
184+ butil::thread_atexit_cancel (nullptr );
185+ butil::thread_atexit_cancel (nullptr , nullptr );
186186
187187 ASSERT_EQ (0 , butil::thread_atexit (check_result));
188188
@@ -192,12 +192,12 @@ TEST_F(BaiduThreadLocalTest, call_order_and_cancel) {
192192 ASSERT_EQ (0 , butil::thread_atexit (fun3, (void *)1 ));
193193 ASSERT_EQ (0 , butil::thread_atexit (fun3, (void *)1 ));
194194 ASSERT_EQ (0 , butil::thread_atexit (fun3, (void *)2 ));
195- ASSERT_EQ (0 , butil::thread_atexit (fun4, NULL ));
195+ ASSERT_EQ (0 , butil::thread_atexit (fun4, nullptr ));
196196
197- butil::thread_atexit_cancel (NULL );
198- butil::thread_atexit_cancel (NULL , NULL );
197+ butil::thread_atexit_cancel (nullptr );
198+ butil::thread_atexit_cancel (nullptr , nullptr );
199199 butil::thread_atexit_cancel (fun1);
200- butil::thread_atexit_cancel (fun3, NULL );
200+ butil::thread_atexit_cancel (fun3, nullptr );
201201 butil::thread_atexit_cancel (fun3, (void *)1 );
202202}
203203
0 commit comments