summaryrefslogtreecommitdiff
path: root/replay/replay-internal.c
diff options
context:
space:
mode:
authorPavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>2015-09-17 19:23:48 +0300
committerPaolo Bonzini <pbonzini@redhat.com>2015-11-05 12:19:09 +0100
commitc16861ef1b7b27803b4c068ef778ba0f80fba1c2 (patch)
treef550dd82ac16446d302808993e548087eb1ea3f8 /replay/replay-internal.c
parentc92079f45fec0bc6a2757aa3783dd9b0604089ba (diff)
downloadqemu-c16861ef1b7b27803b4c068ef778ba0f80fba1c2.tar.gz
replay: introduce mutex to protect the replay log
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 <pbonzini@redhat.com> Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru> Message-Id: <20150917162348.8676.8628.stgit@PASHA-ISP.def.inno> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'replay/replay-internal.c')
-rw-r--r--replay/replay-internal.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/replay/replay-internal.c b/replay/replay-internal.c
index 04efeee920..efae672dfa 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);
+}