[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH V2 04/10] oslib-win32: add lock for time functions
From: |
Wenchao Xia |
Subject: |
[Qemu-devel] [PATCH V2 04/10] oslib-win32: add lock for time functions |
Date: |
Mon, 7 Jan 2013 15:28:03 +0800 |
This patch adding lock for calling gmtime() and localtime()
on windows. If no other lib linked into qemu would call those
two function itself, then they are thread safe now on windows.
Signed-off-by: Wenchao Xia <address@hidden>
---
oslib-win32.c | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/oslib-win32.c b/oslib-win32.c
index e7e283e..344e3dd 100644
--- a/oslib-win32.c
+++ b/oslib-win32.c
@@ -74,27 +74,35 @@ void qemu_vfree(void *ptr)
VirtualFree(ptr, 0, MEM_RELEASE);
}
-/* FIXME: add proper locking */
+/* WARN: if other lib call gmtime() itself, then it is not thread safe. */
struct tm *gmtime_r(const time_t *timep, struct tm *result)
{
+ static GStaticMutex lock = G_STATIC_MUTEX_INIT;
+
+ g_static_mutex_lock(&lock);
struct tm *p = gmtime(timep);
memset(result, 0, sizeof(*result));
if (p) {
*result = *p;
p = result;
}
+ g_static_mutex_unlock(&lock);
return p;
}
-/* FIXME: add proper locking */
+/* WARN: if other lib call localtime() itself, then it is not thread safe. */
struct tm *localtime_r(const time_t *timep, struct tm *result)
{
+ static GStaticMutex lock = G_STATIC_MUTEX_INIT;
+
+ g_static_mutex_lock(&lock);
struct tm *p = localtime(timep);
memset(result, 0, sizeof(*result));
if (p) {
*result = *p;
p = result;
}
+ g_static_mutex_unlock(&lock);
return p;
}
--
1.7.1
- [Qemu-devel] [PATCH V2 00/10] snapshot: take block snapshots in unified way, Wenchao Xia, 2013/01/07
- [Qemu-devel] [PATCH V2 02/10] block: add function deappend(), Wenchao Xia, 2013/01/07
- [Qemu-devel] [PATCH V2 03/10] error: add function error_set_check(), Wenchao Xia, 2013/01/07
- [Qemu-devel] [PATCH V2 01/10] block: export function bdrv_find_snapshot(), Wenchao Xia, 2013/01/07
- [Qemu-devel] [PATCH V2 04/10] oslib-win32: add lock for time functions, Wenchao Xia, 2013/01/07
- [Qemu-devel] [PATCH V2 04/10] oslib-win32: add lock for time functions,
Wenchao Xia <=
- [Qemu-devel] [PATCH V2 06/10] snapshot: implemention of internal common API to take snapshots, Wenchao Xia, 2013/01/07
- [Qemu-devel] [PATCH V2 09/10] snapshot: qmp add blockdev-snapshot-internal-sync interface, Wenchao Xia, 2013/01/07
- [Qemu-devel] [PATCH V2 05/10] snapshot: design of internal common API to take snapshots, Wenchao Xia, 2013/01/07
- [Qemu-devel] [PATCH V2 10/10] snapshot: hmp add internal snapshot support for block device, Wenchao Xia, 2013/01/07
- [Qemu-devel] [PATCH V2 07/10] snapshot: qmp use new internal API for external snapshot transaction, Wenchao Xia, 2013/01/07