From: José Fonseca Date: Sun, 31 May 2009 19:19:46 +0000 (-0700) Subject: Use critical sections. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=5a147cc01758906ad5c38689953614d39a82d8c0;p=apitrace Use critical sections. --- diff --git a/log.cpp b/log.cpp index 5df0266..1c1804f 100644 --- a/log.cpp +++ b/log.cpp @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright 2008 Tungsten Graphics, Inc. + * Copyright 2008-2009 VMware, Inc. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -23,6 +23,8 @@ #include #include +#include + #include #include "log.hpp" @@ -46,11 +48,13 @@ namespace Log { static gzFile g_gzFile = NULL; static char g_szFileName[PATH_MAX]; +static CRITICAL_SECTION CriticalSection; static void _Close(void) { if(g_gzFile != NULL) { gzclose(g_gzFile); g_gzFile = NULL; + DeleteCriticalSection(&CriticalSection); } } @@ -77,6 +81,7 @@ static void _Open(const char *szName, const char *szExtension) { } g_gzFile = gzopen(g_szFileName, "wb"); + InitializeCriticalSection(&CriticalSection); } static inline void _ReOpen(void) { @@ -224,6 +229,7 @@ void TextF(const char *format, ...) { } void BeginCall(const char *function) { + EnterCriticalSection(&CriticalSection); Indent(1); BeginTag("call", "name", function); NewLine(); @@ -234,6 +240,7 @@ void EndCall(void) { EndTag("call"); NewLine(); gzflush(g_gzFile, Z_SYNC_FLUSH); + LeaveCriticalSection(&CriticalSection); } void BeginArg(const char *type, const char *name) {