<http://www.gnu.org/licenses/>. */
#include "config.h"
-#define INCLUDE_PTHREAD_H
+#define INCLUDE_MUTEX
#include "system.h"
#include "coretypes.h"
#include "target.h"
m_label_expr = NULL;
}
+// This is basically std::lock_guard but it can call the private lock/unlock
+// members of playback::context.
+struct playback::context::scoped_lock
+{
+ scoped_lock (context &ctx) : m_ctx (&ctx) { m_ctx->lock (); }
+ ~scoped_lock () { m_ctx->unlock (); }
+
+ context *m_ctx;
+
+ // Not movable or copyable.
+ scoped_lock (scoped_lock &&) = delete;
+ scoped_lock &operator= (scoped_lock &&) = delete;
+};
+
/* Compile a playback::context:
- Use the context's options to cconstruct command-line options, and
m_recording_ctxt->get_all_requested_dumps (&requested_dumps);
/* Acquire the JIT mutex and set "this" as the active playback ctxt. */
- acquire_mutex ();
+ scoped_lock lock(*this);
auto_string_vec fake_args;
make_fake_args (&fake_args, ctxt_progname, &requested_dumps);
if (errors_occurred ())
- {
- release_mutex ();
- return;
- }
+ return;
/* This runs the compiler. */
toplev toplev (get_timer (), /* external_timer */
followup activities use timevars, which are global state. */
if (errors_occurred ())
- {
- release_mutex ();
- return;
- }
+ return;
if (get_bool_option (GCC_JIT_BOOL_OPTION_DUMP_GENERATED_CODE))
dump_generated_code ();
convert the .s file to the requested output format, and copy it to a
given file (playback::compile_to_file). */
postprocess (ctxt_progname);
-
- release_mutex ();
}
/* Implementation of class gcc::jit::playback::compile_to_memory,
/* This mutex guards gcc::jit::recording::context::compile, so that only
one thread can be accessing the bulk of GCC's state at once. */
-static pthread_mutex_t jit_mutex = PTHREAD_MUTEX_INITIALIZER;
+static std::mutex jit_mutex;
/* Acquire jit_mutex and set "this" as the active playback ctxt. */
void
-playback::context::acquire_mutex ()
+playback::context::lock ()
{
auto_timevar tv (get_timer (), TV_JIT_ACQUIRING_MUTEX);
/* Acquire the big GCC mutex. */
JIT_LOG_SCOPE (get_logger ());
- pthread_mutex_lock (&jit_mutex);
+ jit_mutex.lock ();
gcc_assert (active_playback_ctxt == NULL);
active_playback_ctxt = this;
}
/* Release jit_mutex and clear the active playback ctxt. */
void
-playback::context::release_mutex ()
+playback::context::unlock ()
{
/* Release the big GCC mutex. */
JIT_LOG_SCOPE (get_logger ());
gcc_assert (active_playback_ctxt == this);
active_playback_ctxt = NULL;
- pthread_mutex_unlock (&jit_mutex);
+ jit_mutex.unlock ();
}
/* Callback used by gcc::jit::playback::context::make_fake_args when
<http://www.gnu.org/licenses/>. */
#include "config.h"
-#define INCLUDE_PTHREAD_H
+#define INCLUDE_MUTEX
#include "system.h"
#include "coretypes.h"
#include "timevar.h"
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
{
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;