[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[qemu-xen stable-4.13] coroutine: Add qemu_co_mutex_assert_locked()



commit e9bb3d942e268a19e03fc5d404586d2ed1564282
Author:     Kevin Wolf <kwolf@xxxxxxxxxx>
AuthorDate: Thu Oct 24 16:26:57 2019 +0200
Commit:     Michael Roth <mdroth@xxxxxxxxxxxxxxxxxx>
CommitDate: Wed Oct 30 11:34:26 2019 -0500

    coroutine: Add qemu_co_mutex_assert_locked()
    
    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: qemu-stable@xxxxxxxxxx
    Signed-off-by: Kevin Wolf <kwolf@xxxxxxxxxx>
    Tested-by: Michael Weiser <michael.weiser@xxxxxx>
    Reviewed-by: Michael Weiser <michael.weiser@xxxxxx>
    Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@xxxxxxxxxxxxx>
    Reviewed-by: Denis V. Lunev <den@xxxxxxxxxx>
    Reviewed-by: Max Reitz <mreitz@xxxxxxxxxx>
    (cherry picked from commit 944f3d5dd216fcd8cb007eddd4f82dced0a15b3d)
    Signed-off-by: Michael Roth <mdroth@xxxxxxxxxxxxxxxxxx>
---
 include/qemu/coroutine.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
index 9801e7f5a4..f4843b5f59 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
--
generated by git-patchbot for /home/xen/git/qemu-xen.git#stable-4.13



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.