From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: LIU Hao <lh_mouse@126.com>
Cc: Andrew Pinski <pinskia@gmail.com>,
gcc@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: Re: why does gccgit require pthread?
Date: Mon, 7 Nov 2022 12:57:44 +0000 [thread overview]
Message-ID: <CAH6eHdTh4AhabR1o1pF6-wyTgH-59W_ZLPnspe=ytO_4UY3LEQ@mail.gmail.com> (raw)
In-Reply-To: <98c69fc7-713f-a09a-8ca7-c3e64bdfd309@126.com>
On Mon, 7 Nov 2022 at 06:51, LIU Hao via Gcc <gcc@gcc.gnu.org> wrote:
>
> 在 2022-11-07 12:37, Andrew Pinski 写道:
> >
> > The original code which used pthread was added in GCC 5 way before GCC
> > moved to being written in C++11 which was only in the last 3 years.
> > pthread_* functions were the best choice at the time (2014) but now
> > GCC is written in C++11, I don't see any reason not to move them over
> > to using C++11 threading code.
> >
> >
>
> Attached is the proposed patch.
It would be a lot nicer if playback::context met the C++ Lockable
requirements, and playback::context::compile () could just take a
scoped lock on *this:
--- a/gcc/jit/jit-playback.cc
+++ b/gcc/jit/jit-playback.cc
@@ -2353,15 +2353,12 @@ compile ()
m_recording_ctxt->get_all_requested_dumps (&requested_dumps);
/* Acquire the JIT mutex and set "this" as the active playback ctxt. */
- acquire_mutex ();
+ std::lock_guard<context> 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 */
@@ -2388,10 +2385,7 @@ compile ()
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 ();
@@ -2403,8 +2397,6 @@ compile ()
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,
@@ -2662,18 +2654,18 @@ playback::compile_to_file::copy_file (const
char *src_path,
/* 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;
}
@@ -2681,13 +2673,13 @@ playback::context::acquire_mutex ()
/* 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
diff --git a/gcc/jit/jit-playback.h b/gcc/jit/jit-playback.h
index 3ba02a0451a..bd2bc389f53 100644
--- a/gcc/jit/jit-playback.h
+++ b/gcc/jit/jit-playback.h
@@ -314,8 +314,8 @@ private:
/* Functions for implementing "compile". */
- void acquire_mutex ();
- void release_mutex ();
+ void lock ();
+ void unlock ();
void
make_fake_args (vec <char *> *argvec,
next prev parent reply other threads:[~2022-11-07 12:57 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <8f15b063-9ec8-59e0-590b-20e416f68cb4@126.com>
[not found] ` <CA+=Sn1ncp6hN8MnziZ+2f-6_UUqMwXeVGQLmft2NUeuXGOaBoA@mail.gmail.com>
2022-11-07 6:50 ` LIU Hao
2022-11-07 7:03 ` Andrew Pinski
2022-11-07 7:10 ` LIU Hao
2022-11-07 12:57 ` Jonathan Wakely [this message]
2022-11-07 13:33 ` LIU Hao
2022-11-07 13:51 ` Jonathan Wakely
2022-11-11 17:16 ` Jonathan Wakely
2022-11-11 18:27 ` Jonathan Wakely
2022-11-14 10:54 ` LIU Hao
2022-11-15 18:50 ` why does gcc jit " David Malcolm
2022-11-15 19:01 ` Jonathan Wakely
2022-11-19 11:27 ` Jonathan Wakely
2022-11-19 12:51 ` LIU Hao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAH6eHdTh4AhabR1o1pF6-wyTgH-59W_ZLPnspe=ytO_4UY3LEQ@mail.gmail.com' \
--to=jwakely.gcc@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=gcc@gcc.gnu.org \
--cc=lh_mouse@126.com \
--cc=pinskia@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).