From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39438) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zu0lG-0002pk-92 for qemu-devel@nongnu.org; Wed, 04 Nov 2015 11:18:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zu0lC-0001yO-7m for qemu-devel@nongnu.org; Wed, 04 Nov 2015 11:18:10 -0500 Received: from mail-wi0-x231.google.com ([2a00:1450:400c:c05::231]:34105) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zu0lC-0001yI-1I for qemu-devel@nongnu.org; Wed, 04 Nov 2015 11:18:06 -0500 Received: by wikq8 with SMTP id q8so95500776wik.1 for ; Wed, 04 Nov 2015 08:18:05 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Wed, 4 Nov 2015 17:17:41 +0100 Message-Id: <1446653876-116008-4-git-send-email-pbonzini@redhat.com> In-Reply-To: <1446653876-116008-1-git-send-email-pbonzini@redhat.com> References: <1446653876-116008-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 03/18] replay: introduce mutex to protect the replay log List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Pavel Dovgalyuk From: Pavel Dovgalyuk This mutex will protect read/write operations for replay log. Using mutex is necessary because most of the events consist of several fields stored in the log. The mutex will help to avoid races. Reviewed-by: Paolo Bonzini Signed-off-by: Pavel Dovgalyuk Message-Id: <20150917162348.8676.8628.stgit@PASHA-ISP.def.inno> Signed-off-by: Paolo Bonzini --- replay/replay-internal.c | 27 +++++++++++++++++++++++++++ replay/replay-internal.h | 7 +++++++ 2 files changed, 34 insertions(+) diff --git a/replay/replay-internal.c b/replay/replay-internal.c index 04efeee..efae672 100644 --- a/replay/replay-internal.c +++ b/replay/replay-internal.c @@ -17,6 +17,13 @@ unsigned int replay_data_kind = -1; static unsigned int replay_has_unread_data; +/* Mutex to protect reading and writing events to the log. + replay_data_kind and replay_has_unread_data are also protected + by this mutex. + It also protects replay events queue which stores events to be + written or read to the log. */ +static QemuMutex lock; + /* File for replay writing */ FILE *replay_file; @@ -153,3 +160,23 @@ void replay_finish_event(void) replay_has_unread_data = 0; replay_fetch_data_kind(); } + +void replay_mutex_init(void) +{ + qemu_mutex_init(&lock); +} + +void replay_mutex_destroy(void) +{ + qemu_mutex_destroy(&lock); +} + +void replay_mutex_lock(void) +{ + qemu_mutex_lock(&lock); +} + +void replay_mutex_unlock(void) +{ + qemu_mutex_unlock(&lock); +} diff --git a/replay/replay-internal.h b/replay/replay-internal.h index 17600de..8a0de0d 100644 --- a/replay/replay-internal.h +++ b/replay/replay-internal.h @@ -33,6 +33,13 @@ int64_t replay_get_qword(void); void replay_get_array(uint8_t *buf, size_t *size); void replay_get_array_alloc(uint8_t **buf, size_t *size); +/* Mutex functions for protecting replay log file */ + +void replay_mutex_init(void); +void replay_mutex_destroy(void); +void replay_mutex_lock(void); +void replay_mutex_unlock(void); + /*! Checks error status of the file. */ void replay_check_error(void); -- 1.8.3.1