From patchwork Wed Jan 9 06:18:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 210628 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 DA9B82C00D2 for ; Wed, 9 Jan 2013 17:20:31 +1100 (EST) Received: from localhost ([::1]:57875 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tsp1Z-0000SG-Id for incoming@patchwork.ozlabs.org; Wed, 09 Jan 2013 01:20:29 -0500 Received: from eggs.gnu.org ([208.118.235.92]:36861) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tsp1P-0000R5-RL for qemu-devel@nongnu.org; Wed, 09 Jan 2013 01:20:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tsp1O-0000Yd-Nn for qemu-devel@nongnu.org; Wed, 09 Jan 2013 01:20:19 -0500 Received: from e28smtp01.in.ibm.com ([122.248.162.1]:52539) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tsp1O-0000Xv-0e for qemu-devel@nongnu.org; Wed, 09 Jan 2013 01:20:18 -0500 Received: from /spool/local by e28smtp01.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 9 Jan 2013 11:48:52 +0530 Received: from d28dlp02.in.ibm.com (9.184.220.127) by e28smtp01.in.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 9 Jan 2013 11:48:50 +0530 Received: from d28relay01.in.ibm.com (d28relay01.in.ibm.com [9.184.220.58]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id 2CF2F3940051 for ; Wed, 9 Jan 2013 11:50:10 +0530 (IST) Received: from d28av03.in.ibm.com (d28av03.in.ibm.com [9.184.220.65]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r096K7V719857438 for ; Wed, 9 Jan 2013 11:50:07 +0530 Received: from d28av03.in.ibm.com (loopback [127.0.0.1]) by d28av03.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r096K8ch010995 for ; Wed, 9 Jan 2013 17:20:09 +1100 Received: from RH63Wenchao ([9.77.181.189]) by d28av03.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r096IE7x004003; Wed, 9 Jan 2013 17:20:04 +1100 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Wed, 9 Jan 2013 14:18:09 +0800 Message-Id: <1357712290-16496-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13010906-4790-0000-0000-0000065D22D2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.1 Cc: pbonzini@redhat.com, aliguori@us.ibm.com, quintela@redhat.com, Wenchao Xia , stefanha@gmail.com Subject: [Qemu-devel] [PATCH 1/2] oslib-win32: add lock for gmtime_r() 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 Also changed the caller of gmtime() to gmtime_r(). Signed-off-by: Wenchao Xia --- oslib-win32.c | 6 +++++- vl.c | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/oslib-win32.c b/oslib-win32.c index e7e283e..74e0c52 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: add proper locking in MinGW */ 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; } diff --git a/vl.c b/vl.c index 79e5122..8d7864c 100644 --- a/vl.c +++ b/vl.c @@ -454,12 +454,12 @@ void qemu_get_timedate(struct tm *tm, int offset) ti += offset; if (rtc_date_offset == -1) { if (rtc_utc) - ret = gmtime(&ti); + ret = gmtime_r(&ti, tm); else ret = localtime(&ti); } else { ti -= rtc_date_offset; - ret = gmtime(&ti); + ret = gmtime_r(&ti, tm); } memcpy(tm, ret, sizeof(struct tm));