This helper is necessary to ensure locking constraints. Signed-off-by: Denis V. Lunev <d...@openvz.org> CC: Stefan Hajnoczi <stefa...@redhat.com> CC: Paolo Bonzini <pbonz...@redhat.com> --- include/qemu/rfifolock.h | 1 + util/rfifolock.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/include/qemu/rfifolock.h b/include/qemu/rfifolock.h index b23ab53..1148cb0 100644 --- a/include/qemu/rfifolock.h +++ b/include/qemu/rfifolock.h @@ -50,5 +50,6 @@ void rfifolock_init(RFifoLock *r, void (*cb)(void *), void *opaque); void rfifolock_destroy(RFifoLock *r); void rfifolock_lock(RFifoLock *r); void rfifolock_unlock(RFifoLock *r); +bool rfifolock_is_owner(RFifoLock *r); #endif /* QEMU_RFIFOLOCK_H */ diff --git a/util/rfifolock.c b/util/rfifolock.c index afbf748..4533617 100644 --- a/util/rfifolock.c +++ b/util/rfifolock.c @@ -12,6 +12,7 @@ */ #include <assert.h> +#include <string.h> #include "qemu/rfifolock.h" void rfifolock_init(RFifoLock *r, void (*cb)(void *), void *opaque) @@ -48,7 +49,7 @@ void rfifolock_lock(RFifoLock *r) /* Take a ticket */ unsigned int ticket = r->tail++; - if (r->nesting > 0 && qemu_thread_is_self(&r->owner_thread)) { + if (rfifolock_is_owner(r)) { r->tail--; /* put ticket back, we're nesting */ } else { while (ticket != r->head) { @@ -68,11 +69,16 @@ void rfifolock_lock(RFifoLock *r) void rfifolock_unlock(RFifoLock *r) { qemu_mutex_lock(&r->lock); - assert(r->nesting > 0); - assert(qemu_thread_is_self(&r->owner_thread)); + assert(rfifolock_is_owner(r)); if (--r->nesting == 0) { + memset(&r->owner_thread, 0, sizeof(r->owner_thread)); r->head++; qemu_cond_broadcast(&r->cond); } qemu_mutex_unlock(&r->lock); } + +bool rfifolock_is_owner(RFifoLock *r) +{ + return r->nesting > 0 && qemu_thread_is_self(&r->owner_thread); +} -- 2.5.0