57 #ifndef ABSL_SYNCHRONIZATION_MUTEX_H_ 58 #define ABSL_SYNCHRONIZATION_MUTEX_H_ 77 #ifdef ABSL_INTERNAL_USE_NONPROD_MUTEX 78 #error ABSL_INTERNAL_USE_NONPROD_MUTEX cannot be directly set 79 #elif defined(ABSL_LOW_LEVEL_ALLOC_MISSING) 80 #define ABSL_INTERNAL_USE_NONPROD_MUTEX 1 81 #include "absl/synchronization/internal/mutex_nonprod.inc" 87 struct SynchWaitParams;
260 void WriterLock() EXCLUSIVE_LOCK_FUNCTION() { this->Lock(); }
265 return this->TryLock();
323 this->LockWhen(cond);
369 return this->LockWhenWithTimeout(cond, timeout);
389 return this->LockWhenWithDeadline(cond, deadline);
409 void EnableInvariantDebugging(
void (*
invariant)(
void *),
void *
arg);
418 void EnableDebugLog(
const char *
name);
427 void ForgetDeadlockInfo();
440 void AssertNotHeld()
const;
461 static void InternalAttemptToUseMutexInFatalSignalHandler();
464 #ifdef ABSL_INTERNAL_USE_NONPROD_MUTEX 467 synchronization_internal::MutexImpl *impl() {
return impl_.get(); }
469 synchronization_internal::SynchronizationStorage<
470 synchronization_internal::MutexImpl>
473 std::atomic<intptr_t>
mu_;
477 static inline void IncrementSynchSem(Mutex *mu,
479 static inline bool DecrementSynchSem(
486 bool LockSlowWithDeadline(MuHow how,
const Condition *cond,
489 void LockSlow(MuHow how,
const Condition *cond,
504 void Trans(MuHow how);
512 Mutex(
const Mutex&) =
delete;
513 Mutex& operator=(
const Mutex&) =
delete;
572 this->mu_->ReaderUnlock();
596 this->mu_->WriterUnlock();
648 Condition(
bool (*func)(
void *),
void *arg);
701 template <
typename T,
typename E = decltype(
702 static_cast<bool (T::*)() const
>(&T::operator()))>
704 :
Condition(obj, static_cast<
bool (T::*)() const>(&T::operator())) {}
722 typedef bool (*InternalFunctionType)(
void *
arg);
724 typedef bool (*InternalMethodCallerType)(
void *
arg,
725 InternalMethodType internal_method);
735 static bool CallVoidPtrFunction(
const Condition*);
736 template <
typename T>
static bool CastAndCallFunction(
const Condition* c);
737 template <
typename T>
static bool CastAndCallMethod(
const Condition* c);
787 void Wait(Mutex *mu);
819 bool WaitWithDeadline(Mutex *mu,
absl::Time deadline);
836 void EnableDebugLog(
const char *name);
839 #ifdef ABSL_INTERNAL_USE_NONPROD_MUTEX 840 synchronization_internal::CondVarImpl *impl() {
return impl_.get(); }
841 synchronization_internal::SynchronizationStorage<
842 synchronization_internal::CondVarImpl>
848 std::atomic<intptr_t>
cv_;
866 : mu_(mu) {
if (this->mu_ !=
nullptr) { this->mu_->Lock(); } }
868 if (this->mu_ !=
nullptr) { this->mu_->Unlock(); }
889 if (this->mu_ !=
nullptr) { this->mu_->Unlock(); }
902 #ifdef ABSL_INTERNAL_USE_NONPROD_MUTEX 916 template <
typename T>
918 typedef bool (T::*MemberType)();
919 MemberType rm =
reinterpret_cast<MemberType
>(c->
method_);
920 T *x =
static_cast<T *
>(c->
arg_);
925 template <
typename T>
927 typedef bool (*FuncType)(T *);
928 FuncType fn =
reinterpret_cast<FuncType
>(c->
function_);
929 T *x =
static_cast<T *
>(c->
arg_);
933 template <
typename T>
935 : eval_(&CastAndCallFunction<T>),
936 function_(reinterpret_cast<InternalFunctionType>(func)),
938 arg_(const_cast<void *>(static_cast<const void *>(arg))) {}
940 template <
typename T>
948 template <
typename T>
955 arg_(reinterpret_cast<void *>(const_cast<T *>(object))) {}
981 int64_t wait_cycles));
1011 ABSL_DEPRECATED(
"absl::RegisterSymbolizer() is deprecated and will be removed " 1012 "on or after 2023-05-01")
1054 #endif // ABSL_SYNCHRONIZATION_MUTEX_H_ static bool CastAndCallMethod(const Condition *c)
static const Condition kTrue
#define EXCLUSIVE_LOCK_FUNCTION(...)
bool WriterTryLock() EXCLUSIVE_TRYLOCK_FUNCTION(true)
ReaderMutexLock(Mutex *mu) SHARED_LOCK_FUNCTION(mu)
#define EXCLUSIVE_TRYLOCK_FUNCTION(...)
ABSL_DEPRECATED("absl::bit_cast type requirements were violated. Update the types being " "used such that they are the same size and are both TriviallyCopyable.") inline Dest bit_cast(const Source &source)
InternalMethodType method_
void WriterLockWhen(const Condition &cond) EXCLUSIVE_LOCK_FUNCTION()
bool WriterLockWhenWithDeadline(const Condition &cond, absl::Time deadline) EXCLUSIVE_LOCK_FUNCTION()
InternalFunctionType function_
WriterMutexLock(Mutex *mu) EXCLUSIVE_LOCK_FUNCTION(mu)
void WriterLock() EXCLUSIVE_LOCK_FUNCTION()
MutexLock(Mutex *mu) EXCLUSIVE_LOCK_FUNCTION(mu)
void RegisterMutexTracer(void(*fn)(const char *msg, const void *obj, int64_t wait_cycles))
#define SHARED_LOCK_FUNCTION(...)
void RegisterSymbolizer(bool(*)(const void *, char *, int))
#define SHARED_TRYLOCK_FUNCTION(...)
void(* invariant)(void *arg)
bool(* eval_)(const Condition *)
Mutex(const volatile Mutex *)
void RegisterMutexProfiler(void(*fn)(int64_t wait_timestamp))
std::atomic< intptr_t > mu_
void WriterUnlock() UNLOCK_FUNCTION()
const struct MuHowS * MuHow
#define UNLOCK_FUNCTION(...)
#define ASSERT_SHARED_LOCK(...)
static bool CastAndCallFunction(const Condition *c)
~MutexLock() UNLOCK_FUNCTION()
bool(Condition::* InternalMethodType)()
#define ABSL_TSAN_MUTEX_CREATE(...)
~MutexLockMaybe() UNLOCK_FUNCTION()
bool WriterLockWhenWithTimeout(const Condition &cond, absl::Duration timeout) EXCLUSIVE_LOCK_FUNCTION()
void SetMutexDeadlockDetectionMode(OnDeadlockCycle mode)
void EnableMutexInvariantDebugging(bool enabled)
void AbslInternalMutexYield()
~WriterMutexLock() UNLOCK_FUNCTION()
ReleasableMutexLock(Mutex *mu) EXCLUSIVE_LOCK_FUNCTION(mu)
MutexLockMaybe(Mutex *mu) EXCLUSIVE_LOCK_FUNCTION(mu)
void RegisterCondVarTracer(void(*fn)(const char *msg, const void *cv))
~ReaderMutexLock() UNLOCK_FUNCTION()
~ReleasableMutexLock() UNLOCK_FUNCTION()
#define ASSERT_EXCLUSIVE_LOCK(...)
#define ABSL_ATTRIBUTE_COLD
std::atomic< intptr_t > cv_