[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 02/15] job.c: make job_lock/unlock public
From: |
Emanuele Giuseppe Esposito |
Subject: |
[RFC PATCH 02/15] job.c: make job_lock/unlock public |
Date: |
Fri, 29 Oct 2021 12:39:01 -0400 |
job mutex will be used to protect the job struct elements and list,
replacing AioContext locks.
Right now use a shared lock for all jobs, in order to keep things
simple. Once the AioContext lock is gone, we can introduce per-job
locks.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
include/qemu/job-common.h | 18 ++++++++++++++++++
job.c | 12 +++++-------
2 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/include/qemu/job-common.h b/include/qemu/job-common.h
index c115028e33..dcc24fba48 100644
--- a/include/qemu/job-common.h
+++ b/include/qemu/job-common.h
@@ -297,4 +297,22 @@ typedef enum JobCreateFlags {
JOB_MANUAL_DISMISS = 0x04,
} JobCreateFlags;
+/**
+ * job_lock:
+ *
+ * Take the mutex protecting the list of jobs and their status.
+ * Most functions called by the monitor need to call job_lock
+ * and job_unlock manually. On the other hand, function called
+ * by the block jobs themselves and by the block layer will take the
+ * lock for you.
+ */
+void job_lock(void);
+
+/**
+ * job_unlock:
+ *
+ * Release the mutex protecting the list of jobs and their status.
+ */
+void job_unlock(void);
+
#endif
diff --git a/job.c b/job.c
index 94b142684f..e003f136f0 100644
--- a/job.c
+++ b/job.c
@@ -32,6 +32,9 @@
#include "trace/trace-root.h"
#include "qapi/qapi-events-job.h"
+/* job_mutex protects the jobs list, but also makes the job API thread-safe. */
+static QemuMutex job_mutex;
+
static QLIST_HEAD(, Job) jobs = QLIST_HEAD_INITIALIZER(jobs);
/* Job State Transition Table */
@@ -74,17 +77,12 @@ struct JobTxn {
int refcnt;
};
-/* Right now, this mutex is only needed to synchronize accesses to job->busy
- * and job->sleep_timer, such as concurrent calls to job_do_yield and
- * job_enter. */
-static QemuMutex job_mutex;
-
-static void job_lock(void)
+void job_lock(void)
{
qemu_mutex_lock(&job_mutex);
}
-static void job_unlock(void)
+void job_unlock(void)
{
qemu_mutex_unlock(&job_mutex);
}
--
2.27.0
- [RFC PATCH 00/15] job: replace AioContext lock with job_mutex, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 01/15] jobs: add job-common.h, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 02/15] job.c: make job_lock/unlock public,
Emanuele Giuseppe Esposito <=
- [RFC PATCH 03/15] job-common.h: categorize fields in struct Job, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 04/15] jobs: add job-monitor.h, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 05/15] job-monitor.h: define the job monitor API, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 06/15] jobs: add job-driver.h, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 09/15] job.c: move inner aiocontext lock in callbacks, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 07/15] job-driver.h: add helper functions, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 14/15] jobs: add missing job locks to replace aiocontext lock, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 15/15] jobs: remove all unnecessary AioContext locks, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 10/15] aio-wait.h: introduce AIO_WAIT_WHILE_UNLOCKED, Emanuele Giuseppe Esposito, 2021/10/29
- [RFC PATCH 13/15] jobs: use job locks and helpers also in the unit tests, Emanuele Giuseppe Esposito, 2021/10/29