Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/google/protobuf/descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1979,7 +1979,7 @@ Symbol DescriptorPool::Tables::FindByNameHelper(const DescriptorPool* pool,
absl::string_view name) {
if (pool->mutex_ != nullptr) {
// Fast path: the Symbol is already cached. This is just a hash lookup.
absl::ReaderMutexLock lock(pool->mutex_);
ReaderMutexLock lock(pool->mutex_);
if (known_bad_symbols_.empty() && known_bad_files_.empty()) {
Symbol result = FindSymbol(name);
if (!result.IsNull()) return result;
Expand All @@ -1988,7 +1988,7 @@ Symbol DescriptorPool::Tables::FindByNameHelper(const DescriptorPool* pool,
DescriptorPool::DeferredValidation deferred_validation(pool);
Symbol result;
{
absl::MutexLockMaybe lock(pool->mutex_);
MutexLockMaybe lock(pool->mutex_);
if (pool->fallback_database_ != nullptr) {
known_bad_symbols_.clear();
known_bad_files_.clear();
Expand Down Expand Up @@ -2165,7 +2165,7 @@ FileDescriptorTables::FindEnumValueByNumberCreatingIfUnknown(

{
// Must lock the pool because we will do allocations in the shared arena.
absl::MutexLockMaybe l2(pool->mutex_);
DescriptorPool::MutexLockMaybe l2(pool->mutex_);
alloc.FinalizePlanning(tables);
}
EnumValueDescriptor* result = alloc.AllocateArray<EnumValueDescriptor>(1);
Expand Down Expand Up @@ -2387,7 +2387,7 @@ DescriptorPool::DescriptorPool()

DescriptorPool::DescriptorPool(DescriptorDatabase* fallback_database,
ErrorCollector* error_collector)
: mutex_(new absl::Mutex),
: mutex_(new Mutex),
fallback_database_(fallback_database),
default_error_collector_(error_collector),
underlay_(nullptr),
Expand Down Expand Up @@ -2452,7 +2452,7 @@ bool DescriptorPool::IsReadyForCheckingDescriptorExtDecl(
void DescriptorPool::ClearDirectInputFiles() { direct_input_files_.clear(); }

bool DescriptorPool::InternalIsFileLoaded(absl::string_view filename) const {
absl::MutexLockMaybe lock(mutex_);
MutexLockMaybe lock(mutex_);
return tables_->FindFile(filename) != nullptr;
}

Expand Down Expand Up @@ -2522,7 +2522,7 @@ void DescriptorPool::InternalAddGeneratedFile(
// Therefore, when we parse one, we have to be very careful to avoid using
// any descriptor-based operations, since this might cause infinite recursion
// or deadlock.
absl::MutexLockMaybe lock(internal_generated_pool()->mutex_);
MutexLockMaybe lock(internal_generated_pool()->mutex_);
ABSL_CHECK(GeneratedDatabase()->Add(encoded_file_descriptor, size));
}

Expand All @@ -2538,7 +2538,7 @@ const FileDescriptor* DescriptorPool::FindFileByName(
DeferredValidation deferred_validation(this);
const FileDescriptor* result = nullptr;
{
absl::MutexLockMaybe lock(mutex_);
MutexLockMaybe lock(mutex_);
if (fallback_database_ != nullptr) {
tables_->known_bad_symbols_.clear();
tables_->known_bad_files_.clear();
Expand All @@ -2564,7 +2564,7 @@ const FileDescriptor* DescriptorPool::FindFileContainingSymbol(
const FileDescriptor* file_result = nullptr;
DeferredValidation deferred_validation(this);
{
absl::MutexLockMaybe lock(mutex_);
MutexLockMaybe lock(mutex_);
if (fallback_database_ != nullptr) {
tables_->known_bad_symbols_.clear();
tables_->known_bad_files_.clear();
Expand Down Expand Up @@ -2644,7 +2644,7 @@ const FieldDescriptor* DescriptorPool::FindExtensionByNumber(
// A faster path to reduce lock contention in finding extensions, assuming
// most extensions will be cache hit.
if (mutex_ != nullptr) {
absl::ReaderMutexLock lock(mutex_);
ReaderMutexLock lock(mutex_);
const FieldDescriptor* result = tables_->FindExtension(extendee, number);
if (result != nullptr) {
return result;
Expand All @@ -2653,7 +2653,7 @@ const FieldDescriptor* DescriptorPool::FindExtensionByNumber(
const FieldDescriptor* result = nullptr;
DeferredValidation deferred_validation(this);
{
absl::MutexLockMaybe lock(mutex_);
MutexLockMaybe lock(mutex_);
if (fallback_database_ != nullptr) {
tables_->known_bad_symbols_.clear();
tables_->known_bad_files_.clear();
Expand Down Expand Up @@ -2728,7 +2728,7 @@ void DescriptorPool::FindAllExtensions(
DeferredValidation deferred_validation(this);
std::vector<const FieldDescriptor*> extensions;
{
absl::MutexLockMaybe lock(mutex_);
MutexLockMaybe lock(mutex_);
if (fallback_database_ != nullptr) {
tables_->known_bad_symbols_.clear();
tables_->known_bad_files_.clear();
Expand Down Expand Up @@ -5309,7 +5309,7 @@ Symbol DescriptorBuilder::FindSymbolNotEnforcingDepsHelper(
const DescriptorPool* pool, const absl::string_view name, bool build_it) {
// If we are looking at an underlay, we must lock its mutex_, since we are
// accessing the underlay's tables_ directly.
absl::MutexLockMaybe lock((pool == pool_) ? nullptr : pool->mutex_);
DescriptorPool::MutexLockMaybe lock((pool == pool_) ? nullptr : pool->mutex_);

Symbol result = pool->tables_->FindSymbol(name);
if (result.IsNull() && pool->underlay_ != nullptr) {
Expand Down Expand Up @@ -5502,7 +5502,7 @@ static bool ValidateQualifiedName(absl::string_view name) {

Symbol DescriptorPool::NewPlaceholder(absl::string_view name,
PlaceholderType placeholder_type) const {
absl::MutexLockMaybe lock(mutex_);
MutexLockMaybe lock(mutex_);
return NewPlaceholderWithMutexHeld(name, placeholder_type);
}

Expand Down Expand Up @@ -5634,7 +5634,7 @@ Symbol DescriptorPool::NewPlaceholderWithMutexHeld(

FileDescriptor* DescriptorPool::NewPlaceholderFile(
const absl::string_view name) const {
absl::MutexLockMaybe lock(mutex_);
MutexLockMaybe lock(mutex_);
internal::FlatAllocator alloc;
alloc.PlanArray<FileDescriptor>(1);
alloc.PlanArray<std::string>(1);
Expand Down
7 changes: 6 additions & 1 deletion src/google/protobuf/descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2661,9 +2661,14 @@ class PROTOBUF_EXPORT DescriptorPool {
std::unique_ptr<MemoBase>>>();
#endif // SWIG

using Mutex = absl::Mutex;
using MutexLock = absl::MutexLock;
using MutexLockMaybe = absl::MutexLockMaybe;
using ReaderMutexLock = absl::ReaderMutexLock;

// If fallback_database_ is nullptr, this is nullptr. Otherwise, this is a
// mutex which must be locked while accessing tables_.
absl::Mutex* mutex_;
Mutex* mutex_;

// See constructor.
DescriptorDatabase* fallback_database_;
Expand Down
Loading