From 83c1d65c90a92aa49632b9ac5a793214bb0768bc Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 5 Sep 2019 02:54:58 -0700 Subject: Export of internal Abseil changes -- 972333fe1e43427849b8a634aa35061e81be3642 by Abseil Team : Replace deprecated thread annotations macros. PiperOrigin-RevId: 267332619 -- 7039c6dc499a31c372b4872eda0772455931c360 by Gennadiy Rozental : Internal change PiperOrigin-RevId: 267220271 -- a3f524d2afc2535686f206a7ce06961016349d7a by Abseil Team : Factor kernel_timeout out of synchronization. PiperOrigin-RevId: 267217304 -- 90287de4114ef9a06cafe50256a2d03349772c21 by Abseil Team : Fixed comment typo. PiperOrigin-RevId: 267198532 -- d312c1a1e52aeca1871ff0deead416d09a7f237e by Gennadiy Rozental : Internal change PiperOrigin-RevId: 267185804 GitOrigin-RevId: 972333fe1e43427849b8a634aa35061e81be3642 Change-Id: Ia8a2f877c57cef9854aad48f1753af872fc04dc8 --- absl/flags/internal/commandlineflag.cc | 126 ++++++++++++++++----------------- 1 file changed, 63 insertions(+), 63 deletions(-) (limited to 'absl/flags/internal/commandlineflag.cc') diff --git a/absl/flags/internal/commandlineflag.cc b/absl/flags/internal/commandlineflag.cc index 2063cda..ae6a8d7 100644 --- a/absl/flags/internal/commandlineflag.cc +++ b/absl/flags/internal/commandlineflag.cc @@ -58,55 +58,55 @@ absl::Mutex* InitFlag(CommandLineFlag* flag) { { absl::MutexLock lock(&init_lock); - if (flag->locks == nullptr) { // Must initialize Mutexes for this flag. - flag->locks = new flags_internal::CommandLineFlagLocks; + if (flag->locks_ == nullptr) { // Must initialize Mutexes for this flag. + flag->locks_ = new flags_internal::CommandLineFlagLocks; } - mu = &flag->locks->primary_mu; + mu = &flag->locks_->primary_mu; } { absl::MutexLock lock(mu); - if (!flag->IsRetired() && flag->def == nullptr) { + if (!flag->IsRetired() && flag->def_ == nullptr) { // Need to initialize def and cur fields. - flag->def = (*flag->make_init_value)(); - flag->cur = Clone(flag->op, flag->def); + flag->def_ = (*flag->make_init_value_)(); + flag->cur_ = Clone(flag->op_, flag->def_); UpdateCopy(flag); - flag->inited.store(true, std::memory_order_release); + flag->inited_.store(true, std::memory_order_release); flag->InvokeCallback(); } } - flag->inited.store(true, std::memory_order_release); + flag->inited_.store(true, std::memory_order_release); return mu; } // Ensure that the lazily initialized fields of *flag have been initialized, -// and return &flag->locks->primary_mu. +// and return &flag->locks_->primary_mu. absl::Mutex* CommandLineFlag::InitFlagIfNecessary() const - LOCK_RETURNED(locks->primary_mu) { - if (!this->inited.load(std::memory_order_acquire)) { + ABSL_LOCK_RETURNED(locks_->primary_mu) { + if (!inited_.load(std::memory_order_acquire)) { return InitFlag(const_cast(this)); } - // All fields initialized; this->locks is therefore safe to read. - return &this->locks->primary_mu; + // All fields initialized; locks_ is therefore safe to read. + return &locks_->primary_mu; } bool CommandLineFlag::IsModified() const { absl::MutexLock l(InitFlagIfNecessary()); - return modified; + return modified_; } void CommandLineFlag::SetModified(bool is_modified) { absl::MutexLock l(InitFlagIfNecessary()); - modified = is_modified; + modified_ = is_modified; } bool CommandLineFlag::IsSpecifiedOnCommandLine() const { absl::MutexLock l(InitFlagIfNecessary()); - return on_command_line; + return on_command_line_; } absl::string_view CommandLineFlag::Typename() const { @@ -134,19 +134,19 @@ absl::string_view CommandLineFlag::Typename() const { } std::string CommandLineFlag::Filename() const { - return flags_internal::GetUsageConfig().normalize_filename(this->filename); + return flags_internal::GetUsageConfig().normalize_filename(filename_); } std::string CommandLineFlag::DefaultValue() const { absl::MutexLock l(InitFlagIfNecessary()); - return Unparse(this->marshalling_op, this->def); + return Unparse(marshalling_op_, def_); } std::string CommandLineFlag::CurrentValue() const { absl::MutexLock l(InitFlagIfNecessary()); - return Unparse(this->marshalling_op, this->cur); + return Unparse(marshalling_op_, cur_); } // Attempts to parse supplied `value` string using parsing routine in the `flag` @@ -157,31 +157,31 @@ std::string CommandLineFlag::CurrentValue() const { // in 'err' bool TryParseLocked(CommandLineFlag* flag, void* dst, absl::string_view value, std::string* err) - EXCLUSIVE_LOCKS_REQUIRED(flag->locks->primary_mu) { - void* tentative_value = Clone(flag->op, flag->def); + ABSL_EXCLUSIVE_LOCKS_REQUIRED(flag->locks_->primary_mu) { + void* tentative_value = Clone(flag->op_, flag->def_); std::string parse_err; - if (!Parse(flag->marshalling_op, value, tentative_value, &parse_err)) { + if (!Parse(flag->marshalling_op_, value, tentative_value, &parse_err)) { auto type_name = flag->Typename(); absl::string_view err_sep = parse_err.empty() ? "" : "; "; absl::string_view typename_sep = type_name.empty() ? "" : " "; *err = absl::StrCat("Illegal value '", value, "' specified for", typename_sep, type_name, " flag '", flag->Name(), "'", err_sep, parse_err); - Delete(flag->op, tentative_value); + Delete(flag->op_, tentative_value); return false; } if (!flag->InvokeValidator(tentative_value)) { *err = absl::StrCat("Failed validation of new value '", - Unparse(flag->marshalling_op, tentative_value), + Unparse(flag->marshalling_op_, tentative_value), "' for flag '", flag->Name(), "'"); - Delete(flag->op, tentative_value); + Delete(flag->op_, tentative_value); return false; } - flag->counter++; - Copy(flag->op, tentative_value, dst); - Delete(flag->op, tentative_value); + flag->counter_++; + Copy(flag->op_, tentative_value, dst); + Delete(flag->op_, tentative_value); return true; } @@ -201,38 +201,38 @@ bool CommandLineFlag::SetFromString(absl::string_view value, absl::MutexLock l(InitFlagIfNecessary()); // Direct-access flags can be modified without going through the - // flag API. Detect such changes and update the flag->modified bit. + // flag API. Detect such changes and update the flag->modified_ bit. if (!IsAbseilFlag()) { - if (!this->modified && ChangedDirectly(this, this->cur, this->def)) { - this->modified = true; + if (!modified_ && ChangedDirectly(this, cur_, def_)) { + modified_ = true; } } switch (set_mode) { case SET_FLAGS_VALUE: { // set or modify the flag's value - if (!TryParseLocked(this, this->cur, value, err)) return false; - this->modified = true; + if (!TryParseLocked(this, cur_, value, err)) return false; + modified_ = true; UpdateCopy(this); InvokeCallback(); if (source == kCommandLine) { - this->on_command_line = true; + on_command_line_ = true; } break; } case SET_FLAG_IF_DEFAULT: { // set the flag's value, but only if it hasn't been set by someone else - if (!this->modified) { - if (!TryParseLocked(this, this->cur, value, err)) return false; - this->modified = true; + if (!modified_) { + if (!TryParseLocked(this, cur_, value, err)) return false; + modified_ = true; UpdateCopy(this); InvokeCallback(); } else { // TODO(rogeeff): review and fix this semantic. Currently we do not fail // in this case if flag is modified. This is misleading since the flag's // value is not updated even though we return true. - // *err = absl::StrCat(this->Name(), " is already set to ", + // *err = absl::StrCat(Name(), " is already set to ", // CurrentValue(), "\n"); // return false; return true; @@ -241,11 +241,11 @@ bool CommandLineFlag::SetFromString(absl::string_view value, } case SET_FLAGS_DEFAULT: { // modify the flag's default-value - if (!TryParseLocked(this, this->def, value, err)) return false; + if (!TryParseLocked(this, def_, value, err)) return false; - if (!this->modified) { + if (!modified_) { // Need to set both defvalue *and* current, in this case - Copy(this->op, this->def, this->cur); + Copy(op_, def_, cur_); UpdateCopy(this); InvokeCallback(); } @@ -264,8 +264,8 @@ bool CommandLineFlag::SetFromString(absl::string_view value, void CommandLineFlag::StoreAtomic(size_t size) { int64_t t = 0; assert(size <= sizeof(int64_t)); - memcpy(&t, this->cur, size); - this->atomic.store(t, std::memory_order_release); + memcpy(&t, cur_, size); + atomic_.store(t, std::memory_order_release); } void CommandLineFlag::CheckDefaultValueParsingRoundtrip() const { @@ -273,9 +273,9 @@ void CommandLineFlag::CheckDefaultValueParsingRoundtrip() const { absl::MutexLock lock(InitFlagIfNecessary()); - void* dst = Clone(this->op, this->def); + void* dst = Clone(op_, def_); std::string error; - if (!flags_internal::Parse(this->marshalling_op, v, dst, &error)) { + if (!flags_internal::Parse(marshalling_op_, v, dst, &error)) { ABSL_INTERNAL_LOG( FATAL, absl::StrCat("Flag ", Name(), " (from ", Filename(), @@ -285,23 +285,23 @@ void CommandLineFlag::CheckDefaultValueParsingRoundtrip() const { // We do not compare dst to def since parsing/unparsing may make // small changes, e.g., precision loss for floating point types. - Delete(this->op, dst); + Delete(op_, dst); } bool CommandLineFlag::ValidateDefaultValue() const { absl::MutexLock lock(InitFlagIfNecessary()); - return InvokeValidator(this->def); + return InvokeValidator(def_); } bool CommandLineFlag::ValidateInputValue(absl::string_view value) const { absl::MutexLock l(InitFlagIfNecessary()); // protect default value access - void* obj = Clone(this->op, this->def); + void* obj = Clone(op_, def_); std::string ignored_error; const bool result = - flags_internal::Parse(this->marshalling_op, value, obj, &ignored_error) && + flags_internal::Parse(marshalling_op_, value, obj, &ignored_error) && InvokeValidator(obj); - Delete(this->op, obj); + Delete(op_, obj); return result; } @@ -314,13 +314,13 @@ void CommandLineFlag::Read(void* dst, // `dst_op` is the unmarshaling operation corresponding to the declaration // visibile at the call site. `op` is the Flag's defined unmarshalling // operation. They must match for this operation to be well-defined. - if (ABSL_PREDICT_FALSE(dst_op != op)) { + if (ABSL_PREDICT_FALSE(dst_op != op_)) { ABSL_INTERNAL_LOG( ERROR, - absl::StrCat("Flag '", name, + absl::StrCat("Flag '", Name(), "' is defined as one type and declared as another")); } - CopyConstruct(op, cur, dst); + CopyConstruct(op_, cur_, dst); } void CommandLineFlag::Write(const void* src, @@ -330,28 +330,28 @@ void CommandLineFlag::Write(const void* src, // `src_op` is the marshalling operation corresponding to the declaration // visible at the call site. `op` is the Flag's defined marshalling operation. // They must match for this operation to be well-defined. - if (ABSL_PREDICT_FALSE(src_op != op)) { + if (ABSL_PREDICT_FALSE(src_op != op_)) { ABSL_INTERNAL_LOG( ERROR, - absl::StrCat("Flag '", name, + absl::StrCat("Flag '", Name(), "' is defined as one type and declared as another")); } if (ShouldValidateFlagValue(*this)) { - void* obj = Clone(op, src); + void* obj = Clone(op_, src); std::string ignored_error; - std::string src_as_str = Unparse(marshalling_op, src); - if (!Parse(marshalling_op, src_as_str, obj, &ignored_error) || + std::string src_as_str = Unparse(marshalling_op_, src); + if (!Parse(marshalling_op_, src_as_str, obj, &ignored_error) || !InvokeValidator(obj)) { - ABSL_INTERNAL_LOG(ERROR, absl::StrCat("Attempt to set flag '", name, + ABSL_INTERNAL_LOG(ERROR, absl::StrCat("Attempt to set flag '", Name(), "' to invalid value ", src_as_str)); } - Delete(op, obj); + Delete(op_, obj); } - modified = true; - counter++; - Copy(op, src, cur); + modified_ = true; + counter_++; + Copy(op_, src, cur_); UpdateCopy(this); InvokeCallback(); -- cgit v1.2.3