bionic: libc: avoid -Wdeprecated-declarations via std::atomic_init
std::atomic_init is deprecated in C++20, and is slated for removal in C++26.
Replace the usage of std::atomic_init with std::atomic_store_explicit with
std::memory_ordering_relaxed.
Link: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0883r2.pdf
Link: https://github.com/llvm/llvm-project/commit/56aac567acfd696f54163e33d8df02dc2ad3a72e
Test: mmma bionic
Change-Id: Idf42aea193cfacf8dd7f8528560a396c6064468c
diff --git a/libc/bionic/pthread_create.cpp b/libc/bionic/pthread_create.cpp
index 54bfa20..3fa8ee6 100644
--- a/libc/bionic/pthread_create.cpp
+++ b/libc/bionic/pthread_create.cpp
@@ -159,11 +159,11 @@
int __init_thread(pthread_internal_t* thread) {
thread->cleanup_stack = nullptr;
- if (__predict_true((thread->attr.flags & PTHREAD_ATTR_FLAG_DETACHED) == 0)) {
- atomic_init(&thread->join_state, THREAD_NOT_JOINED);
- } else {
- atomic_init(&thread->join_state, THREAD_DETACHED);
+ ThreadJoinState state = THREAD_NOT_JOINED;
+ if (__predict_false((thread->attr.flags & PTHREAD_ATTR_FLAG_DETACHED) != 0)) {
+ state = THREAD_DETACHED;
}
+ atomic_store_explicit(&thread->join_state, state, memory_order_relaxed);
// Set the scheduling policy/priority of the thread if necessary.
bool need_set = true;