From 0a62889c7a155f8ed971860d68870dc9c46bb004 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Fri, 11 Nov 2022 12:48:29 +0000 Subject: 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 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. --- gcc/jit/jit-playback.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'gcc/jit/jit-playback.h') diff --git a/gcc/jit/jit-playback.h b/gcc/jit/jit-playback.h index 3ba02a0..1aeee2c 100644 --- a/gcc/jit/jit-playback.h +++ b/gcc/jit/jit-playback.h @@ -314,8 +314,9 @@ private: /* Functions for implementing "compile". */ - void acquire_mutex (); - void release_mutex (); + void lock (); + void unlock (); + struct scoped_lock; void make_fake_args (vec *argvec, -- cgit v1.1