From patchwork Fri Jan 11 10:30:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [V2,2/2] oslib-win32: add lock for localtime_r() From: Wayne Xia X-Patchwork-Id: 211293 Message-Id: <1357900227-5228-2-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 Date: Fri, 11 Jan 2013 18:30:27 +0800 Signed-off-by: Wenchao Xia --- v2: better comments and removed the code change localtime() to localtime_r(). --- oslib-win32.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/oslib-win32.c b/oslib-win32.c index 9a443da..aa1268c 100644 --- a/oslib-win32.c +++ b/oslib-win32.c @@ -90,15 +90,17 @@ struct tm *gmtime_r(const time_t *timep, struct tm *result) return p; } -/* FIXME: add proper locking */ +/* FIXME: make it thread safe in MinGW, remove the lock in qemu. */ struct tm *localtime_r(const time_t *timep, struct tm *result) { + g_static_mutex_lock(&time_lock); struct tm *p = localtime(timep); memset(result, 0, sizeof(*result)); if (p) { *result = *p; p = result; } + g_static_mutex_unlock(&time_lock); return p; }