Change complex_thread_local to absl::call_once()
Change-Id: I3f6f4658fcdd43c3c3ef9211be13f635c98ffad2
diff --git a/aos/BUILD b/aos/BUILD
index 04d77f3..9962cea 100644
--- a/aos/BUILD
+++ b/aos/BUILD
@@ -232,7 +232,7 @@
visibility = ["//visibility:public"],
deps = [
"//aos:die",
- "//aos:once",
+ "@com_google_absl//absl/base",
],
)
diff --git a/aos/complex_thread_local.cc b/aos/complex_thread_local.cc
index f6a3135..70f3e82 100644
--- a/aos/complex_thread_local.cc
+++ b/aos/complex_thread_local.cc
@@ -3,7 +3,7 @@
#include <pthread.h>
#include "aos/die.h"
-#include "aos/once.h"
+#include "absl/base/call_once.h"
#define SIMPLE_CHECK(call) \
do { \
@@ -24,28 +24,33 @@
}
}
-pthread_key_t *CreateKey() {
- static pthread_key_t r;
- SIMPLE_CHECK(pthread_key_create(&r, ExecuteDestructorList));
- return &r;
+void CreateKey(pthread_key_t **r) {
+ static pthread_key_t hr;
+ SIMPLE_CHECK(pthread_key_create(&hr, ExecuteDestructorList));
+ *r = &hr;
}
-::aos::Once<pthread_key_t> key_once(CreateKey);
+absl::once_flag key_once;
+pthread_key_t *GetKey() {
+ static pthread_key_t *key = nullptr;
+ absl::call_once(key_once, CreateKey, &key);
+ return key;
+}
} // namespace
void ComplexThreadLocalDestructor::Add() {
static_assert(
::std::is_pod<ComplexThreadLocalDestructor>::value,
"ComplexThreadLocalDestructor might not be safe to pass through void*");
- pthread_key_t *const key = key_once.Get();
+ pthread_key_t *key = GetKey();
next = static_cast<ComplexThreadLocalDestructor *>(pthread_getspecific(*key));
SIMPLE_CHECK(pthread_setspecific(*key, this));
}
void ComplexThreadLocalDestructor::Remove() {
- pthread_key_t *const key = key_once.Get();
+ pthread_key_t *key = GetKey();
ComplexThreadLocalDestructor *previous = nullptr;
for (ComplexThreadLocalDestructor *c =
diff --git a/aos/logging/implementations.h b/aos/logging/implementations.h
index e8a2213..962982b 100644
--- a/aos/logging/implementations.h
+++ b/aos/logging/implementations.h
@@ -20,7 +20,6 @@
#include "aos/logging/sizes.h"
#include "aos/macros.h"
#include "aos/mutex/mutex.h"
-#include "aos/once.h"
#include "aos/time/time.h"
#include "aos/type_traits/type_traits.h"