[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH v8 05/21] replay: introduce mutex to protect the
From: |
Pavel Dovgalyuk |
Subject: |
[Qemu-devel] [RFC PATCH v8 05/21] replay: introduce mutex to protect the replay log |
Date: |
Thu, 22 Jan 2015 11:51:59 +0300 |
User-agent: |
StGit/0.16 |
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 <address@hidden>
---
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);
+}
+
+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);
[Qemu-devel] [RFC PATCH v8 06/21] replay: introduce icount event, Pavel Dovgalyuk, 2015/01/22
[Qemu-devel] [RFC PATCH v8 07/21] cpu-exec: allow temporary disabling icount, Pavel Dovgalyuk, 2015/01/22
[Qemu-devel] [RFC PATCH v8 08/21] cpu: replay instructions sequence, Pavel Dovgalyuk, 2015/01/22