[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 6/7] coroutine: Add qemu_co_mutex_assert_locked()
From: |
Kevin Wolf |
Subject: |
[PULL 6/7] coroutine: Add qemu_co_mutex_assert_locked() |
Date: |
Fri, 25 Oct 2019 15:46:10 +0200 |
Some functions require that the caller holds a certain CoMutex for them
to operate correctly. Add a function so that they can assert the lock is
really held.
Cc: address@hidden
Signed-off-by: Kevin Wolf <address@hidden>
Tested-by: Michael Weiser <address@hidden>
Reviewed-by: Michael Weiser <address@hidden>
Reviewed-by: Vladimir Sementsov-Ogievskiy <address@hidden>
Reviewed-by: Denis V. Lunev <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
---
include/qemu/coroutine.h | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
index 8d55663062..dfd261c5b1 100644
--- a/include/qemu/coroutine.h
+++ b/include/qemu/coroutine.h
@@ -167,6 +167,21 @@ void coroutine_fn qemu_co_mutex_lock(CoMutex *mutex);
*/
void coroutine_fn qemu_co_mutex_unlock(CoMutex *mutex);
+/**
+ * Assert that the current coroutine holds @mutex.
+ */
+static inline coroutine_fn void qemu_co_mutex_assert_locked(CoMutex *mutex)
+{
+ /*
+ * mutex->holder doesn't need any synchronisation if the assertion holds
+ * true because the mutex protects it. If it doesn't hold true, we still
+ * don't mind if another thread takes or releases mutex behind our back,
+ * because the condition will be false no matter whether we read NULL or
+ * the pointer for any other coroutine.
+ */
+ assert(atomic_read(&mutex->locked) &&
+ mutex->holder == qemu_coroutine_self());
+}
/**
* CoQueues are a mechanism to queue coroutines in order to continue executing
--
2.20.1
- [PULL 0/7] Block layer patches, Kevin Wolf, 2019/10/25
- [PULL 2/7] iotests: Skip read-only cases in 118 when run as root, Kevin Wolf, 2019/10/25
- [PULL 4/7] block/backup: drop dead code from backup_job_create, Kevin Wolf, 2019/10/25
- [PULL 1/7] qapi: add support for blkreplay driver, Kevin Wolf, 2019/10/25
- [PULL 5/7] doc: Describe missing generic -blockdev options, Kevin Wolf, 2019/10/25
- [PULL 3/7] blockdev: Use error_report() in hmp_commit(), Kevin Wolf, 2019/10/25
- [PULL 7/7] qcow2: Fix corruption bug in qcow2_detect_metadata_preallocation(), Kevin Wolf, 2019/10/25
- [PULL 6/7] coroutine: Add qemu_co_mutex_assert_locked(),
Kevin Wolf <=
- Re: [PULL 0/7] Block layer patches, Peter Maydell, 2019/10/25