From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41023) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZNLo4-0005QN-Ar for qemu-devel@nongnu.org; Thu, 06 Aug 2015 10:06:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZNLnz-0000bi-IX for qemu-devel@nongnu.org; Thu, 06 Aug 2015 10:06:04 -0400 From: Paolo Bonzini Date: Thu, 6 Aug 2015 15:36:06 +0200 Message-Id: <1438868176-20364-9-git-send-email-pbonzini@redhat.com> In-Reply-To: <1438868176-20364-1-git-send-email-pbonzini@redhat.com> References: <1438868176-20364-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 08/18] aio: document locking List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, famz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org Signed-off-by: Paolo Bonzini --- docs/multiple-iothreads.txt | 5 ++--- include/block/aio.h | 24 +++++++++++------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/docs/multiple-iothreads.txt b/docs/multiple-iothreads.txt index 723cc7e..4197f62 100644 --- a/docs/multiple-iothreads.txt +++ b/docs/multiple-iothreads.txt @@ -84,9 +84,8 @@ How to synchronize with an IOThread AioContext is not thread-safe so some rules must be followed when using file descriptors, event notifiers, timers, or BHs across threads: -1. AioContext functions can be called safely from file descriptor, event -notifier, timer, or BH callbacks invoked by the AioContext. No locking is -necessary. +1. AioContext functions can always be called safely. They handle their +own locking internally. 2. Other threads wishing to access the AioContext must use aio_context_acquire()/aio_context_release() for mutual exclusion. Once the diff --git a/include/block/aio.h b/include/block/aio.h index 3988d28..5d4ca01 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -51,18 +51,12 @@ typedef void IOHandler(void *opaque); struct AioContext { GSource source; - /* Protects all fields from multi-threaded access */ + /* Used by AioContext users to protect from multi-threaded access. */ RFifoLock lock; - /* The list of registered AIO handlers */ + /* The list of registered AIO handlers. Protected by ctx->list_lock. */ QLIST_HEAD(, AioHandler) aio_handlers; - /* This is a simple lock used to protect the aio_handlers list. - * Specifically, it's used to ensure that no callbacks are removed while - * we're walking and dispatching callbacks. - */ - int walking_handlers; - /* Used to avoid unnecessary event_notifier_set calls in aio_notify; * accessed with atomic primitives. If this field is 0, everything * (file descriptors, bottom halves, timers) will be re-evaluated @@ -88,9 +82,9 @@ struct AioContext { */ uint32_t notify_me; - /* A lock to protect between bh's adders and deleter, and to ensure - * that no callbacks are removed while we're walking and dispatching - * them. + /* A lock to protect between QEMUBH and AioHandler adders and deleter, + * and to ensure that no callbacks are removed while we're walking and + * dispatching them. */ QemuLockCnt list_lock; @@ -112,10 +106,14 @@ struct AioContext { bool notified; EventNotifier notifier; - /* Thread pool for performing work and receiving completion callbacks */ + /* Thread pool for performing work and receiving completion callbacks. + * Has its own locking. + */ struct ThreadPool *thread_pool; - /* TimerLists for calling timers - one per clock type */ + /* TimerLists for calling timers - one per clock type. Has its own + * locking. + */ QEMUTimerListGroup tlg; }; -- 2.4.3