Skip to content

Commit

Permalink
[C++] Fix synchronization abstraction for Abseil (antlr#3696)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcking authored May 5, 2022
1 parent 1650f0e commit a9e0ccf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion runtime/Cpp/runtime/src/internal/Synchronization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void SharedMutex::lock() {

bool SharedMutex::try_lock() {
#if ANTLR4CPP_USING_ABSEIL
return _impl.TryWriterLock();
return _impl.WriterTryLock();
#else
return _impl.try_lock();
#endif
Expand Down
22 changes: 13 additions & 9 deletions runtime/Cpp/runtime/src/internal/Synchronization.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@

#if ANTLR4CPP_USING_ABSEIL
#include "absl/base/call_once.h"
#include "absl/base/thread_annotations.h"
#include "absl/synchronization/mutex.h"
#define ANTLR4CPP_NO_THREAD_SAFTEY_ANALYSIS ABSL_NO_THREAD_SAFETY_ANALYSIS
#else
#define ANTLR4CPP_NO_THREAD_SAFTEY_ANALYSIS
#endif

// By default ANTLRv4 uses synchronization primitives provided by the C++ standard library. In most
Expand All @@ -56,11 +60,11 @@ namespace antlr4::internal {
Mutex& operator=(const Mutex&) = delete;
Mutex& operator=(Mutex&&) = delete;

void lock();
void lock() ANTLR4CPP_NO_THREAD_SAFTEY_ANALYSIS;

bool try_lock();
bool try_lock() ANTLR4CPP_NO_THREAD_SAFTEY_ANALYSIS;

void unlock();
void unlock() ANTLR4CPP_NO_THREAD_SAFTEY_ANALYSIS;

private:
#if ANTLR4CPP_USING_ABSEIL
Expand All @@ -86,17 +90,17 @@ namespace antlr4::internal {
SharedMutex& operator=(const SharedMutex&) = delete;
SharedMutex& operator=(SharedMutex&&) = delete;

void lock();
void lock() ANTLR4CPP_NO_THREAD_SAFTEY_ANALYSIS;

bool try_lock();
bool try_lock() ANTLR4CPP_NO_THREAD_SAFTEY_ANALYSIS;

void unlock();
void unlock() ANTLR4CPP_NO_THREAD_SAFTEY_ANALYSIS;

void lock_shared();
void lock_shared() ANTLR4CPP_NO_THREAD_SAFTEY_ANALYSIS;

bool try_lock_shared();
bool try_lock_shared() ANTLR4CPP_NO_THREAD_SAFTEY_ANALYSIS;

void unlock_shared();
void unlock_shared() ANTLR4CPP_NO_THREAD_SAFTEY_ANALYSIS;

private:
#if ANTLR4CPP_USING_ABSEIL
Expand Down

0 comments on commit a9e0ccf

Please sign in to comment.