mirror of
https://github.com/abseil/abseil-cpp.git
synced 2026-06-04 12:07:05 +08:00
Inline internal usages of pointerful SpinLockHolder/MutexLock.
PiperOrigin-RevId: 789441157 Change-Id: I2ed5d12f4b9725edbe3fd6cf629a0563a2f2d739
This commit is contained in:
committed by
Copybara-Service
parent
2e99bf25d4
commit
0f1abc9b73
@@ -239,6 +239,7 @@ class ABSL_SCOPED_LOCKABLE [[nodiscard]] SpinLockHolder {
|
||||
: lock_(l) {
|
||||
l.lock();
|
||||
}
|
||||
ABSL_DEPRECATE_AND_INLINE()
|
||||
inline explicit SpinLockHolder(SpinLock* l) ABSL_EXCLUSIVE_LOCK_FUNCTION(l)
|
||||
: SpinLockHolder(*l) {}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ TEST(SysinfoTest, GetTID) {
|
||||
threads.push_back(std::thread([&]() {
|
||||
pid_t id = GetTID();
|
||||
{
|
||||
MutexLock lock(&mutex);
|
||||
MutexLock lock(mutex);
|
||||
ASSERT_TRUE(tids.find(id) == tids.end());
|
||||
tids.insert(id);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ static void TestThreadIdentityCurrent(const void* assert_no_identity) {
|
||||
PerThreadSynch::kAlignment);
|
||||
EXPECT_EQ(identity, identity->per_thread_synch.thread_identity());
|
||||
|
||||
absl::base_internal::SpinLockHolder l(&map_lock);
|
||||
absl::base_internal::SpinLockHolder l(map_lock);
|
||||
num_identities_reused++;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ TEST(ThreadIdentityTest, BasicIdentityWorksThreaded) {
|
||||
// We should have recycled ThreadIdentity objects above; while (external)
|
||||
// library threads allocating their own identities may preclude some
|
||||
// reuse, we should have sufficient repetitions to exclude this.
|
||||
absl::base_internal::SpinLockHolder l(&map_lock);
|
||||
absl::base_internal::SpinLockHolder l(map_lock);
|
||||
EXPECT_LT(kNumThreads, num_identities_reused);
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ TEST(ThreadIdentityTest, ReusedThreadIdentityMutexTest) {
|
||||
threads.push_back(std::thread([&]() {
|
||||
for (int l = 0; l < kNumLockLoops; ++l) {
|
||||
for (int m = 0; m < kNumMutexes; ++m) {
|
||||
MutexLock lock(&mutexes[m]);
|
||||
MutexLock lock(mutexes[m]);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -132,12 +132,12 @@ static_assert(std::is_trivially_destructible<SpinLock>(), "");
|
||||
|
||||
TEST(SpinLock, StackNonCooperativeDisablesScheduling) {
|
||||
SpinLock spinlock(base_internal::SCHEDULE_KERNEL_ONLY);
|
||||
SpinLockHolder l(&spinlock);
|
||||
SpinLockHolder l(spinlock);
|
||||
EXPECT_FALSE(base_internal::SchedulingGuard::ReschedulingIsAllowed());
|
||||
}
|
||||
|
||||
TEST(SpinLock, StaticNonCooperativeDisablesScheduling) {
|
||||
SpinLockHolder l(&static_noncooperative_spinlock);
|
||||
SpinLockHolder l(static_noncooperative_spinlock);
|
||||
EXPECT_FALSE(base_internal::SchedulingGuard::ReschedulingIsAllowed());
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ TEST(HashtablezInfoTest, PrepareForSampling) {
|
||||
const size_t test_value_size = 13;
|
||||
|
||||
HashtablezInfo info;
|
||||
absl::MutexLock l(&info.init_mu);
|
||||
absl::MutexLock l(info.init_mu);
|
||||
info.PrepareForSampling(test_stride, test_element_size,
|
||||
/*key_size=*/test_key_size,
|
||||
/*value_size=*/test_value_size,
|
||||
@@ -148,7 +148,7 @@ TEST(HashtablezInfoTest, PrepareForSampling) {
|
||||
|
||||
TEST(HashtablezInfoTest, RecordStorageChanged) {
|
||||
HashtablezInfo info;
|
||||
absl::MutexLock l(&info.init_mu);
|
||||
absl::MutexLock l(info.init_mu);
|
||||
const int64_t test_stride = 21;
|
||||
const size_t test_element_size = 19;
|
||||
const size_t test_key_size = 17;
|
||||
@@ -168,7 +168,7 @@ TEST(HashtablezInfoTest, RecordStorageChanged) {
|
||||
|
||||
TEST(HashtablezInfoTest, RecordInsert) {
|
||||
HashtablezInfo info;
|
||||
absl::MutexLock l(&info.init_mu);
|
||||
absl::MutexLock l(info.init_mu);
|
||||
const int64_t test_stride = 25;
|
||||
const size_t test_element_size = 23;
|
||||
const size_t test_key_size = 21;
|
||||
@@ -203,7 +203,7 @@ TEST(HashtablezInfoTest, RecordErase) {
|
||||
const size_t test_value_size = 25;
|
||||
|
||||
HashtablezInfo info;
|
||||
absl::MutexLock l(&info.init_mu);
|
||||
absl::MutexLock l(info.init_mu);
|
||||
info.PrepareForSampling(test_stride, test_element_size,
|
||||
/*key_size=*/test_key_size,
|
||||
/*value_size=*/test_value_size,
|
||||
@@ -227,7 +227,7 @@ TEST(HashtablezInfoTest, RecordRehash) {
|
||||
const size_t test_key_size = 29;
|
||||
const size_t test_value_size = 27;
|
||||
HashtablezInfo info;
|
||||
absl::MutexLock l(&info.init_mu);
|
||||
absl::MutexLock l(info.init_mu);
|
||||
info.PrepareForSampling(test_stride, test_element_size,
|
||||
/*key_size=*/test_key_size,
|
||||
/*value_size=*/test_value_size,
|
||||
@@ -259,7 +259,7 @@ TEST(HashtablezInfoTest, RecordRehash) {
|
||||
|
||||
TEST(HashtablezInfoTest, RecordReservation) {
|
||||
HashtablezInfo info;
|
||||
absl::MutexLock l(&info.init_mu);
|
||||
absl::MutexLock l(info.init_mu);
|
||||
const int64_t test_stride = 35;
|
||||
const size_t test_element_size = 33;
|
||||
const size_t test_key_size = 31;
|
||||
|
||||
@@ -88,9 +88,9 @@ class MutexRelock {
|
||||
// we move the memory to the freelist where it lives indefinitely, so it can
|
||||
// still be safely accessed. This also prevents leak checkers from complaining
|
||||
// about the leaked memory that can no longer be accessed through any pointer.
|
||||
absl::Mutex* FreelistMutex() {
|
||||
absl::Mutex& FreelistMutex() {
|
||||
static absl::NoDestructor<absl::Mutex> mutex;
|
||||
return mutex.get();
|
||||
return *mutex;
|
||||
}
|
||||
ABSL_CONST_INIT std::vector<void*>* s_freelist ABSL_GUARDED_BY(FreelistMutex())
|
||||
ABSL_PT_GUARDED_BY(FreelistMutex()) = nullptr;
|
||||
@@ -248,12 +248,12 @@ void FlagImpl::Init() {
|
||||
seq_lock_.MarkInitialized();
|
||||
}
|
||||
|
||||
absl::Mutex* FlagImpl::DataGuard() const {
|
||||
absl::Mutex& FlagImpl::DataGuard() const {
|
||||
absl::call_once(const_cast<FlagImpl*>(this)->init_control_, &FlagImpl::Init,
|
||||
const_cast<FlagImpl*>(this));
|
||||
|
||||
// data_guard_ is initialized inside Init.
|
||||
return reinterpret_cast<absl::Mutex*>(&data_guard_);
|
||||
return *reinterpret_cast<absl::Mutex*>(&data_guard_);
|
||||
}
|
||||
|
||||
void FlagImpl::AssertValidType(FlagFastTypeId rhs_type_id,
|
||||
@@ -375,7 +375,7 @@ std::string FlagImpl::DefaultValue() const {
|
||||
}
|
||||
|
||||
std::string FlagImpl::CurrentValue() const {
|
||||
auto* guard = DataGuard(); // Make sure flag initialized
|
||||
auto& guard = DataGuard(); // Make sure flag initialized
|
||||
switch (ValueStorageKind()) {
|
||||
case FlagValueStorageKind::kValueAndInitBit:
|
||||
case FlagValueStorageKind::kOneWordAtomic: {
|
||||
@@ -429,8 +429,8 @@ void FlagImpl::InvokeCallback() const {
|
||||
// and it also can be different by the time the callback invocation is
|
||||
// completed. Requires that *primary_lock be held in exclusive mode; it may be
|
||||
// released and reacquired by the implementation.
|
||||
MutexRelock relock(*DataGuard());
|
||||
absl::MutexLock lock(&callback_->guard);
|
||||
MutexRelock relock(DataGuard());
|
||||
absl::MutexLock lock(callback_->guard);
|
||||
cb();
|
||||
}
|
||||
|
||||
@@ -535,7 +535,7 @@ std::unique_ptr<void, DynValueDeleter> FlagImpl::TryParse(
|
||||
}
|
||||
|
||||
void FlagImpl::Read(void* dst) const {
|
||||
auto* guard = DataGuard(); // Make sure flag initialized
|
||||
auto& guard = DataGuard(); // Make sure flag initialized
|
||||
switch (ValueStorageKind()) {
|
||||
case FlagValueStorageKind::kValueAndInitBit:
|
||||
case FlagValueStorageKind::kOneWordAtomic: {
|
||||
@@ -567,14 +567,14 @@ void FlagImpl::Read(void* dst) const {
|
||||
int64_t FlagImpl::ReadOneWord() const {
|
||||
assert(ValueStorageKind() == FlagValueStorageKind::kOneWordAtomic ||
|
||||
ValueStorageKind() == FlagValueStorageKind::kValueAndInitBit);
|
||||
auto* guard = DataGuard(); // Make sure flag initialized
|
||||
auto& guard = DataGuard(); // Make sure flag initialized
|
||||
(void)guard;
|
||||
return OneWordValue().load(std::memory_order_acquire);
|
||||
}
|
||||
|
||||
bool FlagImpl::ReadOneBool() const {
|
||||
assert(ValueStorageKind() == FlagValueStorageKind::kValueAndInitBit);
|
||||
auto* guard = DataGuard(); // Make sure flag initialized
|
||||
auto& guard = DataGuard(); // Make sure flag initialized
|
||||
(void)guard;
|
||||
return absl::bit_cast<FlagValueAndInitBit<bool>>(
|
||||
OneWordValue().load(std::memory_order_acquire))
|
||||
|
||||
@@ -601,17 +601,17 @@ class FlagImpl final : public CommandLineFlag {
|
||||
data_guard_{} {}
|
||||
|
||||
// Constant access methods
|
||||
int64_t ReadOneWord() const ABSL_LOCKS_EXCLUDED(*DataGuard());
|
||||
bool ReadOneBool() const ABSL_LOCKS_EXCLUDED(*DataGuard());
|
||||
void Read(void* dst) const override ABSL_LOCKS_EXCLUDED(*DataGuard());
|
||||
void Read(bool* value) const ABSL_LOCKS_EXCLUDED(*DataGuard()) {
|
||||
int64_t ReadOneWord() const ABSL_LOCKS_EXCLUDED(DataGuard());
|
||||
bool ReadOneBool() const ABSL_LOCKS_EXCLUDED(DataGuard());
|
||||
void Read(void* dst) const override ABSL_LOCKS_EXCLUDED(DataGuard());
|
||||
void Read(bool* value) const ABSL_LOCKS_EXCLUDED(DataGuard()) {
|
||||
*value = ReadOneBool();
|
||||
}
|
||||
template <typename T,
|
||||
absl::enable_if_t<flags_internal::StorageKind<T>() ==
|
||||
FlagValueStorageKind::kOneWordAtomic,
|
||||
int> = 0>
|
||||
void Read(T* value) const ABSL_LOCKS_EXCLUDED(*DataGuard()) {
|
||||
void Read(T* value) const ABSL_LOCKS_EXCLUDED(DataGuard()) {
|
||||
int64_t v = ReadOneWord();
|
||||
std::memcpy(value, static_cast<const void*>(&v), sizeof(T));
|
||||
}
|
||||
@@ -619,17 +619,17 @@ class FlagImpl final : public CommandLineFlag {
|
||||
typename std::enable_if<flags_internal::StorageKind<T>() ==
|
||||
FlagValueStorageKind::kValueAndInitBit,
|
||||
int>::type = 0>
|
||||
void Read(T* value) const ABSL_LOCKS_EXCLUDED(*DataGuard()) {
|
||||
void Read(T* value) const ABSL_LOCKS_EXCLUDED(DataGuard()) {
|
||||
*value = absl::bit_cast<FlagValueAndInitBit<T>>(ReadOneWord()).value;
|
||||
}
|
||||
|
||||
// Mutating access methods
|
||||
void Write(const void* src) ABSL_LOCKS_EXCLUDED(*DataGuard());
|
||||
void Write(const void* src) ABSL_LOCKS_EXCLUDED(DataGuard());
|
||||
|
||||
// Interfaces to operate on callbacks.
|
||||
void SetCallback(const FlagCallbackFunc mutation_callback)
|
||||
ABSL_LOCKS_EXCLUDED(*DataGuard());
|
||||
void InvokeCallback() const ABSL_EXCLUSIVE_LOCKS_REQUIRED(*DataGuard());
|
||||
ABSL_LOCKS_EXCLUDED(DataGuard());
|
||||
void InvokeCallback() const ABSL_EXCLUSIVE_LOCKS_REQUIRED(DataGuard());
|
||||
|
||||
// Used in read/write operations to validate source/target has correct type.
|
||||
// For example if flag is declared as absl::Flag<int> FLAGS_foo, a call to
|
||||
@@ -646,11 +646,11 @@ class FlagImpl final : public CommandLineFlag {
|
||||
friend class FlagState;
|
||||
|
||||
// Ensures that `data_guard_` is initialized and returns it.
|
||||
absl::Mutex* DataGuard() const
|
||||
absl::Mutex& DataGuard() const
|
||||
ABSL_LOCK_RETURNED(reinterpret_cast<absl::Mutex*>(data_guard_));
|
||||
// Returns heap allocated value of type T initialized with default value.
|
||||
std::unique_ptr<void, DynValueDeleter> MakeInitValue() const
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(*DataGuard());
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(DataGuard());
|
||||
// Flag initialization called via absl::call_once.
|
||||
void Init();
|
||||
|
||||
@@ -676,16 +676,15 @@ class FlagImpl final : public CommandLineFlag {
|
||||
// returns new value. Otherwise returns nullptr.
|
||||
std::unique_ptr<void, DynValueDeleter> TryParse(absl::string_view value,
|
||||
std::string& err) const
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(*DataGuard());
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(DataGuard());
|
||||
// Stores the flag value based on the pointer to the source.
|
||||
void StoreValue(const void* src, ValueSource source)
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(*DataGuard());
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(DataGuard());
|
||||
|
||||
// Copy the flag data, protected by `seq_lock_` into `dst`.
|
||||
//
|
||||
// REQUIRES: ValueStorageKind() == kSequenceLocked.
|
||||
void ReadSequenceLockedData(void* dst) const
|
||||
ABSL_LOCKS_EXCLUDED(*DataGuard());
|
||||
void ReadSequenceLockedData(void* dst) const ABSL_LOCKS_EXCLUDED(DataGuard());
|
||||
|
||||
FlagHelpKind HelpSourceKind() const {
|
||||
return static_cast<FlagHelpKind>(help_source_kind_);
|
||||
@@ -694,7 +693,7 @@ class FlagImpl final : public CommandLineFlag {
|
||||
return static_cast<FlagValueStorageKind>(value_storage_kind_);
|
||||
}
|
||||
FlagDefaultKind DefaultKind() const
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(*DataGuard()) {
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(DataGuard()) {
|
||||
return static_cast<FlagDefaultKind>(def_kind_);
|
||||
}
|
||||
|
||||
@@ -705,30 +704,30 @@ class FlagImpl final : public CommandLineFlag {
|
||||
std::string Help() const override;
|
||||
FlagFastTypeId TypeId() const override;
|
||||
bool IsSpecifiedOnCommandLine() const override
|
||||
ABSL_LOCKS_EXCLUDED(*DataGuard());
|
||||
std::string DefaultValue() const override ABSL_LOCKS_EXCLUDED(*DataGuard());
|
||||
std::string CurrentValue() const override ABSL_LOCKS_EXCLUDED(*DataGuard());
|
||||
ABSL_LOCKS_EXCLUDED(DataGuard());
|
||||
std::string DefaultValue() const override ABSL_LOCKS_EXCLUDED(DataGuard());
|
||||
std::string CurrentValue() const override ABSL_LOCKS_EXCLUDED(DataGuard());
|
||||
bool ValidateInputValue(absl::string_view value) const override
|
||||
ABSL_LOCKS_EXCLUDED(*DataGuard());
|
||||
ABSL_LOCKS_EXCLUDED(DataGuard());
|
||||
void CheckDefaultValueParsingRoundtrip() const override
|
||||
ABSL_LOCKS_EXCLUDED(*DataGuard());
|
||||
ABSL_LOCKS_EXCLUDED(DataGuard());
|
||||
|
||||
int64_t ModificationCount() const ABSL_EXCLUSIVE_LOCKS_REQUIRED(*DataGuard());
|
||||
int64_t ModificationCount() const ABSL_EXCLUSIVE_LOCKS_REQUIRED(DataGuard());
|
||||
|
||||
// Interfaces to save and restore flags to/from persistent state.
|
||||
// Returns current flag state or nullptr if flag does not support
|
||||
// saving and restoring a state.
|
||||
std::unique_ptr<FlagStateInterface> SaveState() override
|
||||
ABSL_LOCKS_EXCLUDED(*DataGuard());
|
||||
ABSL_LOCKS_EXCLUDED(DataGuard());
|
||||
|
||||
// Restores the flag state to the supplied state object. If there is
|
||||
// nothing to restore returns false. Otherwise returns true.
|
||||
bool RestoreState(const FlagState& flag_state)
|
||||
ABSL_LOCKS_EXCLUDED(*DataGuard());
|
||||
ABSL_LOCKS_EXCLUDED(DataGuard());
|
||||
|
||||
bool ParseFrom(absl::string_view value, FlagSettingMode set_mode,
|
||||
ValueSource source, std::string& error) override
|
||||
ABSL_LOCKS_EXCLUDED(*DataGuard());
|
||||
ABSL_LOCKS_EXCLUDED(DataGuard());
|
||||
|
||||
// Immutable flag's state.
|
||||
|
||||
@@ -758,9 +757,9 @@ class FlagImpl final : public CommandLineFlag {
|
||||
// locks.
|
||||
uint8_t def_kind_ : 2;
|
||||
// Has this flag's value been modified?
|
||||
bool modified_ : 1 ABSL_GUARDED_BY(*DataGuard());
|
||||
bool modified_ : 1 ABSL_GUARDED_BY(DataGuard());
|
||||
// Has this flag been specified on command line.
|
||||
bool on_command_line_ : 1 ABSL_GUARDED_BY(*DataGuard());
|
||||
bool on_command_line_ : 1 ABSL_GUARDED_BY(DataGuard());
|
||||
|
||||
// Unique tag for absl::call_once call to initialize this flag.
|
||||
absl::once_flag init_control_;
|
||||
@@ -769,7 +768,7 @@ class FlagImpl final : public CommandLineFlag {
|
||||
flags_internal::SequenceLock seq_lock_;
|
||||
|
||||
// Optional flag's callback and absl::Mutex to guard the invocations.
|
||||
FlagCallback* callback_ ABSL_GUARDED_BY(*DataGuard());
|
||||
FlagCallback* callback_ ABSL_GUARDED_BY(DataGuard());
|
||||
// Either a pointer to the function generating the default value based on the
|
||||
// value specified in ABSL_FLAG or pointer to the dynamically set default
|
||||
// value via SetCommandLineOptionWithMode. def_kind_ is used to distinguish
|
||||
|
||||
@@ -29,9 +29,9 @@ namespace absl {
|
||||
ABSL_NAMESPACE_BEGIN
|
||||
namespace flags_internal {
|
||||
|
||||
static absl::Mutex* ProgramNameMutex() {
|
||||
static absl::Mutex& ProgramNameMutex() {
|
||||
static absl::NoDestructor<absl::Mutex> mutex;
|
||||
return mutex.get();
|
||||
return *mutex;
|
||||
}
|
||||
ABSL_CONST_INIT static std::string* program_name ABSL_GUARDED_BY(
|
||||
ProgramNameMutex()) ABSL_PT_GUARDED_BY(ProgramNameMutex()) = nullptr;
|
||||
|
||||
@@ -434,9 +434,9 @@ HelpMode HandleUsageFlags(std::ostream& out,
|
||||
|
||||
namespace {
|
||||
|
||||
absl::Mutex* HelpAttributesMutex() {
|
||||
absl::Mutex& HelpAttributesMutex() {
|
||||
static absl::NoDestructor<absl::Mutex> mutex;
|
||||
return mutex.get();
|
||||
return *mutex;
|
||||
}
|
||||
ABSL_CONST_INIT std::string* match_substr ABSL_GUARDED_BY(HelpAttributesMutex())
|
||||
ABSL_PT_GUARDED_BY(HelpAttributesMutex()) = nullptr;
|
||||
|
||||
@@ -64,9 +64,9 @@ ABSL_NAMESPACE_BEGIN
|
||||
namespace flags_internal {
|
||||
namespace {
|
||||
|
||||
absl::Mutex* ProcessingChecksMutex() {
|
||||
absl::Mutex& ProcessingChecksMutex() {
|
||||
static absl::NoDestructor<absl::Mutex> mutex;
|
||||
return mutex.get();
|
||||
return *mutex;
|
||||
}
|
||||
|
||||
ABSL_CONST_INIT bool flagfile_needs_processing
|
||||
@@ -76,9 +76,9 @@ ABSL_CONST_INIT bool fromenv_needs_processing
|
||||
ABSL_CONST_INIT bool tryfromenv_needs_processing
|
||||
ABSL_GUARDED_BY(ProcessingChecksMutex()) = false;
|
||||
|
||||
absl::Mutex* SpecifiedFlagsMutex() {
|
||||
absl::Mutex& SpecifiedFlagsMutex() {
|
||||
static absl::NoDestructor<absl::Mutex> mutex;
|
||||
return mutex.get();
|
||||
return *mutex;
|
||||
}
|
||||
|
||||
ABSL_CONST_INIT std::vector<const CommandLineFlag*>* specified_flags
|
||||
|
||||
@@ -40,7 +40,7 @@ ABSL_CONST_INIT std::string* program_usage_message
|
||||
// --------------------------------------------------------------------
|
||||
// Sets the "usage" message to be used by help reporting routines.
|
||||
void SetProgramUsageMessage(absl::string_view new_usage_message) {
|
||||
absl::MutexLock l(&flags_internal::usage_message_guard);
|
||||
absl::MutexLock l(flags_internal::usage_message_guard);
|
||||
|
||||
if (flags_internal::program_usage_message != nullptr) {
|
||||
ABSL_INTERNAL_LOG(FATAL, "SetProgramUsageMessage() called twice.");
|
||||
@@ -55,7 +55,7 @@ void SetProgramUsageMessage(absl::string_view new_usage_message) {
|
||||
// Note: We able to return string_view here only because calling
|
||||
// SetProgramUsageMessage twice is prohibited.
|
||||
absl::string_view ProgramUsageMessage() {
|
||||
absl::MutexLock l(&flags_internal::usage_message_guard);
|
||||
absl::MutexLock l(flags_internal::usage_message_guard);
|
||||
|
||||
return flags_internal::program_usage_message != nullptr
|
||||
? absl::string_view(*flags_internal::program_usage_message)
|
||||
|
||||
@@ -105,9 +105,9 @@ std::string NormalizeFilename(absl::string_view filename) {
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
absl::Mutex* CustomUsageConfigMutex() {
|
||||
absl::Mutex& CustomUsageConfigMutex() {
|
||||
static absl::NoDestructor<absl::Mutex> mutex;
|
||||
return mutex.get();
|
||||
return *mutex;
|
||||
}
|
||||
ABSL_CONST_INIT FlagsUsageConfig* custom_usage_config
|
||||
ABSL_GUARDED_BY(CustomUsageConfigMutex())
|
||||
|
||||
@@ -192,7 +192,7 @@ class GlobalLogSinkSet final {
|
||||
absl::log_internal::WriteToStderr(
|
||||
entry.text_message_with_prefix_and_newline(), entry.log_severity());
|
||||
} else {
|
||||
absl::ReaderMutexLock global_sinks_lock(&guard_);
|
||||
absl::ReaderMutexLock global_sinks_lock(guard_);
|
||||
ThreadIsLoggingStatus() = true;
|
||||
// Ensure the "thread is logging" status is reverted upon leaving the
|
||||
// scope even in case of exceptions.
|
||||
@@ -205,7 +205,7 @@ class GlobalLogSinkSet final {
|
||||
|
||||
void AddLogSink(absl::LogSink* sink) ABSL_LOCKS_EXCLUDED(guard_) {
|
||||
{
|
||||
absl::WriterMutexLock global_sinks_lock(&guard_);
|
||||
absl::WriterMutexLock global_sinks_lock(guard_);
|
||||
auto pos = std::find(sinks_.begin(), sinks_.end(), sink);
|
||||
if (pos == sinks_.end()) {
|
||||
sinks_.push_back(sink);
|
||||
@@ -217,7 +217,7 @@ class GlobalLogSinkSet final {
|
||||
|
||||
void RemoveLogSink(absl::LogSink* sink) ABSL_LOCKS_EXCLUDED(guard_) {
|
||||
{
|
||||
absl::WriterMutexLock global_sinks_lock(&guard_);
|
||||
absl::WriterMutexLock global_sinks_lock(guard_);
|
||||
auto pos = std::find(sinks_.begin(), sinks_.end(), sink);
|
||||
if (pos != sinks_.end()) {
|
||||
sinks_.erase(pos);
|
||||
@@ -235,7 +235,7 @@ class GlobalLogSinkSet final {
|
||||
guard_.AssertReaderHeld();
|
||||
FlushLogSinksLocked();
|
||||
} else {
|
||||
absl::ReaderMutexLock global_sinks_lock(&guard_);
|
||||
absl::ReaderMutexLock global_sinks_lock(guard_);
|
||||
// In case if LogSink::Flush overload decides to log
|
||||
ThreadIsLoggingStatus() = true;
|
||||
// Ensure the "thread is logging" status is reverted upon leaving the
|
||||
|
||||
@@ -94,12 +94,12 @@ ABSL_CONST_INIT absl::base_internal::SpinLock mutex(
|
||||
|
||||
// `GetUpdateSitesMutex()` serializes updates to all of the sites (i.e. those in
|
||||
// `site_list_head`) themselves.
|
||||
absl::Mutex* GetUpdateSitesMutex() {
|
||||
absl::Mutex& GetUpdateSitesMutex() {
|
||||
// Chromium requires no global destructors, so we can't use the
|
||||
// absl::kConstInit idiom since absl::Mutex as a non-trivial destructor.
|
||||
static absl::NoDestructor<absl::Mutex> update_sites_mutex ABSL_ACQUIRED_AFTER(
|
||||
mutex);
|
||||
return update_sites_mutex.get();
|
||||
return *update_sites_mutex;
|
||||
}
|
||||
|
||||
ABSL_CONST_INIT int global_v ABSL_GUARDED_BY(mutex) = 0;
|
||||
@@ -222,7 +222,7 @@ int PrependVModuleLocked(absl::string_view module_pattern, int log_level)
|
||||
} // namespace
|
||||
|
||||
int VLogLevel(absl::string_view file) ABSL_LOCKS_EXCLUDED(mutex) {
|
||||
absl::base_internal::SpinLockHolder l(&mutex);
|
||||
absl::base_internal::SpinLockHolder l(mutex);
|
||||
return VLogLevel(file, vmodule_info, global_v);
|
||||
}
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ SampleRecorder<T>::SetDisposeCallback(DisposeCallback f) {
|
||||
template <typename T>
|
||||
SampleRecorder<T>::SampleRecorder()
|
||||
: dropped_samples_(0), size_estimate_(0), all_(nullptr), dispose_(nullptr) {
|
||||
absl::MutexLock l(&graveyard_.init_mu);
|
||||
absl::MutexLock l(graveyard_.init_mu);
|
||||
graveyard_.dead = &graveyard_;
|
||||
}
|
||||
|
||||
@@ -159,8 +159,8 @@ void SampleRecorder<T>::PushDead(T* sample) {
|
||||
dispose(*sample);
|
||||
}
|
||||
|
||||
absl::MutexLock graveyard_lock(&graveyard_.init_mu);
|
||||
absl::MutexLock sample_lock(&sample->init_mu);
|
||||
absl::MutexLock graveyard_lock(graveyard_.init_mu);
|
||||
absl::MutexLock sample_lock(sample->init_mu);
|
||||
sample->dead = graveyard_.dead;
|
||||
graveyard_.dead = sample;
|
||||
}
|
||||
@@ -168,7 +168,7 @@ void SampleRecorder<T>::PushDead(T* sample) {
|
||||
template <typename T>
|
||||
template <typename... Targs>
|
||||
T* SampleRecorder<T>::PopDead(Targs... args) {
|
||||
absl::MutexLock graveyard_lock(&graveyard_.init_mu);
|
||||
absl::MutexLock graveyard_lock(graveyard_.init_mu);
|
||||
|
||||
// The list is circular, so eventually it collapses down to
|
||||
// graveyard_.dead == &graveyard_
|
||||
@@ -176,7 +176,7 @@ T* SampleRecorder<T>::PopDead(Targs... args) {
|
||||
T* sample = graveyard_.dead;
|
||||
if (sample == &graveyard_) return nullptr;
|
||||
|
||||
absl::MutexLock sample_lock(&sample->init_mu);
|
||||
absl::MutexLock sample_lock(sample->init_mu);
|
||||
graveyard_.dead = sample->dead;
|
||||
sample->dead = nullptr;
|
||||
sample->PrepareForSampling(std::forward<Targs>(args)...);
|
||||
@@ -198,7 +198,7 @@ T* SampleRecorder<T>::Register(Targs&&... args) {
|
||||
// Resurrection failed. Hire a new warlock.
|
||||
sample = new T();
|
||||
{
|
||||
absl::MutexLock sample_lock(&sample->init_mu);
|
||||
absl::MutexLock sample_lock(sample->init_mu);
|
||||
// If flag initialization happens to occur (perhaps in another thread)
|
||||
// while in this block, it will lock `graveyard_` which is usually always
|
||||
// locked before any sample. This will appear as a lock inversion.
|
||||
@@ -226,7 +226,7 @@ size_t SampleRecorder<T>::Iterate(
|
||||
const std::function<void(const T& stack)>& f) {
|
||||
T* s = all_.load(std::memory_order_acquire);
|
||||
while (s != nullptr) {
|
||||
absl::MutexLock l(&s->init_mu);
|
||||
absl::MutexLock l(s->init_mu);
|
||||
if (s->dead == nullptr) {
|
||||
f(*s);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ class alignas(std::max(size_t{ABSL_CACHELINE_SIZE}, size_t{32}))
|
||||
RandenTraits::kCapacityBytes / sizeof(uint32_t);
|
||||
|
||||
void Init(absl::Span<const uint32_t> data) {
|
||||
SpinLockHolder l(&mu_); // Always uncontested.
|
||||
SpinLockHolder l(mu_); // Always uncontested.
|
||||
std::copy(data.begin(), data.end(), std::begin(state_));
|
||||
next_ = kState;
|
||||
}
|
||||
@@ -84,7 +84,7 @@ class alignas(std::max(size_t{ABSL_CACHELINE_SIZE}, size_t{32}))
|
||||
};
|
||||
|
||||
void RandenPoolEntry::Fill(uint8_t* out, size_t bytes) {
|
||||
SpinLockHolder l(&mu_);
|
||||
SpinLockHolder l(mu_);
|
||||
while (bytes > 0) {
|
||||
MaybeRefill();
|
||||
size_t remaining = available() * sizeof(state_[0]);
|
||||
|
||||
@@ -44,7 +44,7 @@ TEST(EntropyPoolTest, DistinctSequencesPerThread) {
|
||||
threads.emplace_back([&]() {
|
||||
std::vector<result_type> v(kValuesPerThread);
|
||||
GetEntropyFromRandenPool(v.data(), sizeof(result_type) * v.size());
|
||||
absl::MutexLock l(&mu);
|
||||
absl::MutexLock l(mu);
|
||||
data.push_back(std::move(v));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ TEST(NonsecureURBGBase, DistinctSequencesPerThread) {
|
||||
|
||||
std::vector<result_type> v(kValuesPerThread);
|
||||
std::generate(v.begin(), v.end(), [&]() { return gen(); });
|
||||
absl::MutexLock l(&mu);
|
||||
absl::MutexLock l(mu);
|
||||
data.push_back(std::move(v));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ static Queue& GlobalQueue() {
|
||||
CordzHandle::CordzHandle(bool is_snapshot) : is_snapshot_(is_snapshot) {
|
||||
Queue& global_queue = GlobalQueue();
|
||||
if (is_snapshot) {
|
||||
MutexLock lock(&global_queue.mutex);
|
||||
MutexLock lock(global_queue.mutex);
|
||||
CordzHandle* dq_tail = global_queue.dq_tail.load(std::memory_order_acquire);
|
||||
if (dq_tail != nullptr) {
|
||||
dq_prev_ = dq_tail;
|
||||
@@ -69,7 +69,7 @@ CordzHandle::~CordzHandle() {
|
||||
if (is_snapshot_) {
|
||||
std::vector<CordzHandle*> to_delete;
|
||||
{
|
||||
MutexLock lock(&global_queue.mutex);
|
||||
MutexLock lock(global_queue.mutex);
|
||||
CordzHandle* next = dq_next_;
|
||||
if (dq_prev_ == nullptr) {
|
||||
// We were head of the queue, delete every CordzHandle until we reach
|
||||
@@ -103,7 +103,7 @@ void CordzHandle::Delete(CordzHandle* handle) {
|
||||
if (handle) {
|
||||
Queue& queue = GlobalQueue();
|
||||
if (!handle->SafeToDelete()) {
|
||||
MutexLock lock(&queue.mutex);
|
||||
MutexLock lock(queue.mutex);
|
||||
CordzHandle* dq_tail = queue.dq_tail.load(std::memory_order_acquire);
|
||||
if (dq_tail != nullptr) {
|
||||
handle->dq_prev_ = dq_tail;
|
||||
@@ -119,7 +119,7 @@ void CordzHandle::Delete(CordzHandle* handle) {
|
||||
std::vector<const CordzHandle*> CordzHandle::DiagnosticsGetDeleteQueue() {
|
||||
std::vector<const CordzHandle*> handles;
|
||||
Queue& global_queue = GlobalQueue();
|
||||
MutexLock lock(&global_queue.mutex);
|
||||
MutexLock lock(global_queue.mutex);
|
||||
CordzHandle* dq_tail = global_queue.dq_tail.load(std::memory_order_acquire);
|
||||
for (const CordzHandle* p = dq_tail; p; p = p->dq_prev_) {
|
||||
handles.push_back(p);
|
||||
@@ -134,7 +134,7 @@ bool CordzHandle::DiagnosticsHandleIsSafeToInspect(
|
||||
if (handle->is_snapshot_) return false;
|
||||
bool snapshot_found = false;
|
||||
Queue& global_queue = GlobalQueue();
|
||||
MutexLock lock(&global_queue.mutex);
|
||||
MutexLock lock(global_queue.mutex);
|
||||
for (const CordzHandle* p = global_queue.dq_tail; p; p = p->dq_prev_) {
|
||||
if (p == handle) return !snapshot_found;
|
||||
if (p == this) snapshot_found = true;
|
||||
@@ -151,7 +151,7 @@ CordzHandle::DiagnosticsGetSafeToInspectDeletedHandles() {
|
||||
}
|
||||
|
||||
Queue& global_queue = GlobalQueue();
|
||||
MutexLock lock(&global_queue.mutex);
|
||||
MutexLock lock(global_queue.mutex);
|
||||
for (const CordzHandle* p = dq_next_; p != nullptr; p = p->dq_next_) {
|
||||
if (!p->is_snapshot()) {
|
||||
handles.push_back(p);
|
||||
|
||||
@@ -327,7 +327,7 @@ CordzInfo::~CordzInfo() {
|
||||
}
|
||||
|
||||
void CordzInfo::Track() {
|
||||
SpinLockHolder l(&list_->mutex);
|
||||
SpinLockHolder l(list_->mutex);
|
||||
|
||||
CordzInfo* const head = list_->head.load(std::memory_order_acquire);
|
||||
if (head != nullptr) {
|
||||
@@ -340,7 +340,7 @@ void CordzInfo::Track() {
|
||||
void CordzInfo::Untrack() {
|
||||
ODRCheck();
|
||||
{
|
||||
SpinLockHolder l(&list_->mutex);
|
||||
SpinLockHolder l(list_->mutex);
|
||||
|
||||
CordzInfo* const head = list_->head.load(std::memory_order_acquire);
|
||||
CordzInfo* const next = ci_next_.load(std::memory_order_acquire);
|
||||
@@ -370,7 +370,7 @@ void CordzInfo::Untrack() {
|
||||
|
||||
// We are likely part of a snapshot, extend the life of the CordRep
|
||||
{
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
if (rep_) CordRep::Ref(rep_);
|
||||
}
|
||||
CordzHandle::Delete(this);
|
||||
|
||||
@@ -290,7 +290,7 @@ inline void CordzInfo::SetCordRep(CordRep* rep) {
|
||||
inline void CordzInfo::UnsafeSetCordRep(CordRep* rep) { rep_ = rep; }
|
||||
|
||||
inline CordRep* CordzInfo::RefCordRep() const ABSL_LOCKS_EXCLUDED(mutex_) {
|
||||
MutexLock lock(&mutex_);
|
||||
MutexLock lock(mutex_);
|
||||
return rep_ ? CordRep::Ref(rep_) : nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ static bool IsZero(void *arg) {
|
||||
}
|
||||
|
||||
bool Barrier::Block() {
|
||||
MutexLock l(&this->lock_);
|
||||
MutexLock l(this->lock_);
|
||||
|
||||
this->num_to_block_--;
|
||||
if (this->num_to_block_ < 0) {
|
||||
|
||||
@@ -37,7 +37,7 @@ TEST(Barrier, SanityTest) {
|
||||
}
|
||||
|
||||
// Increment the counter.
|
||||
absl::MutexLock lock(&mutex);
|
||||
absl::MutexLock lock(mutex);
|
||||
++counter;
|
||||
};
|
||||
|
||||
@@ -57,7 +57,7 @@ TEST(Barrier, SanityTest) {
|
||||
// The counter should still be zero since no thread should have
|
||||
// been able to pass the barrier yet.
|
||||
{
|
||||
absl::MutexLock lock(&mutex);
|
||||
absl::MutexLock lock(mutex);
|
||||
EXPECT_EQ(counter, 0);
|
||||
}
|
||||
|
||||
@@ -70,6 +70,6 @@ TEST(Barrier, SanityTest) {
|
||||
}
|
||||
|
||||
// All threads should now have incremented the counter.
|
||||
absl::MutexLock lock(&mutex);
|
||||
absl::MutexLock lock(mutex);
|
||||
EXPECT_EQ(counter, kNumThreads);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ bool BlockingCounter::DecrementCount() {
|
||||
"BlockingCounter::DecrementCount() called too many times");
|
||||
if (count == 0) {
|
||||
base_internal::TraceSignal(this, TraceObjectKind());
|
||||
MutexLock l(&lock_);
|
||||
MutexLock l(lock_);
|
||||
done_ = true;
|
||||
return true;
|
||||
}
|
||||
@@ -52,7 +52,7 @@ bool BlockingCounter::DecrementCount() {
|
||||
void BlockingCounter::Wait() {
|
||||
base_internal::TraceWait(this, TraceObjectKind());
|
||||
{
|
||||
MutexLock l(&this->lock_);
|
||||
MutexLock l(this->lock_);
|
||||
|
||||
// only one thread may call Wait(). To support more than one thread,
|
||||
// implement a counter num_to_exit, like in the Barrier class.
|
||||
|
||||
@@ -60,7 +60,7 @@ static void ReclaimThreadIdentity(void* v) {
|
||||
// association state in this case.
|
||||
base_internal::ClearCurrentThreadIdentity();
|
||||
{
|
||||
base_internal::SpinLockHolder l(&freelist_lock);
|
||||
base_internal::SpinLockHolder l(freelist_lock);
|
||||
identity->next = thread_identity_freelist;
|
||||
thread_identity_freelist = identity;
|
||||
}
|
||||
@@ -108,7 +108,7 @@ static base_internal::ThreadIdentity* NewThreadIdentity() {
|
||||
|
||||
{
|
||||
// Re-use a previously released object if possible.
|
||||
base_internal::SpinLockHolder l(&freelist_lock);
|
||||
base_internal::SpinLockHolder l(freelist_lock);
|
||||
if (thread_identity_freelist) {
|
||||
identity = thread_identity_freelist; // Take list-head.
|
||||
thread_identity_freelist = thread_identity_freelist->next;
|
||||
|
||||
@@ -58,7 +58,7 @@ ABSL_CONST_INIT static absl::base_internal::SpinLock arena_mu(
|
||||
ABSL_CONST_INIT static base_internal::LowLevelAlloc::Arena* arena;
|
||||
|
||||
static void InitArenaIfNecessary() {
|
||||
base_internal::SpinLockHolder l(&arena_mu);
|
||||
base_internal::SpinLockHolder l(arena_mu);
|
||||
if (arena == nullptr) {
|
||||
arena = base_internal::LowLevelAlloc::NewArena(0);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class ThreadPool {
|
||||
|
||||
~ThreadPool() {
|
||||
{
|
||||
absl::MutexLock l(&mu_);
|
||||
absl::MutexLock l(mu_);
|
||||
for (size_t i = 0; i < threads_.size(); i++) {
|
||||
queue_.push(nullptr); // Shutdown signal.
|
||||
}
|
||||
@@ -59,7 +59,7 @@ class ThreadPool {
|
||||
// Schedule a function to be run on a ThreadPool thread immediately.
|
||||
void Schedule(absl::AnyInvocable<void()> func) {
|
||||
assert(func != nullptr);
|
||||
absl::MutexLock l(&mu_);
|
||||
absl::MutexLock l(mu_);
|
||||
queue_.push(std::move(func));
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class ThreadPool {
|
||||
while (true) {
|
||||
absl::AnyInvocable<void()> func;
|
||||
{
|
||||
absl::MutexLock l(&mu_);
|
||||
absl::MutexLock l(mu_);
|
||||
mu_.Await(absl::Condition(this, &ThreadPool::WorkAvailable));
|
||||
func = std::move(queue_.front());
|
||||
queue_.pop();
|
||||
|
||||
@@ -1223,9 +1223,8 @@ static GraphId GetGraphIdLocked(Mutex* mu)
|
||||
}
|
||||
|
||||
static GraphId GetGraphId(Mutex* mu) ABSL_LOCKS_EXCLUDED(deadlock_graph_mu) {
|
||||
deadlock_graph_mu.lock();
|
||||
base_internal::SpinLockHolder l(deadlock_graph_mu);
|
||||
GraphId id = GetGraphIdLocked(mu);
|
||||
deadlock_graph_mu.unlock();
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -1386,7 +1385,7 @@ static GraphId DeadlockCheck(Mutex* mu) {
|
||||
|
||||
SynchLocksHeld* all_locks = Synch_GetAllLocks();
|
||||
|
||||
absl::base_internal::SpinLockHolder lock(&deadlock_graph_mu);
|
||||
absl::base_internal::SpinLockHolder lock(deadlock_graph_mu);
|
||||
const GraphId mu_id = GetGraphIdLocked(mu);
|
||||
|
||||
if (all_locks->n == 0) {
|
||||
|
||||
@@ -587,7 +587,7 @@ class ABSL_LOCKABLE ABSL_ATTRIBUTE_WARN_UNUSED Mutex {
|
||||
// Class Foo {
|
||||
// public:
|
||||
// Foo::Bar* Baz() {
|
||||
// MutexLock lock(&mu_);
|
||||
// MutexLock lock(mu_);
|
||||
// ...
|
||||
// return bar;
|
||||
// }
|
||||
@@ -743,7 +743,7 @@ class ABSL_SCOPED_LOCKABLE WriterMutexLock {
|
||||
// Example using a scope guard:
|
||||
//
|
||||
// {
|
||||
// MutexLock lock(&mu_, count_is_zero);
|
||||
// MutexLock lock(mu_, count_is_zero);
|
||||
// // ...
|
||||
// }
|
||||
//
|
||||
|
||||
@@ -145,7 +145,7 @@ void BM_MutexEnqueue(benchmark::State& state) {
|
||||
shared->looping_threads.fetch_add(1);
|
||||
for (int i = 0; i < kBatchSize; i++) {
|
||||
{
|
||||
absl::MutexLock l(&shared->mu);
|
||||
absl::MutexLock l(shared->mu);
|
||||
shared->thread_has_mutex.store(true, std::memory_order_relaxed);
|
||||
// Spin until all other threads are either out of the benchmark loop
|
||||
// or blocked on the mutex. This ensures that the mutex queue is kept
|
||||
|
||||
@@ -108,7 +108,7 @@ static void CheckSumG0G1(void *v) {
|
||||
|
||||
static void TestMu(TestContext *cxt, int c) {
|
||||
for (int i = 0; i != cxt->iterations; i++) {
|
||||
absl::MutexLock l(&cxt->mu);
|
||||
absl::MutexLock l(cxt->mu);
|
||||
int a = cxt->g0 + 1;
|
||||
cxt->g0 = a;
|
||||
cxt->g1--;
|
||||
@@ -129,7 +129,7 @@ static void TestTry(TestContext *cxt, int c) {
|
||||
|
||||
static void TestR20ms(TestContext *cxt, int c) {
|
||||
for (int i = 0; i != cxt->iterations; i++) {
|
||||
absl::ReaderMutexLock l(&cxt->mu);
|
||||
absl::ReaderMutexLock l(cxt->mu);
|
||||
absl::SleepFor(absl::Milliseconds(20));
|
||||
cxt->mu.AssertReaderHeld();
|
||||
}
|
||||
@@ -138,7 +138,7 @@ static void TestR20ms(TestContext *cxt, int c) {
|
||||
static void TestRW(TestContext *cxt, int c) {
|
||||
if ((c & 1) == 0) {
|
||||
for (int i = 0; i != cxt->iterations; i++) {
|
||||
absl::WriterMutexLock l(&cxt->mu);
|
||||
absl::WriterMutexLock l(cxt->mu);
|
||||
cxt->g0++;
|
||||
cxt->g1--;
|
||||
cxt->mu.AssertHeld();
|
||||
@@ -146,7 +146,7 @@ static void TestRW(TestContext *cxt, int c) {
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i != cxt->iterations; i++) {
|
||||
absl::ReaderMutexLock l(&cxt->mu);
|
||||
absl::ReaderMutexLock l(cxt->mu);
|
||||
CHECK_EQ(cxt->g0, -cxt->g1) << "Error in TestRW";
|
||||
cxt->mu.AssertReaderHeld();
|
||||
}
|
||||
@@ -168,7 +168,7 @@ static void TestAwait(TestContext *cxt, int c) {
|
||||
MyContext mc;
|
||||
mc.target = c;
|
||||
mc.cxt = cxt;
|
||||
absl::MutexLock l(&cxt->mu);
|
||||
absl::MutexLock l(cxt->mu);
|
||||
cxt->mu.AssertHeld();
|
||||
while (cxt->g0 < cxt->iterations) {
|
||||
cxt->mu.Await(absl::Condition(&mc, &MyContext::MyTurn));
|
||||
@@ -184,7 +184,7 @@ static void TestAwait(TestContext *cxt, int c) {
|
||||
|
||||
static void TestSignalAll(TestContext *cxt, int c) {
|
||||
int target = c;
|
||||
absl::MutexLock l(&cxt->mu);
|
||||
absl::MutexLock l(cxt->mu);
|
||||
cxt->mu.AssertHeld();
|
||||
while (cxt->g0 < cxt->iterations) {
|
||||
while (cxt->g0 != target && cxt->g0 != cxt->iterations) {
|
||||
@@ -202,7 +202,7 @@ static void TestSignalAll(TestContext *cxt, int c) {
|
||||
static void TestSignal(TestContext *cxt, int c) {
|
||||
CHECK_EQ(cxt->threads, 2) << "TestSignal should use 2 threads";
|
||||
int target = c;
|
||||
absl::MutexLock l(&cxt->mu);
|
||||
absl::MutexLock l(cxt->mu);
|
||||
cxt->mu.AssertHeld();
|
||||
while (cxt->g0 < cxt->iterations) {
|
||||
while (cxt->g0 != target && cxt->g0 != cxt->iterations) {
|
||||
@@ -219,7 +219,7 @@ static void TestSignal(TestContext *cxt, int c) {
|
||||
|
||||
static void TestCVTimeout(TestContext *cxt, int c) {
|
||||
int target = c;
|
||||
absl::MutexLock l(&cxt->mu);
|
||||
absl::MutexLock l(cxt->mu);
|
||||
cxt->mu.AssertHeld();
|
||||
while (cxt->g0 < cxt->iterations) {
|
||||
while (cxt->g0 != target && cxt->g0 != cxt->iterations) {
|
||||
@@ -243,7 +243,7 @@ static void TestTime(TestContext *cxt, int c, bool use_cv) {
|
||||
absl::Condition false_cond(&kFalse);
|
||||
absl::Condition g0ge2(G0GE2, cxt);
|
||||
if (c == 0) {
|
||||
absl::MutexLock l(&cxt->mu);
|
||||
absl::MutexLock l(cxt->mu);
|
||||
|
||||
absl::Time start = absl::Now();
|
||||
if (use_cv) {
|
||||
@@ -311,7 +311,7 @@ static void TestTime(TestContext *cxt, int c, bool use_cv) {
|
||||
CHECK_EQ(cxt->g0, cxt->threads) << "TestTime failed";
|
||||
|
||||
} else if (c == 1) {
|
||||
absl::MutexLock l(&cxt->mu);
|
||||
absl::MutexLock l(cxt->mu);
|
||||
const absl::Time start = absl::Now();
|
||||
if (use_cv) {
|
||||
cxt->cv.WaitWithTimeout(&cxt->mu, absl::Milliseconds(500));
|
||||
@@ -324,7 +324,7 @@ static void TestTime(TestContext *cxt, int c, bool use_cv) {
|
||||
<< "TestTime failed";
|
||||
cxt->g0++;
|
||||
} else if (c == 2) {
|
||||
absl::MutexLock l(&cxt->mu);
|
||||
absl::MutexLock l(cxt->mu);
|
||||
if (use_cv) {
|
||||
while (cxt->g0 < 2) {
|
||||
cxt->cv.WaitWithTimeout(&cxt->mu, absl::Seconds(100));
|
||||
@@ -335,7 +335,7 @@ static void TestTime(TestContext *cxt, int c, bool use_cv) {
|
||||
}
|
||||
cxt->g0++;
|
||||
} else {
|
||||
absl::MutexLock l(&cxt->mu);
|
||||
absl::MutexLock l(cxt->mu);
|
||||
if (use_cv) {
|
||||
while (cxt->g0 < 2) {
|
||||
cxt->cv.Wait(&cxt->mu);
|
||||
@@ -726,20 +726,20 @@ TEST(Mutex, LockWhenGuard) {
|
||||
bool (*cond_lt_10)(int *) = [](int *p) { return *p < 10; };
|
||||
|
||||
std::thread t1([&mu, &n, &done, cond_eq_10]() {
|
||||
absl::ReaderMutexLock lock(&mu, absl::Condition(cond_eq_10, &n));
|
||||
absl::ReaderMutexLock lock(mu, absl::Condition(cond_eq_10, &n));
|
||||
done = true;
|
||||
});
|
||||
|
||||
std::thread t2[10];
|
||||
for (std::thread &t : t2) {
|
||||
t = std::thread([&mu, &n, cond_lt_10]() {
|
||||
absl::WriterMutexLock lock(&mu, absl::Condition(cond_lt_10, &n));
|
||||
absl::WriterMutexLock lock(mu, absl::Condition(cond_lt_10, &n));
|
||||
++n;
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
absl::MutexLock lock(&mu);
|
||||
absl::MutexLock lock(mu);
|
||||
n = 0;
|
||||
}
|
||||
|
||||
@@ -793,7 +793,7 @@ static bool AllDone(void *v) {
|
||||
// L={}
|
||||
static void WaitForCond(ReaderDecrementBugStruct *x) {
|
||||
absl::Mutex dummy;
|
||||
absl::MutexLock l(&dummy);
|
||||
absl::MutexLock l(dummy);
|
||||
x->mu.LockWhen(absl::Condition(&IsCond, x));
|
||||
x->done--;
|
||||
x->mu.Unlock();
|
||||
@@ -1576,11 +1576,11 @@ TEST_P(TimeoutTest, Await) {
|
||||
std::unique_ptr<absl::synchronization_internal::ThreadPool> pool =
|
||||
CreateDefaultPool();
|
||||
RunAfterDelay(params.satisfy_condition_delay, pool.get(), [&] {
|
||||
absl::MutexLock l(&mu);
|
||||
absl::MutexLock l(mu);
|
||||
value = true;
|
||||
});
|
||||
|
||||
absl::MutexLock lock(&mu);
|
||||
absl::MutexLock lock(mu);
|
||||
absl::Time start_time = absl::Now();
|
||||
absl::Condition cond(&value);
|
||||
bool result =
|
||||
@@ -1610,7 +1610,7 @@ TEST_P(TimeoutTest, LockWhen) {
|
||||
std::unique_ptr<absl::synchronization_internal::ThreadPool> pool =
|
||||
CreateDefaultPool();
|
||||
RunAfterDelay(params.satisfy_condition_delay, pool.get(), [&] {
|
||||
absl::MutexLock l(&mu);
|
||||
absl::MutexLock l(mu);
|
||||
value = true;
|
||||
});
|
||||
|
||||
@@ -1645,7 +1645,7 @@ TEST_P(TimeoutTest, ReaderLockWhen) {
|
||||
std::unique_ptr<absl::synchronization_internal::ThreadPool> pool =
|
||||
CreateDefaultPool();
|
||||
RunAfterDelay(params.satisfy_condition_delay, pool.get(), [&] {
|
||||
absl::MutexLock l(&mu);
|
||||
absl::MutexLock l(mu);
|
||||
value = true;
|
||||
});
|
||||
|
||||
@@ -1682,12 +1682,12 @@ TEST_P(TimeoutTest, Wait) {
|
||||
std::unique_ptr<absl::synchronization_internal::ThreadPool> pool =
|
||||
CreateDefaultPool();
|
||||
RunAfterDelay(params.satisfy_condition_delay, pool.get(), [&] {
|
||||
absl::MutexLock l(&mu);
|
||||
absl::MutexLock l(mu);
|
||||
value = true;
|
||||
cv.Signal();
|
||||
});
|
||||
|
||||
absl::MutexLock lock(&mu);
|
||||
absl::MutexLock lock(mu);
|
||||
absl::Time start_time = absl::Now();
|
||||
absl::Duration timeout = params.wait_timeout;
|
||||
absl::Time deadline = start_time + timeout;
|
||||
@@ -1933,7 +1933,7 @@ TEST(Mutex, WriterPriority) {
|
||||
std::atomic<bool> saw_wrote{false};
|
||||
auto readfunc = [&]() {
|
||||
for (size_t i = 0; i < 10; ++i) {
|
||||
absl::ReaderMutexLock lock(&mu);
|
||||
absl::ReaderMutexLock lock(mu);
|
||||
if (wrote) {
|
||||
saw_wrote = true;
|
||||
break;
|
||||
@@ -1948,7 +1948,7 @@ TEST(Mutex, WriterPriority) {
|
||||
// PerThreadSynch::priority, so the writer intentionally runs on a new thread.
|
||||
std::thread t3([&]() {
|
||||
// The writer should be able squeeze between the two alternating readers.
|
||||
absl::MutexLock lock(&mu);
|
||||
absl::MutexLock lock(mu);
|
||||
wrote = true;
|
||||
});
|
||||
t1.join();
|
||||
|
||||
@@ -26,7 +26,7 @@ ABSL_NAMESPACE_BEGIN
|
||||
|
||||
void Notification::Notify() {
|
||||
base_internal::TraceSignal(this, TraceObjectKind());
|
||||
MutexLock l(&this->mutex_);
|
||||
MutexLock l(this->mutex_);
|
||||
|
||||
#ifndef NDEBUG
|
||||
if (ABSL_PREDICT_FALSE(notified_yet_.load(std::memory_order_relaxed))) {
|
||||
@@ -43,7 +43,7 @@ void Notification::Notify() {
|
||||
Notification::~Notification() {
|
||||
// Make sure that the thread running Notify() exits before the object is
|
||||
// destructed.
|
||||
MutexLock l(&this->mutex_);
|
||||
MutexLock l(this->mutex_);
|
||||
}
|
||||
|
||||
void Notification::WaitForNotification() const {
|
||||
|
||||
@@ -34,17 +34,17 @@ class ThreadSafeCounter {
|
||||
ThreadSafeCounter() : count_(0) {}
|
||||
|
||||
void Increment() {
|
||||
MutexLock lock(&mutex_);
|
||||
MutexLock lock(mutex_);
|
||||
++count_;
|
||||
}
|
||||
|
||||
int Get() const {
|
||||
MutexLock lock(&mutex_);
|
||||
MutexLock lock(mutex_);
|
||||
return count_;
|
||||
}
|
||||
|
||||
void WaitUntilGreaterOrEqual(int n) {
|
||||
MutexLock lock(&mutex_);
|
||||
MutexLock lock(mutex_);
|
||||
auto cond = [this, n]() { return count_ >= n; };
|
||||
mutex_.Await(Condition(&cond));
|
||||
}
|
||||
|
||||
@@ -415,7 +415,7 @@ static int64_t GetCurrentTimeNanosSlowPath()
|
||||
ABSL_LOCKS_EXCLUDED(time_state.lock) {
|
||||
// Serialize access to slow-path. Fast-path readers are not blocked yet, and
|
||||
// code below must not modify last_sample until the seqlock is acquired.
|
||||
base_internal::SpinLockHolder l(&time_state.lock);
|
||||
base_internal::SpinLockHolder l(time_state.lock);
|
||||
|
||||
// Sample the kernel time base. This is the definition of
|
||||
// "now" if we take the slow path.
|
||||
|
||||
Reference in New Issue
Block a user