This is an automated email from the ASF dual-hosted git repository.
wwbmmm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git
The following commit(s) were added to refs/heads/master by this push:
new a2a43d95 Refactor NULL with nullptr in butil/threading (#3443)
a2a43d95 is described below
commit a2a43d951a778d5346d3def3b0655e8a95c16c97
Author: Bright Chen <[email protected]>
AuthorDate: Sat Aug 15 13:56:50 2026 +0800
Refactor NULL with nullptr in butil/threading (#3443)
---
src/butil/threading/platform_thread_posix.cc | 8 ++++----
src/butil/threading/simple_thread.cc | 8 ++++----
src/butil/threading/simple_thread.h | 2 +-
src/butil/threading/thread_id_name_manager.cc | 4 ++--
src/butil/threading/thread_local.h | 14 +++++++-------
src/butil/threading/thread_local_posix.cc | 2 +-
src/butil/threading/thread_local_storage.cc | 12 ++++++------
src/butil/threading/thread_local_storage.h | 4 ++--
8 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/src/butil/threading/platform_thread_posix.cc
b/src/butil/threading/platform_thread_posix.cc
index 5e1403da..32c34cf2 100644
--- a/src/butil/threading/platform_thread_posix.cc
+++ b/src/butil/threading/platform_thread_posix.cc
@@ -39,10 +39,10 @@ namespace {
struct ThreadParams {
ThreadParams()
- : delegate(NULL),
+ : delegate(nullptr),
joinable(false),
priority(kThreadPriority_Normal),
- handle(NULL),
+ handle(nullptr),
handle_set(false, false) {
}
@@ -83,7 +83,7 @@ void* ThreadFunc(void* params) {
PlatformThread::CurrentId());
butil::TerminateOnThread();
- return NULL;
+ return nullptr;
}
bool CreateThread(size_t stack_size, bool joinable,
@@ -231,7 +231,7 @@ void PlatformThread::Join(PlatformThreadHandle
thread_handle) {
// the thread referred to by |thread_handle| may still be running long-lived
/
// blocking tasks.
butil::ThreadRestrictions::AssertIOAllowed();
- CHECK_EQ(0, pthread_join(thread_handle.handle_, NULL));
+ CHECK_EQ(0, pthread_join(thread_handle.handle_, nullptr));
}
} // namespace butil
diff --git a/src/butil/threading/simple_thread.cc
b/src/butil/threading/simple_thread.cc
index 40559ba4..301117f0 100644
--- a/src/butil/threading/simple_thread.cc
+++ b/src/butil/threading/simple_thread.cc
@@ -79,7 +79,7 @@ DelegateSimpleThread::~DelegateSimpleThread() {
void DelegateSimpleThread::Run() {
DCHECK(delegate_) << "Tried to call Run without a delegate (called twice?)";
delegate_->Run();
- delegate_ = NULL;
+ delegate_ = nullptr;
}
DelegateSimpleThreadPool::DelegateSimpleThreadPool(
@@ -109,7 +109,7 @@ void DelegateSimpleThreadPool::JoinAll() {
DCHECK(!threads_.empty()) << "JoinAll() called with no outstanding threads.";
// Tell all our threads to quit their worker loop.
- AddWork(NULL, num_threads_);
+ AddWork(nullptr, num_threads_);
// Join and destroy all the worker threads.
for (int i = 0; i < num_threads_; ++i) {
@@ -130,7 +130,7 @@ void DelegateSimpleThreadPool::AddWork(Delegate* delegate,
int repeat_count) {
}
void DelegateSimpleThreadPool::Run() {
- Delegate* work = NULL;
+ Delegate* work = nullptr;
while (true) {
dry_.Wait();
@@ -148,7 +148,7 @@ void DelegateSimpleThreadPool::Run() {
dry_.Reset();
}
- // A NULL delegate pointer signals us to quit.
+ // A nullptr delegate pointer signals us to quit.
if (!work)
break;
diff --git a/src/butil/threading/simple_thread.h
b/src/butil/threading/simple_thread.h
index 7eb6790f..904bda17 100644
--- a/src/butil/threading/simple_thread.h
+++ b/src/butil/threading/simple_thread.h
@@ -167,7 +167,7 @@ class BUTIL_EXPORT DelegateSimpleThreadPool
void JoinAll();
// It is safe to AddWork() any time, before or after Start().
- // Delegate* should always be a valid pointer, NULL is reserved internally.
+ // Delegate* should always be a valid pointer, nullptr is reserved
internally.
void AddWork(Delegate* work, int repeat_count);
void AddWork(Delegate* work) {
AddWork(work, 1);
diff --git a/src/butil/threading/thread_id_name_manager.cc
b/src/butil/threading/thread_id_name_manager.cc
index cb0de0fa..a12e75d9 100644
--- a/src/butil/threading/thread_id_name_manager.cc
+++ b/src/butil/threading/thread_id_name_manager.cc
@@ -20,7 +20,7 @@ static std::string* g_default_name;
}
ThreadIdNameManager::ThreadIdNameManager()
- : main_process_name_(NULL),
+ : main_process_name_(nullptr),
main_process_id_(kInvalidThreadId) {
g_default_name = new std::string(kDefaultName);
@@ -53,7 +53,7 @@ void ThreadIdNameManager::SetName(PlatformThreadId id, const
char* name) {
AutoLock locked(lock_);
NameToInternedNameMap::iterator iter = name_to_interned_name_.find(str_name);
- std::string* leaked_str = NULL;
+ std::string* leaked_str = nullptr;
if (iter != name_to_interned_name_.end()) {
leaked_str = iter->second;
} else {
diff --git a/src/butil/threading/thread_local.h
b/src/butil/threading/thread_local.h
index 4eda9378..3435deec 100644
--- a/src/butil/threading/thread_local.h
+++ b/src/butil/threading/thread_local.h
@@ -15,7 +15,7 @@
//
// ThreadLocalPointer<Type> wraps a Type*. It performs no creation or
// destruction, so memory management must be handled elsewhere. The first call
-// to Get() on a thread will return NULL. You can update the pointer with a
+// to Get() on a thread will return nullptr. You can update the pointer with a
// call to Set().
//
// ThreadLocalBoolean wraps a bool. It will default to false if it has never
@@ -33,17 +33,17 @@
// // My class is logically attached to a single thread. We cache a pointer
// // on the thread it was created on, so we can implement current().
// MyClass::MyClass() {
-// DCHECK(Singleton<ThreadLocalPointer<MyClass> >::get()->Get() == NULL);
+// DCHECK(Singleton<ThreadLocalPointer<MyClass> >::get()->Get() ==
nullptr);
// Singleton<ThreadLocalPointer<MyClass> >::get()->Set(this);
// }
//
// MyClass::~MyClass() {
-// DCHECK(Singleton<ThreadLocalPointer<MyClass> >::get()->Get() != NULL);
-// Singleton<ThreadLocalPointer<MyClass> >::get()->Set(NULL);
+// DCHECK(Singleton<ThreadLocalPointer<MyClass> >::get()->Get() !=
nullptr);
+// Singleton<ThreadLocalPointer<MyClass> >::get()->Set(nullptr);
// }
//
// // Return the current MyClass associated with the calling thread, can be
-// // NULL if there isn't a MyClass associated.
+// // nullptr if there isn't a MyClass associated.
// MyClass* MyClass::current() {
// return Singleton<ThreadLocalPointer<MyClass> >::get()->Get();
// }
@@ -115,11 +115,11 @@ class ThreadLocalBoolean {
~ThreadLocalBoolean() {}
bool Get() {
- return tlp_.Get() != NULL;
+ return tlp_.Get() != nullptr;
}
void Set(bool val) {
- tlp_.Set(val ? this : NULL);
+ tlp_.Set(val ? this : nullptr);
}
private:
diff --git a/src/butil/threading/thread_local_posix.cc
b/src/butil/threading/thread_local_posix.cc
index 8af300da..484bc88b 100644
--- a/src/butil/threading/thread_local_posix.cc
+++ b/src/butil/threading/thread_local_posix.cc
@@ -15,7 +15,7 @@ namespace internal {
// static
void ThreadLocalPlatform::AllocateSlot(SlotType* slot) {
- int error = pthread_key_create(slot, NULL);
+ int error = pthread_key_create(slot, nullptr);
CHECK_EQ(error, 0);
}
diff --git a/src/butil/threading/thread_local_storage.cc
b/src/butil/threading/thread_local_storage.cc
index 6d6c42cf..32071d82 100644
--- a/src/butil/threading/thread_local_storage.cc
+++ b/src/butil/threading/thread_local_storage.cc
@@ -141,17 +141,17 @@ void OnThreadExitInternal(void* value) {
butil::subtle::NoBarrier_Load(&g_last_used_tls_key);
for (int slot = last_used_tls_key; slot > 0; --slot) {
void* value = stack_allocated_tls_data[slot];
- if (value == NULL)
+ if (value == nullptr)
continue;
butil::ThreadLocalStorage::TLSDestructorFunc destructor =
g_tls_destructors[slot];
- if (destructor == NULL)
+ if (destructor == nullptr)
continue;
- stack_allocated_tls_data[slot] = NULL; // pre-clear the slot.
+ stack_allocated_tls_data[slot] = nullptr; // pre-clear the slot.
destructor(value);
// Any destructor might have called a different service, which then set
- // a different slot to a non-NULL value. Hence we need to check
+ // a different slot to a non-nullptr value. Hence we need to check
// the whole vector again. This is a pthread standard.
need_to_scan_destructors = true;
}
@@ -162,7 +162,7 @@ void OnThreadExitInternal(void* value) {
}
// Remove our stack allocated vector.
- PlatformThreadLocalStorage::SetTLSValue(key, NULL);
+ PlatformThreadLocalStorage::SetTLSValue(key, nullptr);
}
} // namespace
@@ -220,7 +220,7 @@ void ThreadLocalStorage::StaticSlot::Free() {
// So all we need to do is wipe the destructor.
DCHECK_GT(slot_, 0);
DCHECK_LT(slot_, kThreadLocalStorageSize);
- g_tls_destructors[slot_] = NULL;
+ g_tls_destructors[slot_] = nullptr;
slot_ = 0;
initialized_ = false;
}
diff --git a/src/butil/threading/thread_local_storage.h
b/src/butil/threading/thread_local_storage.h
index d055bc53..f9c06be8 100644
--- a/src/butil/threading/thread_local_storage.h
+++ b/src/butil/threading/thread_local_storage.h
@@ -97,7 +97,7 @@ class BUTIL_EXPORT ThreadLocalStorage {
struct BUTIL_EXPORT StaticSlot {
// Set up the TLS slot. Called by the constructor.
// 'destructor' is a pointer to a function to perform per-thread cleanup of
- // this object. If set to NULL, no cleanup is done for this TLS slot.
+ // this object. If set to nullptr, no cleanup is done for this TLS slot.
// Returns false on error.
bool Initialize(TLSDestructorFunc destructor);
@@ -127,7 +127,7 @@ class BUTIL_EXPORT ThreadLocalStorage {
class BUTIL_EXPORT Slot : public StaticSlot {
public:
// Calls StaticSlot::Initialize().
- explicit Slot(TLSDestructorFunc destructor = NULL);
+ explicit Slot(TLSDestructorFunc destructor = nullptr);
private:
using StaticSlot::initialized_;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]