From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52922) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGmAL-0003yB-DL for qemu-devel@nongnu.org; Thu, 29 Jan 2015 05:17:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YGmAK-0000ZM-EQ for qemu-devel@nongnu.org; Thu, 29 Jan 2015 05:17:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51505) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGmAK-0000YK-4Z for qemu-devel@nongnu.org; Thu, 29 Jan 2015 05:17:36 -0500 Message-ID: <54C9F98A.4060205@redhat.com> Date: Thu, 29 Jan 2015 10:12:42 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <20150122085127.5276.53895.stgit@PASHA-ISP.def.inno> <20150122085158.5276.29044.stgit@PASHA-ISP.def.inno> In-Reply-To: <20150122085158.5276.29044.stgit@PASHA-ISP.def.inno> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC PATCH v8 05/21] replay: introduce mutex to protect the replay log List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Pavel Dovgalyuk , qemu-devel@nongnu.org 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, afaerber@suse.de, fred.konrad@greensocs.com On 22/01/2015 09:51, Pavel Dovgalyuk wrote: > 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. > > Signed-off-by: Pavel Dovgalyuk > --- > replay/replay-internal.c | 25 +++++++++++++++++++++++++ > replay/replay-internal.h | 7 +++++++ > 2 files changed, 32 insertions(+), 0 deletions(-) > > diff --git a/replay/replay-internal.c b/replay/replay-internal.c > index 3865fa5..f552dad 100755 > --- a/replay/replay-internal.c > +++ b/replay/replay-internal.c > @@ -15,6 +15,11 @@ > 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. */ > +static QemuMutex lock; > + > /* File for replay writing */ > FILE *replay_file; > > @@ -139,3 +144,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); > +} Destroy is probably not necessary. > +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 dad5bc8..50ce29b 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); > > Reviewed-by: Paolo Bonzini