From patchwork Mon Jan 7 07:28:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 209874 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 439002C007E for ; Mon, 7 Jan 2013 18:54:52 +1100 (EST) Received: from localhost ([::1]:36735 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ts7B8-0005ox-Uu for incoming@patchwork.ozlabs.org; Mon, 07 Jan 2013 02:31:26 -0500 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 d23dlp01.au.ibm.com (202.81.31.203) by e23smtp05.au.ibm.com (202.81.31.211) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 7 Jan 2013 17:27:12 +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 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 r077Rp6Z018491; Mon, 7 Jan 2013 18:30:13 +1100 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Mon, 7 Jan 2013 15:28:03 +0800 Message-Id: <1357543689-11415-6-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-1396-0000-0000-000002615FA2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.147 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; }