diff --git a/libcxxabi/src/cxa_guard_impl.h b/libcxxabi/src/cxa_guard_impl.h --- a/libcxxabi/src/cxa_guard_impl.h +++ b/libcxxabi/src/cxa_guard_impl.h @@ -41,9 +41,9 @@ #include "include/atomic_support.h" #include #if defined(__has_include) -# if __has_include() -# include -# endif +#if __has_include() +#include +#endif #endif #include @@ -55,11 +55,11 @@ #endif #if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wtautological-pointer-compare" +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wtautological-pointer-compare" #elif defined(__GNUC__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Waddress" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Waddress" #endif // To make testing possible, this header is included from both cxa_guard.cpp @@ -74,12 +74,12 @@ // defined when including this file. Only `src/cxa_guard.cpp` should define // the former. #ifdef BUILDING_CXA_GUARD -# include "abort_message.h" -# define ABORT_WITH_MESSAGE(...) ::abort_message(__VA_ARGS__) +#include "abort_message.h" +#define ABORT_WITH_MESSAGE(...) ::abort_message(__VA_ARGS__) #elif defined(TESTING_CXA_GUARD) -# define ABORT_WITH_MESSAGE(...) ::abort() +#define ABORT_WITH_MESSAGE(...) ::abort() #else -# error "Either BUILDING_CXA_GUARD or TESTING_CXA_GUARD must be defined" +#error "Either BUILDING_CXA_GUARD or TESTING_CXA_GUARD must be defined" #endif #if __has_feature(thread_sanitizer) @@ -99,7 +99,7 @@ // Misc Utilities //===----------------------------------------------------------------------===// -template +template struct LazyValue { LazyValue() : is_init(false) {} @@ -110,7 +110,8 @@ } return value; } - private: + +private: T value; bool is_init = false; }; @@ -120,25 +121,25 @@ public: using MemoryOrder = std::__libcpp_atomic_order; - explicit AtomicInt(IntType *b) : b_(b) {} + explicit AtomicInt(IntType* b) : b_(b) {} AtomicInt(AtomicInt const&) = delete; AtomicInt& operator=(AtomicInt const&) = delete; - IntType load(MemoryOrder ord) { - return std::__libcpp_atomic_load(b_, ord); - } + IntType load(MemoryOrder ord) { return std::__libcpp_atomic_load(b_, ord); } void store(IntType val, MemoryOrder ord) { std::__libcpp_atomic_store(b_, val, ord); } IntType exchange(IntType new_val, MemoryOrder ord) { return std::__libcpp_atomic_exchange(b_, new_val, ord); } - bool compare_exchange(IntType *expected, IntType desired, MemoryOrder ord_success, MemoryOrder ord_failure) { - return std::__libcpp_atomic_compare_exchange(b_, expected, desired, ord_success, ord_failure); + bool compare_exchange(IntType* expected, IntType desired, + MemoryOrder ord_success, MemoryOrder ord_failure) { + return std::__libcpp_atomic_compare_exchange(b_, expected, desired, + ord_success, ord_failure); } private: - IntType *b_; + IntType* b_; }; //===----------------------------------------------------------------------===// @@ -160,7 +161,6 @@ constexpr uint32_t (*PlatformThreadID)() = nullptr; #endif - constexpr bool PlatformSupportsThreadID() { return +PlatformThreadID != nullptr; } @@ -244,7 +244,8 @@ if (*init_byte_address == COMPLETE_BIT) return INIT_IS_DONE; if (*init_byte_address & PENDING_BIT) - ABORT_WITH_MESSAGE("__cxa_guard_acquire detected recursive initialization"); + ABORT_WITH_MESSAGE( + "__cxa_guard_acquire detected recursive initialization"); *init_byte_address = PENDING_BIT; return INIT_IS_PENDING; } @@ -253,7 +254,6 @@ void abort_init_byte() { *init_byte_address = UNSET; } }; - //===----------------------------------------------------------------------===// // Global Mutex Implementation //===----------------------------------------------------------------------===// @@ -293,20 +293,19 @@ struct LibcppCondVar {}; #endif // !defined(_LIBCXXABI_HAS_NO_THREADS) - template struct InitByteGlobalMutex : GuardObject> { + GetThreadID>> { using BaseT = typename InitByteGlobalMutex::GuardObject; using BaseT::BaseT; - explicit InitByteGlobalMutex(uint32_t *g) - : BaseT(g), has_thread_id_support(false) {} - explicit InitByteGlobalMutex(uint64_t *g) - : BaseT(g), has_thread_id_support(PlatformSupportsThreadID()) {} + explicit InitByteGlobalMutex(uint32_t* g) + : BaseT(g), has_thread_id_support(false) {} + explicit InitByteGlobalMutex(uint64_t* g) + : BaseT(g), has_thread_id_support(PlatformSupportsThreadID()) {} public: AcquireResult acquire_init_byte() { @@ -314,7 +313,8 @@ // Check for possible recursive initialization. if (has_thread_id_support && (*init_byte_address & PENDING_BIT)) { if (*thread_id_address == current_thread_id.get()) - ABORT_WITH_MESSAGE("__cxa_guard_acquire detected recursive initialization"); + ABORT_WITH_MESSAGE( + "__cxa_guard_acquire detected recursive initialization"); } // Wait until the pending bit is not set. @@ -375,8 +375,7 @@ LockGuard(LockGuard const&) = delete; LockGuard& operator=(LockGuard const&) = delete; - explicit LockGuard(const char* calling_func) - : calling_func_(calling_func) { + explicit LockGuard(const char* calling_func) : calling_func_(calling_func) { if (global_mutex.lock()) ABORT_WITH_MESSAGE("%s failed to acquire mutex", calling_func_); } @@ -411,9 +410,7 @@ constexpr void (*PlatformFutexWake)(int*) = nullptr; #endif -constexpr bool PlatformSupportsFutex() { - return +PlatformFutexWait != nullptr; -} +constexpr bool PlatformSupportsFutex() { return +PlatformFutexWait != nullptr; } /// InitByteFutex - Manages initialization using atomics and the futex syscall /// for waiting and waking. @@ -424,16 +421,16 @@ using BaseT = typename InitByteFutex::GuardObject; /// ARM Constructor - explicit InitByteFutex(uint32_t *g) : BaseT(g), - init_byte(this->init_byte_address), - has_thread_id_support(this->thread_id_address && GetThreadIDArg), - thread_id(this->thread_id_address) {} + explicit InitByteFutex(uint32_t* g) + : BaseT(g), init_byte(this->init_byte_address), + has_thread_id_support(this->thread_id_address && GetThreadIDArg), + thread_id(this->thread_id_address) {} /// Itanium Constructor - explicit InitByteFutex(uint64_t *g) : BaseT(g), - init_byte(this->init_byte_address), - has_thread_id_support(this->thread_id_address && GetThreadIDArg), - thread_id(this->thread_id_address) {} + explicit InitByteFutex(uint64_t* g) + : BaseT(g), init_byte(this->init_byte_address), + has_thread_id_support(this->thread_id_address && GetThreadIDArg), + thread_id(this->thread_id_address) {} public: AcquireResult acquire_init_byte() { @@ -453,8 +450,10 @@ if (last_val & PENDING_BIT) { // Check for recursive initialization - if (has_thread_id_support && thread_id.load(std::_AO_Relaxed) == current_thread_id.get()) { - ABORT_WITH_MESSAGE("__cxa_guard_acquire detected recursive initialization"); + if (has_thread_id_support && + thread_id.load(std::_AO_Relaxed) == current_thread_id.get()) { + ABORT_WITH_MESSAGE( + "__cxa_guard_acquire detected recursive initialization"); } if ((last_val & WAITING_BIT) == 0) { @@ -490,7 +489,7 @@ if (has_thread_id_support) thread_id.store(0, std::_AO_Relaxed); - uint8_t old = init_byte.exchange(0, std::_AO_Acq_Rel); + uint8_t old = init_byte.exchange(UNSET, std::_AO_Acq_Rel); if (old & WAITING_BIT) wake_all(); } @@ -536,11 +535,7 @@ template _LIBCPP_SAFE_STATIC T GlobalStatic::instance = {}; -enum class Implementation { - NoThreads, - GlobalLock, - Futex -}; +enum class Implementation { NoThreads, GlobalLock, Futex }; template struct SelectImplementation; @@ -571,11 +566,12 @@ #elif defined(_LIBCXXABI_USE_FUTEX) Implementation::Futex; #else - Implementation::GlobalLock; + Implementation::GlobalLock; #endif -static_assert(CurrentImplementation != Implementation::Futex - || PlatformSupportsFutex(), "Futex selected but not supported"); +static_assert(CurrentImplementation != Implementation::Futex || + PlatformSupportsFutex(), + "Futex selected but not supported"); using SelectedImplementation = SelectImplementation::type; @@ -584,9 +580,9 @@ } // end namespace __cxxabiv1 #if defined(__clang__) -# pragma clang diagnostic pop +#pragma clang diagnostic pop #elif defined(__GNUC__) -# pragma GCC diagnostic pop +#pragma GCC diagnostic pop #endif #endif // LIBCXXABI_SRC_INCLUDE_CXA_GUARD_IMPL_H