[PATCH] D21803: [libcxxabi] Provide a fallback __cxa_thread_atexit() implementation

David Majnemer via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 28 15:30:57 PDT 2016


majnemer added a subscriber: majnemer.

================
Comment at: src/cxa_thread_atexit.cpp:36-47
@@ +35,14 @@
+  public:
+    DtorListHolder() {
+      pthread_key_create(&key_, run_dtors);
+    }
+
+    ~DtorListHolder() {
+      run_dtors(get());
+      pthread_key_delete(key_);
+    }
+
+    DtorList* get() {
+      return static_cast<DtorList*>(pthread_getspecific(key_));
+    }
+
----------------
What happens if `pthread_key_create` fails?

================
Comment at: src/cxa_thread_atexit.cpp:61-67
@@ -18,6 +60,9 @@
+_LIBCXXABI_FUNC_VIS int __cxa_thread_atexit(Dtor dtor, void *obj,
                                             void *dso_symbol) throw() {
-  extern int __cxa_thread_atexit_impl(void (*)(void *), void *, void *);
-  return __cxa_thread_atexit_impl(dtor, obj, dso_symbol);
-}
+  extern int __cxa_thread_atexit_impl(Dtor, void *, void *)
+    __attribute__((__weak__));
 
-#endif // HAVE__CXA_THREAD_ATEXIT_IMPL
+  if (__cxa_thread_atexit_impl) {
+    return __cxa_thread_atexit_impl(dtor, obj, dso_symbol);
+  } else {
+    static DtorListHolder dtors;
----------------
Is there a reason to use the weak symbol on non-Android platforms?


http://reviews.llvm.org/D21803





More information about the cfe-commits mailing list