diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2022-11-11 12:48:29 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2022-11-19 11:10:22 +0000 |
commit | 0a62889c7a155f8ed971860d68870dc9c46bb004 (patch) | |
tree | 6f9cdbfaa40430d129e13cb35bbfe39a8e4481d4 /gcc/jit/libgccjit.cc | |
parent | 8c05d8cd4300f74bf2698f0a6b96464b5be571be (diff) | |
download | gcc-0a62889c7a155f8ed971860d68870dc9c46bb004.zip gcc-0a62889c7a155f8ed971860d68870dc9c46bb004.tar.gz gcc-0a62889c7a155f8ed971860d68870dc9c46bb004.tar.bz2 |
jit: Use std::mutex instead of pthread_mutex_t
This allows JIT to be built with a different thread model from posix
where pthread isn't available
By renaming the acquire_mutex () and release_mutex () member functions
to lock() and unlock() we make the playback::context type meet the C++
Lockable requirements. This allows it to be used with a scoped lock
(i.e. RAII) type as std::lock_guard. This automatically releases the
mutex when leaving the scope.
Co-authored-by: LIU Hao <lh_mouse@126.com>
gcc/jit/ChangeLog:
* jit-playback.cc (playback::context::scoped_lock): Define RAII
lock type.
(playback::context::compile): Use scoped_lock to acquire mutex
for the active playback context.
(jit_mutex): Change to std::mutex.
(playback::context::acquire_mutex): Rename to ...
(playback::context::lock): ... this.
(playback::context::release_mutex): Rename to ...
(playback::context::unlock): ... this.
* jit-playback.h (playback::context): Rename members and declare
scoped_lock.
* jit-recording.cc (INCLUDE_PTHREAD_H): Remove unused define.
* libgccjit.cc (version_mutex): Change to std::mutex.
(struct jit_version_info): Use std::lock_guard to acquire and
release mutex.
gcc/ChangeLog:
* system.h [INCLUDE_MUTEX]: Include header for std::mutex.
Diffstat (limited to 'gcc/jit/libgccjit.cc')
-rw-r--r-- | gcc/jit/libgccjit.cc | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/gcc/jit/libgccjit.cc b/gcc/jit/libgccjit.cc index ca86266..8884128 100644 --- a/gcc/jit/libgccjit.cc +++ b/gcc/jit/libgccjit.cc @@ -19,7 +19,7 @@ along with GCC; see the file COPYING3. If not see <http://www.gnu.org/licenses/>. */ #include "config.h" -#define INCLUDE_PTHREAD_H +#define INCLUDE_MUTEX #include "system.h" #include "coretypes.h" #include "timevar.h" @@ -4060,7 +4060,7 @@ gcc_jit_context_new_rvalue_from_vector (gcc_jit_context *ctxt, Ideally this would be within parse_basever, but the mutex is only needed by libgccjit. */ -static pthread_mutex_t version_mutex = PTHREAD_MUTEX_INITIALIZER; +static std::mutex version_mutex; struct jit_version_info { @@ -4068,9 +4068,8 @@ struct jit_version_info guarded by version_mutex. */ jit_version_info () { - pthread_mutex_lock (&version_mutex); + std::lock_guard<std::mutex> g (version_mutex); parse_basever (&major, &minor, &patchlevel); - pthread_mutex_unlock (&version_mutex); } int major; |