From patchwork Fri Jan 11 10:30:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [V2,1/2] oslib-win32: add lock for gmtime_r() Date: Fri, 11 Jan 2013 00:30:26 -0000 From: Wayne Xia X-Patchwork-Id: 211292 Message-Id: <1357900227-5228-1-git-send-email-xiawenc@linux.vnet.ibm.com> To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, quintela@redhat.com, stefanha@gmail.com, sw@weilnetz.de, pbonzini@redhat.com, Wenchao Xia Signed-off-by: Wenchao Xia --- v2: better comments and removed the code change gmtime() to gmtime_r(). --- oslib-win32.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/oslib-win32.c b/oslib-win32.c index e7e283e..9a443da 100644 --- a/oslib-win32.c +++ b/oslib-win32.c @@ -32,6 +32,8 @@ #include "trace.h" #include "qemu/sockets.h" +static GStaticMutex time_lock = G_STATIC_MUTEX_INIT; + void *qemu_oom_check(void *ptr) { if (ptr == NULL) { @@ -74,15 +76,17 @@ void qemu_vfree(void *ptr) VirtualFree(ptr, 0, MEM_RELEASE); } -/* FIXME: add proper locking */ +/* FIXME: make it thread safe in MinGW, remove the lock in qemu. */ struct tm *gmtime_r(const time_t *timep, struct tm *result) { + g_static_mutex_lock(&time_lock); struct tm *p = gmtime(timep); memset(result, 0, sizeof(*result)); if (p) { *result = *p; p = result; } + g_static_mutex_unlock(&time_lock); return p; }