From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:35686) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ts7A9-0003xM-2w for qemu-devel@nongnu.org; Mon, 07 Jan 2013 02:30:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ts7A7-0005VU-Nu for qemu-devel@nongnu.org; Mon, 07 Jan 2013 02:30:24 -0500 Received: from e23smtp05.au.ibm.com ([202.81.31.147]:47367) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ts7A7-0005VJ-3j for qemu-devel@nongnu.org; Mon, 07 Jan 2013 02:30:23 -0500 Received: from /spool/local by e23smtp05.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 7 Jan 2013 17:27:15 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 261D32CE804A for ; Mon, 7 Jan 2013 18:30:18 +1100 (EST) Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r077IoHP66650130 for ; Mon, 7 Jan 2013 18:18:50 +1100 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r077UFdX022170 for ; Mon, 7 Jan 2013 18:30:15 +1100 From: Wenchao Xia Date: Mon, 7 Jan 2013 15:28:03 +0800 Message-Id: <1357543689-11415-6-git-send-email-xiawenc@linux.vnet.ibm.com> In-Reply-To: <1357543689-11415-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1357543689-11415-1-git-send-email-xiawenc@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH V2 04/10] oslib-win32: add lock for time functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, aliguori@us.ibm.com, quintela@redhat.com, stefanha@gmail.com, Wenchao Xia , lcapitulino@redhat.com, pbonzini@redhat.com, dietmar@proxmox.com 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 --- 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