jit: Use std::mutex instead of pthread_mutex_t
authorJonathan Wakely <jwakely@redhat.com>
Fri, 11 Nov 2022 12:48:29 +0000 (12:48 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Sat, 19 Nov 2022 11:10:22 +0000 (11:10 +0000)
commit0a62889c7a155f8ed971860d68870dc9c46bb004
tree6f9cdbfaa40430d129e13cb35bbfe39a8e4481d4
parent8c05d8cd4300f74bf2698f0a6b96464b5be571be
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.
gcc/jit/jit-playback.cc
gcc/jit/jit-playback.h
gcc/jit/jit-recording.cc
gcc/jit/libgccjit.cc
gcc/system.h