From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54436) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1HvA-0001as-OG for qemu-devel@nongnu.org; Tue, 24 Nov 2015 13:02:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1Hv9-000629-QQ for qemu-devel@nongnu.org; Tue, 24 Nov 2015 13:02:28 -0500 From: Paolo Bonzini Date: Tue, 24 Nov 2015 19:01:18 +0100 Message-Id: <1448388091-117282-28-git-send-email-pbonzini@redhat.com> In-Reply-To: <1448388091-117282-1-git-send-email-pbonzini@redhat.com> References: <1448388091-117282-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 27/40] aio: document locking List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, 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 26aa658..21044af 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -50,18 +50,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. */ QemuRecMutex 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 @@ -87,9 +81,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; @@ -111,10 +105,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; int external_disable_cnt; -- 1.8.3.1