Commit cffa80b9 by Abseil Team Committed by Copybara-Service

absl: reformat Mutex-related files

Reformat Mutex-related files so that incremental formatting changes
don't distract during review of logical changes.
These files are subtle and any unnecessary diffs make reviews harder.

No changes besides running clang-format.

PiperOrigin-RevId: 541981737
Change-Id: I41cccb7a97158c78d17adaff6fe553c2c9c2b9ed
parent 5668c20e
...@@ -58,18 +58,19 @@ void AllocateThreadIdentityKey(ThreadIdentityReclaimerFunction reclaimer) { ...@@ -58,18 +58,19 @@ void AllocateThreadIdentityKey(ThreadIdentityReclaimerFunction reclaimer) {
// that protected visibility is unsupported. // that protected visibility is unsupported.
ABSL_CONST_INIT // Must come before __attribute__((visibility("protected"))) ABSL_CONST_INIT // Must come before __attribute__((visibility("protected")))
#if ABSL_HAVE_ATTRIBUTE(visibility) && !defined(__APPLE__) #if ABSL_HAVE_ATTRIBUTE(visibility) && !defined(__APPLE__)
__attribute__((visibility("protected"))) __attribute__((visibility("protected")))
#endif // ABSL_HAVE_ATTRIBUTE(visibility) && !defined(__APPLE__) #endif // ABSL_HAVE_ATTRIBUTE(visibility) && !defined(__APPLE__)
#if ABSL_PER_THREAD_TLS #if ABSL_PER_THREAD_TLS
// Prefer __thread to thread_local as benchmarks indicate it is a bit faster. // Prefer __thread to thread_local as benchmarks indicate it is a bit
ABSL_PER_THREAD_TLS_KEYWORD ThreadIdentity* thread_identity_ptr = nullptr; // faster.
ABSL_PER_THREAD_TLS_KEYWORD ThreadIdentity* thread_identity_ptr = nullptr;
#elif defined(ABSL_HAVE_THREAD_LOCAL) #elif defined(ABSL_HAVE_THREAD_LOCAL)
thread_local ThreadIdentity* thread_identity_ptr = nullptr; thread_local ThreadIdentity* thread_identity_ptr = nullptr;
#endif // ABSL_PER_THREAD_TLS #endif // ABSL_PER_THREAD_TLS
#endif // TLS or CPP11 #endif // TLS or CPP11
void SetCurrentThreadIdentity( void SetCurrentThreadIdentity(ThreadIdentity* identity,
ThreadIdentity* identity, ThreadIdentityReclaimerFunction reclaimer) { ThreadIdentityReclaimerFunction reclaimer) {
assert(CurrentThreadIdentityIfPresent() == nullptr); assert(CurrentThreadIdentityIfPresent() == nullptr);
// Associate our destructor. // Associate our destructor.
// NOTE: This call to pthread_setspecific is currently the only immovable // NOTE: This call to pthread_setspecific is currently the only immovable
...@@ -134,7 +135,7 @@ void ClearCurrentThreadIdentity() { ...@@ -134,7 +135,7 @@ void ClearCurrentThreadIdentity() {
ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_CPP11 ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_CPP11
thread_identity_ptr = nullptr; thread_identity_ptr = nullptr;
#elif ABSL_THREAD_IDENTITY_MODE == \ #elif ABSL_THREAD_IDENTITY_MODE == \
ABSL_THREAD_IDENTITY_MODE_USE_POSIX_SETSPECIFIC ABSL_THREAD_IDENTITY_MODE_USE_POSIX_SETSPECIFIC
// pthread_setspecific expected to clear value on destruction // pthread_setspecific expected to clear value on destruction
assert(CurrentThreadIdentityIfPresent() == nullptr); assert(CurrentThreadIdentityIfPresent() == nullptr);
#endif #endif
......
...@@ -62,8 +62,8 @@ struct PerThreadSynch { ...@@ -62,8 +62,8 @@ struct PerThreadSynch {
return reinterpret_cast<ThreadIdentity*>(this); return reinterpret_cast<ThreadIdentity*>(this);
} }
PerThreadSynch *next; // Circular waiter queue; initialized to 0. PerThreadSynch* next; // Circular waiter queue; initialized to 0.
PerThreadSynch *skip; // If non-zero, all entries in Mutex queue PerThreadSynch* skip; // If non-zero, all entries in Mutex queue
// up to and including "skip" have same // up to and including "skip" have same
// condition as this, and will be woken later // condition as this, and will be woken later
bool may_skip; // if false while on mutex queue, a mutex unlocker bool may_skip; // if false while on mutex queue, a mutex unlocker
...@@ -104,10 +104,7 @@ struct PerThreadSynch { ...@@ -104,10 +104,7 @@ struct PerThreadSynch {
// //
// Transitions from kAvailable to kQueued require no barrier, they // Transitions from kAvailable to kQueued require no barrier, they
// are externally ordered by the Mutex. // are externally ordered by the Mutex.
enum State { enum State { kAvailable, kQueued };
kAvailable,
kQueued
};
std::atomic<State> state; std::atomic<State> state;
// The wait parameters of the current wait. waitp is null if the // The wait parameters of the current wait. waitp is null if the
...@@ -122,14 +119,14 @@ struct PerThreadSynch { ...@@ -122,14 +119,14 @@ struct PerThreadSynch {
// pointer unchanged. // pointer unchanged.
SynchWaitParams* waitp; SynchWaitParams* waitp;
intptr_t readers; // Number of readers in mutex. intptr_t readers; // Number of readers in mutex.
// When priority will next be read (cycles). // When priority will next be read (cycles).
int64_t next_priority_read_cycles; int64_t next_priority_read_cycles;
// Locks held; used during deadlock detection. // Locks held; used during deadlock detection.
// Allocated in Synch_GetAllLocks() and freed in ReclaimThreadIdentity(). // Allocated in Synch_GetAllLocks() and freed in ReclaimThreadIdentity().
SynchLocksHeld *all_locks; SynchLocksHeld* all_locks;
}; };
// The instances of this class are allocated in NewThreadIdentity() with an // The instances of this class are allocated in NewThreadIdentity() with an
...@@ -220,7 +217,7 @@ void ClearCurrentThreadIdentity(); ...@@ -220,7 +217,7 @@ void ClearCurrentThreadIdentity();
#define ABSL_THREAD_IDENTITY_MODE ABSL_THREAD_IDENTITY_MODE_USE_CPP11 #define ABSL_THREAD_IDENTITY_MODE ABSL_THREAD_IDENTITY_MODE_USE_CPP11
#elif defined(__APPLE__) && defined(ABSL_HAVE_THREAD_LOCAL) #elif defined(__APPLE__) && defined(ABSL_HAVE_THREAD_LOCAL)
#define ABSL_THREAD_IDENTITY_MODE ABSL_THREAD_IDENTITY_MODE_USE_CPP11 #define ABSL_THREAD_IDENTITY_MODE ABSL_THREAD_IDENTITY_MODE_USE_CPP11
#elif ABSL_PER_THREAD_TLS && defined(__GOOGLE_GRTE_VERSION__) && \ #elif ABSL_PER_THREAD_TLS && defined(__GOOGLE_GRTE_VERSION__) && \
(__GOOGLE_GRTE_VERSION__ >= 20140228L) (__GOOGLE_GRTE_VERSION__ >= 20140228L)
// Support for async-safe TLS was specifically added in GRTEv4. It's not // Support for async-safe TLS was specifically added in GRTEv4. It's not
// present in the upstream eglibc. // present in the upstream eglibc.
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
#include <stdint.h> #include <stdint.h>
#include <new> #include <new>
// This file is a no-op if the required LowLevelAlloc support is missing. // This file is a no-op if the required LowLevelAlloc support is missing.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment