From patchwork Mon Jan 7 07:28:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 209879 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1AEA72C0087 for ; Mon, 7 Jan 2013 19:33:17 +1100 (EST) Received: from localhost ([::1]:36371 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ts7Ao-0005d1-0n for incoming@patchwork.ozlabs.org; Mon, 07 Jan 2013 02:31:06 -0500 Received: from eggs.gnu.org ([208.118.235.92]:35688) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ts7A9-0003xa-11 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 1Ts7A5-0005V8-Bs for qemu-devel@nongnu.org; Mon, 07 Jan 2013 02:30:24 -0500 Received: from e23smtp06.au.ibm.com ([202.81.31.148]:49505) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ts7A4-0005Up-Pl for qemu-devel@nongnu.org; Mon, 07 Jan 2013 02:30:21 -0500 Received: from /spool/local by e23smtp06.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 7 Jan 2013 17:26:38 +1000 Received: from d23dlp02.au.ibm.com (202.81.31.213) by e23smtp06.au.ibm.com (202.81.31.212) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 7 Jan 2013 17:26:36 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 98F582BB004B for ; Mon, 7 Jan 2013 18:30:15 +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 r077IjKt56361056 for ; Mon, 7 Jan 2013 18:18:47 +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 r077UC18021908 for ; Mon, 7 Jan 2013 18:30:12 +1100 Received: from RH63Wenchao (wenchaox.cn.ibm.com [9.115.122.237]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r077Rp6Y018491; Mon, 7 Jan 2013 18:30:10 +1100 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Mon, 7 Jan 2013 15:28:02 +0800 Message-Id: <1357543689-11415-5-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 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> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13010707-7014-0000-0000-0000026CDCCA X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.148 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 Subject: [Qemu-devel] [PATCH V2 04/10] oslib-win32: add lock for time functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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; }