From patchwork Wed Feb 18 11:56:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Dovgalyuk X-Patchwork-Id: 440946 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 25CD314007F for ; Wed, 18 Feb 2015 23:04:01 +1100 (AEDT) Received: from localhost ([::1]:50184 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YO3MF-00023q-9F for incoming@patchwork.ozlabs.org; Wed, 18 Feb 2015 07:03:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YO3El-0006oo-C5 for qemu-devel@nongnu.org; Wed, 18 Feb 2015 06:56:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YO3Ee-0002YH-DL for qemu-devel@nongnu.org; Wed, 18 Feb 2015 06:56:15 -0500 Received: from mail.ispras.ru ([83.149.199.45]:38188) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YO3Ee-0002Xk-6P for qemu-devel@nongnu.org; Wed, 18 Feb 2015 06:56:08 -0500 Received: from [10.10.150.136] (unknown [85.142.117.224]) by mail.ispras.ru (Postfix) with ESMTPSA id 11BD0540151; Wed, 18 Feb 2015 14:56:07 +0300 (MSK) To: qemu-devel@nongnu.org From: Pavel Dovgalyuk Date: Wed, 18 Feb 2015 14:56:09 +0300 Message-ID: <20150218115609.4176.60952.stgit@PASHA-ISP> In-Reply-To: <20150218115534.4176.12578.stgit@PASHA-ISP> References: <20150218115534.4176.12578.stgit@PASHA-ISP> User-Agent: StGit/0.16 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 83.149.199.45 Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com, alex.bennee@linaro.org, mark.burton@greensocs.com, real@ispras.ru, batuzovk@ispras.ru, maria.klimushenkova@ispras.ru, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, afaerber@suse.de, fred.konrad@greensocs.com Subject: [Qemu-devel] [RFC PATCH v9 05/23] replay: introduce mutex to protect the replay log X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- replay/replay-internal.c | 27 +++++++++++++++++++++++++++ replay/replay-internal.h | 7 +++++++ 2 files changed, 34 insertions(+), 0 deletions(-) diff --git a/replay/replay-internal.c b/replay/replay-internal.c index e905de8..ce7a1d8 100755 --- a/replay/replay-internal.c +++ b/replay/replay-internal.c @@ -15,6 +15,13 @@ unsigned int replay_data_kind = -1; 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; @@ -141,3 +148,23 @@ void replay_fetch_data_kind(void) } } } + +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 d1b7575..d92410e 100755 --- a/replay/replay-internal.h +++ b/replay/replay-internal.h @@ -34,6 +34,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);