hedgewars/uUtils.pas
changeset 7180 53ffc8853008
parent 7151 ec15d9e1a7e3
child 7194 d8e68cbca7ee
--- a/hedgewars/uUtils.pas	Mon Jun 04 08:11:47 2012 -0400
+++ b/hedgewars/uUtils.pas	Mon Jun 04 21:32:30 2012 +0400
@@ -60,6 +60,7 @@
 function  CheckCJKFont(s: ansistring; font: THWFont): THWFont;
 
 procedure AddFileLog(s: shortstring);
+procedure AddFileLogRaw(s: pchar); cdecl;
 
 function  CheckNoTeamOrHH: boolean; inline;
 
@@ -80,6 +81,7 @@
 
 {$IFDEF DEBUGFILE}
 var f: textfile;
+    logMutex: TRTLCriticalSection; // mutex for debug file
 {$ENDIF}
 var CharArray: array[byte] of Char;
 
@@ -297,11 +299,23 @@
 begin
 s:= s;
 {$IFDEF DEBUGFILE}
+EnterCriticalSection(logMutex);
 writeln(f, inttostr(GameTicks)  + ': ' + s);
-flush(f)
+flush(f);
+LeaveCriticalSection(logMutex);
 {$ENDIF}
 end;
 
+procedure AddFileLogRaw(s: pchar); cdecl;
+begin
+s:= s;
+{$IFDEF DEBUGFILE}
+EnterCriticalSection(logMutex);
+write(f, s);
+flush(f);
+LeaveCriticalSection(logMutex);
+{$ENDIF}
+end;
 
 function CheckCJKFont(s: ansistring; font: THWFont): THWFont;
 var l, i : LongInt;
@@ -394,6 +408,7 @@
         logfileBase:= 'game'
     else
         logfileBase:= 'preview';
+    InitCriticalSection(logMutex);
 {$I-}
 {$IFDEF MOBILE}
     {$IFDEF IPHONEOS} Assign(f,'../Documents/hw-' + logfileBase + '.log'); {$ENDIF}
@@ -430,6 +445,7 @@
     writeln(f, 'halt at ' + inttostr(GameTicks) + ' ticks. TurnTimeLeft = ' + inttostr(TurnTimeLeft));
     flush(f);
     close(f);
+    DoneCriticalSection(logMutex);
 {$ENDIF}
 end;