aboutsummaryrefslogtreecommitdiff
path: root/gcc/jit/jit-playback.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2014-12-09 18:51:04 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2014-12-09 18:51:04 +0000
commit38771e4e1fdacfbdac5a14e50fcc0538577b1bdb (patch)
treedcf6ca65f430649752f2bbeab9e80301f3820f24 /gcc/jit/jit-playback.c
parent38f4f64124c88933acc76325a256950d468022fa (diff)
downloadgcc-38771e4e1fdacfbdac5a14e50fcc0538577b1bdb.zip
gcc-38771e4e1fdacfbdac5a14e50fcc0538577b1bdb.tar.gz
gcc-38771e4e1fdacfbdac5a14e50fcc0538577b1bdb.tar.bz2
Guard less code with the JIT mutex
gcc/jit/ChangeLog: * jit-playback.c (gcc::jit::playback::context::compile): Acquire the mutex here, immediately before using toplev, and release it here, on each exit path after acquisition. (jit_mutex): Move this variable here, from jit-recording.c. (gcc::jit::playback::context::acquire_mutex): New function, based on code in jit-recording.c. (gcc::jit::playback::context::release_mutex): Likewise. * jit-playback.h (gcc::jit::playback::context::acquire_mutex): New function. (gcc::jit::playback::context::release_mutex): New function. * jit-recording.c (jit_mutex): Move this variable to jit-playback.c. (gcc::jit::recording::context::compile): Move mutex-handling from here into jit-playback.c's gcc::jit::playback::context::compile. * notes.txt: Update to show the new locations of ACQUIRE_MUTEX and RELEASE_MUTEX. From-SVN: r218528
Diffstat (limited to 'gcc/jit/jit-playback.c')
-rw-r--r--gcc/jit/jit-playback.c45
1 files changed, 42 insertions, 3 deletions
diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c
index a6de244..281ad85 100644
--- a/gcc/jit/jit-playback.c
+++ b/gcc/jit/jit-playback.c
@@ -1622,6 +1622,9 @@ compile ()
if (errors_occurred ())
return NULL;
+ /* Acquire the JIT mutex and set "this" as the active playback ctxt. */
+ acquire_mutex ();
+
/* This runs the compiler. */
toplev toplev (false);
toplev.main (fake_args.length (),
@@ -1635,25 +1638,61 @@ compile ()
/* Clean up the compiler. */
toplev.finalize ();
- active_playback_ctxt = NULL;
+ /* Ideally we would release the jit mutex here, but we can't yet since
+ followup activities use timevars, which are global state. */
if (errors_occurred ())
- return NULL;
+ {
+ release_mutex ();
+ return NULL;
+ }
if (get_bool_option (GCC_JIT_BOOL_OPTION_DUMP_GENERATED_CODE))
dump_generated_code ();
convert_to_dso (ctxt_progname);
if (errors_occurred ())
- return NULL;
+ {
+ release_mutex ();
+ return NULL;
+ }
result_obj = dlopen_built_dso ();
+ release_mutex ();
+
return result_obj;
}
/* Helper functions for gcc::jit::playback::context::compile. */
+/* 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;
+
+/* Acquire jit_mutex and set "this" as the active playback ctxt. */
+
+void
+playback::context::acquire_mutex ()
+{
+ /* Acquire the big GCC mutex. */
+ pthread_mutex_lock (&jit_mutex);
+ gcc_assert (NULL == active_playback_ctxt);
+ active_playback_ctxt = this;
+}
+
+/* Release jit_mutex and clear the active playback ctxt. */
+
+void
+playback::context::release_mutex ()
+{
+ /* Release the big GCC mutex. */
+ gcc_assert (active_playback_ctxt == this);
+ active_playback_ctxt = NULL;
+ pthread_mutex_unlock (&jit_mutex);
+}
+
/* Build a fake argv for toplev::main from the options set
by the user on the context . */