Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning.
Test: m
Bug: 68236239
Change-Id: I5b4123bc6709641315120a191e36cc57541349b2
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index f2f6e01..fc8945c 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -45,7 +45,7 @@
TEST(pthread, pthread_key_create) {
pthread_key_t key;
- ASSERT_EQ(0, pthread_key_create(&key, NULL));
+ ASSERT_EQ(0, pthread_key_create(&key, nullptr));
ASSERT_EQ(0, pthread_key_delete(key));
// Can't delete a key that's already been deleted.
ASSERT_EQ(EINVAL, pthread_key_delete(key));
@@ -76,7 +76,7 @@
for (int i = 0; i < nkeys; ++i) {
pthread_key_t key;
// If this fails, it's likely that LIBC_PTHREAD_KEY_RESERVED_COUNT is wrong.
- ASSERT_EQ(0, pthread_key_create(&key, NULL)) << i << " of " << nkeys;
+ ASSERT_EQ(0, pthread_key_create(&key, nullptr)) << i << " of " << nkeys;
keys.push_back(key);
ASSERT_EQ(0, pthread_setspecific(key, reinterpret_cast<void*>(i)));
}
@@ -97,7 +97,7 @@
// be more than we are allowed to allocate now.
for (int i = 0; i < PTHREAD_KEYS_MAX; i++) {
pthread_key_t key;
- rv = pthread_key_create(&key, NULL);
+ rv = pthread_key_create(&key, nullptr);
if (rv == EAGAIN) {
break;
}
@@ -119,12 +119,12 @@
TEST(pthread, pthread_key_delete) {
void* expected = reinterpret_cast<void*>(1234);
pthread_key_t key;
- ASSERT_EQ(0, pthread_key_create(&key, NULL));
+ ASSERT_EQ(0, pthread_key_create(&key, nullptr));
ASSERT_EQ(0, pthread_setspecific(key, expected));
ASSERT_EQ(expected, pthread_getspecific(key));
ASSERT_EQ(0, pthread_key_delete(key));
- // After deletion, pthread_getspecific returns NULL.
- ASSERT_EQ(NULL, pthread_getspecific(key));
+ // After deletion, pthread_getspecific returns nullptr.
+ ASSERT_EQ(nullptr, pthread_getspecific(key));
// And you can't use pthread_setspecific with the deleted key.
ASSERT_EQ(EINVAL, pthread_setspecific(key, expected));
}
@@ -132,7 +132,7 @@
TEST(pthread, pthread_key_fork) {
void* expected = reinterpret_cast<void*>(1234);
pthread_key_t key;
- ASSERT_EQ(0, pthread_key_create(&key, NULL));
+ ASSERT_EQ(0, pthread_key_create(&key, nullptr));
ASSERT_EQ(0, pthread_setspecific(key, expected));
ASSERT_EQ(expected, pthread_getspecific(key));
@@ -157,10 +157,10 @@
TEST(pthread, pthread_key_dirty) {
pthread_key_t key;
- ASSERT_EQ(0, pthread_key_create(&key, NULL));
+ ASSERT_EQ(0, pthread_key_create(&key, nullptr));
size_t stack_size = 640 * 1024;
- void* stack = mmap(NULL, stack_size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+ void* stack = mmap(nullptr, stack_size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
ASSERT_NE(MAP_FAILED, stack);
memset(stack, 0xff, stack_size);
@@ -217,7 +217,7 @@
private:
static void* SpinFn(void*) {
while (spin_flag_) {}
- return NULL;
+ return nullptr;
}
static std::atomic<bool> spin_flag_;
};
@@ -228,7 +228,7 @@
std::atomic<bool> SpinFunctionHelper::spin_flag_;
static void* JoinFn(void* arg) {
- return reinterpret_cast<void*>(pthread_join(reinterpret_cast<pthread_t>(arg), NULL));
+ return reinterpret_cast<void*>(pthread_join(reinterpret_cast<pthread_t>(arg), nullptr));
}
static void AssertDetached(pthread_t t, bool is_detached) {
@@ -241,15 +241,15 @@
}
static void MakeDeadThread(pthread_t& t) {
- ASSERT_EQ(0, pthread_create(&t, NULL, IdFn, NULL));
- ASSERT_EQ(0, pthread_join(t, NULL));
+ ASSERT_EQ(0, pthread_create(&t, nullptr, IdFn, nullptr));
+ ASSERT_EQ(0, pthread_join(t, nullptr));
}
TEST(pthread, pthread_create) {
void* expected_result = reinterpret_cast<void*>(123);
// Can we create a thread?
pthread_t t;
- ASSERT_EQ(0, pthread_create(&t, NULL, IdFn, expected_result));
+ ASSERT_EQ(0, pthread_create(&t, nullptr, IdFn, expected_result));
// If we join, do we get the expected value back?
void* result;
ASSERT_EQ(0, pthread_join(t, &result));
@@ -262,32 +262,32 @@
ASSERT_EQ(0, pthread_attr_setstacksize(&attributes, static_cast<size_t>(-1) & ~(getpagesize() - 1)));
pthread_t t;
- ASSERT_EQ(EAGAIN, pthread_create(&t, &attributes, IdFn, NULL));
+ ASSERT_EQ(EAGAIN, pthread_create(&t, &attributes, IdFn, nullptr));
}
TEST(pthread, pthread_no_join_after_detach) {
SpinFunctionHelper spin_helper;
pthread_t t1;
- ASSERT_EQ(0, pthread_create(&t1, NULL, spin_helper.GetFunction(), NULL));
+ ASSERT_EQ(0, pthread_create(&t1, nullptr, spin_helper.GetFunction(), nullptr));
// After a pthread_detach...
ASSERT_EQ(0, pthread_detach(t1));
AssertDetached(t1, true);
// ...pthread_join should fail.
- ASSERT_EQ(EINVAL, pthread_join(t1, NULL));
+ ASSERT_EQ(EINVAL, pthread_join(t1, nullptr));
}
TEST(pthread, pthread_no_op_detach_after_join) {
SpinFunctionHelper spin_helper;
pthread_t t1;
- ASSERT_EQ(0, pthread_create(&t1, NULL, spin_helper.GetFunction(), NULL));
+ ASSERT_EQ(0, pthread_create(&t1, nullptr, spin_helper.GetFunction(), nullptr));
// If thread 2 is already waiting to join thread 1...
pthread_t t2;
- ASSERT_EQ(0, pthread_create(&t2, NULL, JoinFn, reinterpret_cast<void*>(t1)));
+ ASSERT_EQ(0, pthread_create(&t2, nullptr, JoinFn, reinterpret_cast<void*>(t1)));
sleep(1); // (Give t2 a chance to call pthread_join.)
@@ -307,7 +307,7 @@
}
TEST(pthread, pthread_join_self) {
- ASSERT_EQ(EDEADLK, pthread_join(pthread_self(), NULL));
+ ASSERT_EQ(EDEADLK, pthread_join(pthread_self(), nullptr));
}
struct TestBug37410 {
@@ -317,18 +317,18 @@
static void main() {
TestBug37410 data;
data.main_thread = pthread_self();
- ASSERT_EQ(0, pthread_mutex_init(&data.mutex, NULL));
+ ASSERT_EQ(0, pthread_mutex_init(&data.mutex, nullptr));
ASSERT_EQ(0, pthread_mutex_lock(&data.mutex));
pthread_t t;
- ASSERT_EQ(0, pthread_create(&t, NULL, TestBug37410::thread_fn, reinterpret_cast<void*>(&data)));
+ ASSERT_EQ(0, pthread_create(&t, nullptr, TestBug37410::thread_fn, reinterpret_cast<void*>(&data)));
// Wait for the thread to be running...
ASSERT_EQ(0, pthread_mutex_lock(&data.mutex));
ASSERT_EQ(0, pthread_mutex_unlock(&data.mutex));
// ...and exit.
- pthread_exit(NULL);
+ pthread_exit(nullptr);
}
private:
@@ -339,9 +339,9 @@
pthread_mutex_unlock(&data->mutex);
// And wait for the main thread to exit.
- pthread_join(data->main_thread, NULL);
+ pthread_join(data->main_thread, nullptr);
- return NULL;
+ return nullptr;
}
};
@@ -365,29 +365,29 @@
// Check that SIGUSR1 isn't blocked.
sigset_t original_set;
sigemptyset(&original_set);
- ASSERT_EQ(0, pthread_sigmask(SIG_BLOCK, NULL, &original_set));
+ ASSERT_EQ(0, pthread_sigmask(SIG_BLOCK, nullptr, &original_set));
ASSERT_FALSE(sigismember(&original_set, SIGUSR1));
// Block SIGUSR1.
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGUSR1);
- ASSERT_EQ(0, pthread_sigmask(SIG_BLOCK, &set, NULL));
+ ASSERT_EQ(0, pthread_sigmask(SIG_BLOCK, &set, nullptr));
// Check that SIGUSR1 is blocked.
sigset_t final_set;
sigemptyset(&final_set);
- ASSERT_EQ(0, pthread_sigmask(SIG_BLOCK, NULL, &final_set));
+ ASSERT_EQ(0, pthread_sigmask(SIG_BLOCK, nullptr, &final_set));
ASSERT_TRUE(sigismember(&final_set, SIGUSR1));
// ...and that sigprocmask agrees with pthread_sigmask.
sigemptyset(&final_set);
- ASSERT_EQ(0, sigprocmask(SIG_BLOCK, NULL, &final_set));
+ ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &final_set));
ASSERT_TRUE(sigismember(&final_set, SIGUSR1));
// Spawn a thread that calls sigwait and tells us what it received.
pthread_t signal_thread;
int received_signal = -1;
- ASSERT_EQ(0, pthread_create(&signal_thread, NULL, SignalHandlerFn, &received_signal));
+ ASSERT_EQ(0, pthread_create(&signal_thread, nullptr, SignalHandlerFn, &received_signal));
// Send that thread SIGUSR1.
pthread_kill(signal_thread, SIGUSR1);
@@ -399,36 +399,36 @@
ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(join_result));
// Restore the original signal mask.
- ASSERT_EQ(0, pthread_sigmask(SIG_SETMASK, &original_set, NULL));
+ ASSERT_EQ(0, pthread_sigmask(SIG_SETMASK, &original_set, nullptr));
}
TEST(pthread, pthread_sigmask64_SIGTRMIN) {
// Check that SIGRTMIN isn't blocked.
sigset64_t original_set;
sigemptyset64(&original_set);
- ASSERT_EQ(0, pthread_sigmask64(SIG_BLOCK, NULL, &original_set));
+ ASSERT_EQ(0, pthread_sigmask64(SIG_BLOCK, nullptr, &original_set));
ASSERT_FALSE(sigismember64(&original_set, SIGRTMIN));
// Block SIGRTMIN.
sigset64_t set;
sigemptyset64(&set);
sigaddset64(&set, SIGRTMIN);
- ASSERT_EQ(0, pthread_sigmask64(SIG_BLOCK, &set, NULL));
+ ASSERT_EQ(0, pthread_sigmask64(SIG_BLOCK, &set, nullptr));
// Check that SIGRTMIN is blocked.
sigset64_t final_set;
sigemptyset64(&final_set);
- ASSERT_EQ(0, pthread_sigmask64(SIG_BLOCK, NULL, &final_set));
+ ASSERT_EQ(0, pthread_sigmask64(SIG_BLOCK, nullptr, &final_set));
ASSERT_TRUE(sigismember64(&final_set, SIGRTMIN));
// ...and that sigprocmask64 agrees with pthread_sigmask64.
sigemptyset64(&final_set);
- ASSERT_EQ(0, sigprocmask64(SIG_BLOCK, NULL, &final_set));
+ ASSERT_EQ(0, sigprocmask64(SIG_BLOCK, nullptr, &final_set));
ASSERT_TRUE(sigismember64(&final_set, SIGRTMIN));
// Spawn a thread that calls sigwait64 and tells us what it received.
pthread_t signal_thread;
int received_signal = -1;
- ASSERT_EQ(0, pthread_create(&signal_thread, NULL, SignalHandlerFn, &received_signal));
+ ASSERT_EQ(0, pthread_create(&signal_thread, nullptr, SignalHandlerFn, &received_signal));
// Send that thread SIGRTMIN.
pthread_kill(signal_thread, SIGRTMIN);
@@ -440,7 +440,7 @@
ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(join_result));
// Restore the original signal mask.
- ASSERT_EQ(0, pthread_sigmask64(SIG_SETMASK, &original_set, NULL));
+ ASSERT_EQ(0, pthread_sigmask64(SIG_SETMASK, &original_set, nullptr));
}
static void test_pthread_setname_np__pthread_getname_np(pthread_t t) {
@@ -555,7 +555,7 @@
SpinFunctionHelper spin_helper;
pthread_t t;
- ASSERT_EQ(0, pthread_create(&t, NULL, spin_helper.GetFunction(), NULL));
+ ASSERT_EQ(0, pthread_create(&t, nullptr, spin_helper.GetFunction(), nullptr));
clockid_t c;
ASSERT_EQ(0, pthread_getcpuclockid(t, &c));
@@ -627,12 +627,12 @@
pthread_t dead_thread;
MakeDeadThread(dead_thread);
- EXPECT_DEATH(pthread_join(dead_thread, NULL), "invalid pthread_t");
+ EXPECT_DEATH(pthread_join(dead_thread, nullptr), "invalid pthread_t");
}
TEST_F(pthread_DeathTest, pthread_join__null_thread) {
pthread_t null_thread = 0;
- EXPECT_EQ(ESRCH, pthread_join(null_thread, NULL));
+ EXPECT_EQ(ESRCH, pthread_join(null_thread, nullptr));
}
TEST_F(pthread_DeathTest, pthread_kill__no_such_thread) {
@@ -651,15 +651,15 @@
SpinFunctionHelper spin_helper;
pthread_t t1;
- ASSERT_EQ(0, pthread_create(&t1, NULL, spin_helper.GetFunction(), NULL));
+ ASSERT_EQ(0, pthread_create(&t1, nullptr, spin_helper.GetFunction(), nullptr));
pthread_t t2;
- ASSERT_EQ(0, pthread_create(&t2, NULL, JoinFn, reinterpret_cast<void*>(t1)));
+ ASSERT_EQ(0, pthread_create(&t2, nullptr, JoinFn, reinterpret_cast<void*>(t1)));
sleep(1); // (Give t2 a chance to call pthread_join.)
// Multiple joins to the same thread should fail.
- ASSERT_EQ(EINVAL, pthread_join(t1, NULL));
+ ASSERT_EQ(EINVAL, pthread_join(t1, nullptr));
spin_helper.UnSpin();
@@ -674,15 +674,15 @@
// If the joiner unmapped the thread's stack, that could lead to SIGSEGV in the thread.
for (size_t i = 0; i < 1024; ++i) {
size_t stack_size = 640*1024;
- void* stack = mmap(NULL, stack_size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0);
+ void* stack = mmap(nullptr, stack_size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0);
pthread_attr_t a;
pthread_attr_init(&a);
pthread_attr_setstack(&a, stack, stack_size);
pthread_t t;
- ASSERT_EQ(0, pthread_create(&t, &a, IdFn, NULL));
- ASSERT_EQ(0, pthread_join(t, NULL));
+ ASSERT_EQ(0, pthread_create(&t, &a, IdFn, nullptr));
+ ASSERT_EQ(0, pthread_join(t, nullptr));
ASSERT_EQ(0, munmap(stack, stack_size));
}
}
@@ -691,14 +691,14 @@
pthread_attr_t attributes;
pthread_getattr_np(pthread_self(), &attributes);
pthread_attr_getguardsize(&attributes, reinterpret_cast<size_t*>(arg));
- return NULL;
+ return nullptr;
}
static size_t GetActualGuardSize(const pthread_attr_t& attributes) {
size_t result;
pthread_t t;
pthread_create(&t, &attributes, GetActualGuardSizeFn, &result);
- pthread_join(t, NULL);
+ pthread_join(t, nullptr);
return result;
}
@@ -706,14 +706,14 @@
pthread_attr_t attributes;
pthread_getattr_np(pthread_self(), &attributes);
pthread_attr_getstacksize(&attributes, reinterpret_cast<size_t*>(arg));
- return NULL;
+ return nullptr;
}
static size_t GetActualStackSize(const pthread_attr_t& attributes) {
size_t result;
pthread_t t;
pthread_create(&t, &attributes, GetActualStackSizeFn, &result);
- pthread_join(t, NULL);
+ pthread_join(t, nullptr);
return result;
}
@@ -827,13 +827,13 @@
TEST(pthread, pthread_rwlock_init_same_as_PTHREAD_RWLOCK_INITIALIZER) {
pthread_rwlock_t lock1 = PTHREAD_RWLOCK_INITIALIZER;
pthread_rwlock_t lock2;
- ASSERT_EQ(0, pthread_rwlock_init(&lock2, NULL));
+ ASSERT_EQ(0, pthread_rwlock_init(&lock2, nullptr));
ASSERT_EQ(0, memcmp(&lock1, &lock2, sizeof(lock1)));
}
TEST(pthread, pthread_rwlock_smoke) {
pthread_rwlock_t l;
- ASSERT_EQ(0, pthread_rwlock_init(&l, NULL));
+ ASSERT_EQ(0, pthread_rwlock_init(&l, nullptr));
// Single read lock
ASSERT_EQ(0, pthread_rwlock_rdlock(&l));
@@ -911,7 +911,7 @@
static void test_pthread_rwlock_reader_wakeup_writer(std::function<int (pthread_rwlock_t*)> lock_function) {
RwlockWakeupHelperArg wakeup_arg;
- ASSERT_EQ(0, pthread_rwlock_init(&wakeup_arg.lock, NULL));
+ ASSERT_EQ(0, pthread_rwlock_init(&wakeup_arg.lock, nullptr));
ASSERT_EQ(0, pthread_rwlock_rdlock(&wakeup_arg.lock));
wakeup_arg.progress = RwlockWakeupHelperArg::LOCK_INITIALIZED;
wakeup_arg.tid = 0;
@@ -919,7 +919,7 @@
wakeup_arg.lock_function = lock_function;
pthread_t thread;
- ASSERT_EQ(0, pthread_create(&thread, NULL,
+ ASSERT_EQ(0, pthread_create(&thread, nullptr,
reinterpret_cast<void* (*)(void*)>(pthread_rwlock_wakeup_helper), &wakeup_arg));
WaitUntilThreadSleep(wakeup_arg.tid);
ASSERT_EQ(RwlockWakeupHelperArg::LOCK_WAITING, wakeup_arg.progress);
@@ -927,7 +927,7 @@
wakeup_arg.progress = RwlockWakeupHelperArg::LOCK_RELEASED;
ASSERT_EQ(0, pthread_rwlock_unlock(&wakeup_arg.lock));
- ASSERT_EQ(0, pthread_join(thread, NULL));
+ ASSERT_EQ(0, pthread_join(thread, nullptr));
ASSERT_EQ(RwlockWakeupHelperArg::LOCK_ACCESSED, wakeup_arg.progress);
ASSERT_EQ(0, pthread_rwlock_destroy(&wakeup_arg.lock));
}
@@ -960,7 +960,7 @@
static void test_pthread_rwlock_writer_wakeup_reader(std::function<int (pthread_rwlock_t*)> lock_function) {
RwlockWakeupHelperArg wakeup_arg;
- ASSERT_EQ(0, pthread_rwlock_init(&wakeup_arg.lock, NULL));
+ ASSERT_EQ(0, pthread_rwlock_init(&wakeup_arg.lock, nullptr));
ASSERT_EQ(0, pthread_rwlock_wrlock(&wakeup_arg.lock));
wakeup_arg.progress = RwlockWakeupHelperArg::LOCK_INITIALIZED;
wakeup_arg.tid = 0;
@@ -968,7 +968,7 @@
wakeup_arg.lock_function = lock_function;
pthread_t thread;
- ASSERT_EQ(0, pthread_create(&thread, NULL,
+ ASSERT_EQ(0, pthread_create(&thread, nullptr,
reinterpret_cast<void* (*)(void*)>(pthread_rwlock_wakeup_helper), &wakeup_arg));
WaitUntilThreadSleep(wakeup_arg.tid);
ASSERT_EQ(RwlockWakeupHelperArg::LOCK_WAITING, wakeup_arg.progress);
@@ -976,7 +976,7 @@
wakeup_arg.progress = RwlockWakeupHelperArg::LOCK_RELEASED;
ASSERT_EQ(0, pthread_rwlock_unlock(&wakeup_arg.lock));
- ASSERT_EQ(0, pthread_join(thread, NULL));
+ ASSERT_EQ(0, pthread_join(thread, nullptr));
ASSERT_EQ(RwlockWakeupHelperArg::LOCK_ACCESSED, wakeup_arg.progress);
ASSERT_EQ(0, pthread_rwlock_destroy(&wakeup_arg.lock));
}
@@ -1130,14 +1130,14 @@
void CreateWriterThread(pthread_t& thread, std::atomic<pid_t>& tid) {
tid = 0;
ThreadArg* arg = new ThreadArg(this, tid);
- ASSERT_EQ(0, pthread_create(&thread, NULL,
+ ASSERT_EQ(0, pthread_create(&thread, nullptr,
reinterpret_cast<void* (*)(void*)>(WriterThreadFn), arg));
}
void CreateReaderThread(pthread_t& thread, std::atomic<pid_t>& tid) {
tid = 0;
ThreadArg* arg = new ThreadArg(this, tid);
- ASSERT_EQ(0, pthread_create(&thread, NULL,
+ ASSERT_EQ(0, pthread_create(&thread, nullptr,
reinterpret_cast<void* (*)(void*)>(ReaderThreadFn), arg));
}
@@ -1185,10 +1185,10 @@
pthread_t reader_thread;
std::atomic<pid_t> reader_tid;
helper.CreateReaderThread(reader_thread, reader_tid);
- ASSERT_EQ(0, pthread_join(reader_thread, NULL));
+ ASSERT_EQ(0, pthread_join(reader_thread, nullptr));
ASSERT_EQ(0, pthread_rwlock_unlock(&helper.lock));
- ASSERT_EQ(0, pthread_join(writer_thread, NULL));
+ ASSERT_EQ(0, pthread_join(writer_thread, nullptr));
}
TEST(pthread, pthread_rwlock_kind_PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP) {
@@ -1206,8 +1206,8 @@
WaitUntilThreadSleep(reader_tid);
ASSERT_EQ(0, pthread_rwlock_unlock(&helper.lock));
- ASSERT_EQ(0, pthread_join(writer_thread, NULL));
- ASSERT_EQ(0, pthread_join(reader_thread, NULL));
+ ASSERT_EQ(0, pthread_join(writer_thread, nullptr));
+ ASSERT_EQ(0, pthread_join(reader_thread, nullptr));
}
static int g_once_fn_call_count = 0;
@@ -1366,7 +1366,7 @@
void StartWaitingThread(std::function<int (pthread_cond_t* cond, pthread_mutex_t* mutex)> wait_function) {
progress = INITIALIZED;
this->wait_function = wait_function;
- ASSERT_EQ(0, pthread_create(&thread, NULL, reinterpret_cast<void* (*)(void*)>(WaitThreadFn), this));
+ ASSERT_EQ(0, pthread_create(&thread, nullptr, reinterpret_cast<void* (*)(void*)>(WaitThreadFn), this));
while (progress != WAITING) {
usleep(5000);
}
@@ -1517,7 +1517,7 @@
// We do not use "[stack]" label because in native-bridge environment it is not
// guaranteed to point to the right stack. A native bridge implementation may
// keep separate stack for the guest code.
- void* maps_stack_hi = NULL;
+ void* maps_stack_hi = nullptr;
std::vector<map_record> maps;
ASSERT_TRUE(Maps::parse_maps(&maps));
uintptr_t stack_address = reinterpret_cast<uintptr_t>(&maps_stack_hi);
@@ -1621,7 +1621,7 @@
ASSERT_EQ(getpid(), syscall(__NR_gettid));
const size_t sig_stack_size = 16 * 1024;
- void* sig_stack = mmap(NULL, sig_stack_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS,
+ void* sig_stack = mmap(nullptr, sig_stack_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS,
-1, 0);
ASSERT_NE(MAP_FAILED, sig_stack);
stack_t ss;
@@ -1667,10 +1667,10 @@
// [stack_base, stack_base + stack_size). see b/18908062.
TEST(pthread, pthread_attr_getstack_18908062) {
pthread_t t;
- ASSERT_EQ(0, pthread_create(&t, NULL,
+ ASSERT_EQ(0, pthread_create(&t, nullptr,
reinterpret_cast<void* (*)(void*)>(pthread_attr_getstack_18908062_helper),
- NULL));
- ASSERT_EQ(0, pthread_join(t, NULL));
+ nullptr));
+ ASSERT_EQ(0, pthread_join(t, nullptr));
}
#if defined(__BIONIC__)
@@ -1682,7 +1682,7 @@
// Wait for our parent to call pthread_gettid_np on us before exiting.
pthread_mutex_lock(&pthread_gettid_np_mutex);
pthread_mutex_unlock(&pthread_gettid_np_mutex);
- return NULL;
+ return nullptr;
}
#endif
@@ -1696,13 +1696,13 @@
pid_t t_gettid_result;
pthread_t t;
- pthread_create(&t, NULL, pthread_gettid_np_helper, &t_gettid_result);
+ pthread_create(&t, nullptr, pthread_gettid_np_helper, &t_gettid_result);
pid_t t_pthread_gettid_np_result = pthread_gettid_np(t);
// Release the other thread and wait for it to exit.
pthread_mutex_unlock(&pthread_gettid_np_mutex);
- ASSERT_EQ(0, pthread_join(t, NULL));
+ ASSERT_EQ(0, pthread_join(t, nullptr));
ASSERT_EQ(t_gettid_result, t_pthread_gettid_np_result);
#else
@@ -1721,15 +1721,15 @@
}
static void PthreadCleanupTester() {
- pthread_cleanup_push(CountCleanupRoutine, NULL);
- pthread_cleanup_push(CountCleanupRoutine, NULL);
- pthread_cleanup_push(AbortCleanupRoutine, NULL);
+ pthread_cleanup_push(CountCleanupRoutine, nullptr);
+ pthread_cleanup_push(CountCleanupRoutine, nullptr);
+ pthread_cleanup_push(AbortCleanupRoutine, nullptr);
pthread_cleanup_pop(0); // Pop the abort without executing it.
pthread_cleanup_pop(1); // Pop one count while executing it.
ASSERT_EQ(1U, cleanup_counter);
// Exit while the other count is still on the cleanup stack.
- pthread_exit(NULL);
+ pthread_exit(nullptr);
// Calls to pthread_cleanup_pop/pthread_cleanup_push must always be balanced.
pthread_cleanup_pop(0);
@@ -1737,13 +1737,13 @@
static void* PthreadCleanupStartRoutine(void*) {
PthreadCleanupTester();
- return NULL;
+ return nullptr;
}
TEST(pthread, pthread_cleanup_push__pthread_cleanup_pop) {
pthread_t t;
- ASSERT_EQ(0, pthread_create(&t, NULL, PthreadCleanupStartRoutine, NULL));
- ASSERT_EQ(0, pthread_join(t, NULL));
+ ASSERT_EQ(0, pthread_create(&t, nullptr, PthreadCleanupStartRoutine, nullptr));
+ ASSERT_EQ(0, pthread_join(t, nullptr));
ASSERT_EQ(2U, cleanup_counter);
}
@@ -1956,7 +1956,7 @@
tid = 0;
pthread_t thread;
- ASSERT_EQ(0, pthread_create(&thread, NULL,
+ ASSERT_EQ(0, pthread_create(&thread, nullptr,
reinterpret_cast<void* (*)(void*)>(MutexWakeupHelper::thread_fn), this));
WaitUntilThreadSleep(tid);
@@ -1965,7 +1965,7 @@
progress = LOCK_RELEASED;
ASSERT_EQ(0, pthread_mutex_unlock(&m.lock));
- ASSERT_EQ(0, pthread_join(thread, NULL));
+ ASSERT_EQ(0, pthread_join(thread, nullptr));
ASSERT_EQ(LOCK_ACCESSED, progress);
}
};
@@ -2054,7 +2054,7 @@
child_tid = 0;
pthread_t thread;
- ASSERT_EQ(0, pthread_create(&thread, NULL,
+ ASSERT_EQ(0, pthread_create(&thread, nullptr,
reinterpret_cast<void* (*)(void*)>(PIMutexWakeupHelper::thread_fn), this));
WaitUntilThreadSleep(child_tid);
@@ -2081,7 +2081,7 @@
TEST(pthread, pthread_mutex_owner_tid_limit) {
#if defined(__BIONIC__) && !defined(__LP64__)
FILE* fp = fopen("/proc/sys/kernel/pid_max", "r");
- ASSERT_TRUE(fp != NULL);
+ ASSERT_TRUE(fp != nullptr);
long pid_max;
ASSERT_EQ(1, fscanf(fp, "%ld", &pid_max));
fclose(fp);
@@ -2168,7 +2168,7 @@
};
pthread_t thread;
- ASSERT_EQ(0, pthread_create(&thread, NULL, ThreadFn, &thread_args));
+ ASSERT_EQ(0, pthread_create(&thread, nullptr, ThreadFn, &thread_args));
void* result;
ASSERT_EQ(0, pthread_join(thread, &result));
ASSERT_EQ(ETIMEDOUT, reinterpret_cast<intptr_t>(result));
@@ -2242,21 +2242,21 @@
StrictAlignmentAllocator allocator;
pthread_mutex_t* mutex = reinterpret_cast<pthread_mutex_t*>(
allocator.allocate(sizeof(pthread_mutex_t), 4));
- ASSERT_EQ(0, pthread_mutex_init(mutex, NULL));
+ ASSERT_EQ(0, pthread_mutex_init(mutex, nullptr));
ASSERT_EQ(0, pthread_mutex_lock(mutex));
ASSERT_EQ(0, pthread_mutex_unlock(mutex));
ASSERT_EQ(0, pthread_mutex_destroy(mutex));
pthread_cond_t* cond = reinterpret_cast<pthread_cond_t*>(
allocator.allocate(sizeof(pthread_cond_t), 4));
- ASSERT_EQ(0, pthread_cond_init(cond, NULL));
+ ASSERT_EQ(0, pthread_cond_init(cond, nullptr));
ASSERT_EQ(0, pthread_cond_signal(cond));
ASSERT_EQ(0, pthread_cond_broadcast(cond));
ASSERT_EQ(0, pthread_cond_destroy(cond));
pthread_rwlock_t* rwlock = reinterpret_cast<pthread_rwlock_t*>(
allocator.allocate(sizeof(pthread_rwlock_t), 4));
- ASSERT_EQ(0, pthread_rwlock_init(rwlock, NULL));
+ ASSERT_EQ(0, pthread_rwlock_init(rwlock, nullptr));
ASSERT_EQ(0, pthread_rwlock_rdlock(rwlock));
ASSERT_EQ(0, pthread_rwlock_unlock(rwlock));
ASSERT_EQ(0, pthread_rwlock_wrlock(rwlock));