From: Elena Afanasova <eafanasova@gmail.com>
To: jsnow@redhat.com
Cc: qemu-trivial@nongnu.org, Elena Afanasova <eafanasova@gmail.com>,
qemu-devel@nongnu.org, qemu-block@nongnu.org
Subject: [PATCH] job: delete job_{lock, unlock} functions and replace them with lock guard
Date: Tue, 29 Sep 2020 06:42:14 -0700 [thread overview]
Message-ID: <20200929134214.4103-1-eafanasova@gmail.com> (raw)
Signed-off-by: Elena Afanasova <eafanasova@gmail.com>
---
job.c | 46 +++++++++++++++++-----------------------------
1 file changed, 17 insertions(+), 29 deletions(-)
diff --git a/job.c b/job.c
index 8fecf38960..89ceb53434 100644
--- a/job.c
+++ b/job.c
@@ -79,16 +79,6 @@ struct JobTxn {
* job_enter. */
static QemuMutex job_mutex;
-static void job_lock(void)
-{
- qemu_mutex_lock(&job_mutex);
-}
-
-static void job_unlock(void)
-{
- qemu_mutex_unlock(&job_mutex);
-}
-
static void __attribute__((__constructor__)) job_init(void)
{
qemu_mutex_init(&job_mutex);
@@ -437,21 +427,19 @@ void job_enter_cond(Job *job, bool(*fn)(Job *job))
return;
}
- job_lock();
- if (job->busy) {
- job_unlock();
- return;
- }
+ WITH_QEMU_LOCK_GUARD(&job_mutex) {
+ if (job->busy) {
+ return;
+ }
- if (fn && !fn(job)) {
- job_unlock();
- return;
- }
+ if (fn && !fn(job)) {
+ return;
+ }
- assert(!job->deferred_to_main_loop);
- timer_del(&job->sleep_timer);
- job->busy = true;
- job_unlock();
+ assert(!job->deferred_to_main_loop);
+ timer_del(&job->sleep_timer);
+ job->busy = true;
+ }
aio_co_enter(job->aio_context, job->co);
}
@@ -468,13 +456,13 @@ void job_enter(Job *job)
* called explicitly. */
static void coroutine_fn job_do_yield(Job *job, uint64_t ns)
{
- job_lock();
- if (ns != -1) {
- timer_mod(&job->sleep_timer, ns);
+ WITH_QEMU_LOCK_GUARD(&job_mutex) {
+ if (ns != -1) {
+ timer_mod(&job->sleep_timer, ns);
+ }
+ job->busy = false;
+ job_event_idle(job);
}
- job->busy = false;
- job_event_idle(job);
- job_unlock();
qemu_coroutine_yield();
/* Set by job_enter_cond() before re-entering the coroutine. */
--
2.25.1
next reply other threads:[~2020-09-29 14:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-29 13:42 Elena Afanasova [this message]
2020-09-29 18:04 ` [PATCH] job: delete job_{lock, unlock} functions and replace them with lock guard John Snow
2020-09-30 12:15 ` [PATCH] job: delete job_{lock,unlock} " Elena Afanasova
2020-09-30 13:17 ` [PATCH] job: delete job_{lock, unlock} " Paolo Bonzini
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=20200929134214.4103-1-eafanasova@gmail.com \
--to=eafanasova@gmail.com \
--cc=jsnow@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/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 NNTP newsgroup(s).