Index: trunk/src/kernel32/dbglog.cpp
===================================================================
--- trunk/src/kernel32/dbglog.cpp	(revision 21958)
+++ trunk/src/kernel32/dbglog.cpp	(revision 21959)
@@ -301,4 +301,6 @@
 #endif
 
+static VMutex logMutex;
+
 static void win32modname (ULONG eip, char *szModName, int cbModName)
 {
@@ -321,4 +323,6 @@
     TEB *teb = GetThreadTEB();
 
+    logMutex.enter();
+
     pszLastLogEntry = tekst;
 
@@ -393,4 +397,5 @@
         {
             SetFS(sel);
+            logMutex.leave();
             return 1;
         }
@@ -400,6 +405,8 @@
     {
         if (flog)
-            fflush( flog);
+            fflush(flog);
+
         SetFS(sel);
+        logMutex.leave();
         return 1;
     }
@@ -491,13 +498,13 @@
 #ifdef LOG_TIME
                 fprintf(flog,
-                        "tXX --- O %02d:%02d:%02d.%03d: ",
+                        "t-- --- O %02d:%02d:%02d.%03d: ",
                         h, m, s, ms);
 #else
 #ifdef SHOW_FPU_CONTROLREG
                 fprintf(flog,
-                        "tXX --- O ---: ");
+                        "t-- --- O ---: ");
 #else
                 fprintf(flog,
-                        "tXX --- O: ");
+                        "t-- --- O: ");
 #endif
 #endif
@@ -615,4 +622,5 @@
 
     SetFS(sel);
+    logMutex.leave();
     return 1;
 }
@@ -621,45 +629,51 @@
 int SYSTEM WriteLogNoEOL(const char *tekst, ...)
 {
-  USHORT  sel = RestoreOS2FS();
-  va_list argptr;
-
-  ODIN_HEAPCHECK();
-
-  if(!init)
-  {
-    init = TRUE;
+    USHORT  sel = RestoreOS2FS();
+    va_list argptr;
+
+    logMutex.enter();
+
+    ODIN_HEAPCHECK();
+
+    if (!init)
+    {
+        init = TRUE;
 
 #ifdef DEFAULT_LOGGING_OFF
-    if(getenv("WIN32LOG_ENABLED")) {
-#else
-    if(!getenv("NOWIN32LOG")) {
-#endif
-        char logname[CCHMAXPATH];
-
-        sprintf(logname, "odin32_%d.log", getpid());
-        flog = fopen(logname, "w");
-        if(flog == NULL) {//probably running exe on readonly device
-            sprintf(logname, "%sodin32_%d.log", kernel32Path, getpid());
+        if(getenv("WIN32LOG_ENABLED"))
+        {
+#else
+        if (!getenv("NOWIN32LOG"))
+        {
+#endif
+            char logname[CCHMAXPATH];
+
+            sprintf(logname, "odin32_%d.log", getpid());
             flog = fopen(logname, "w");
+            if(flog == NULL) {//probably running exe on readonly device
+                sprintf(logname, "%sodin32_%d.log", kernel32Path, getpid());
+                flog = fopen(logname, "w");
+            }
         }
-    }
-    else
-      fLogging = FALSE;
-  }
-
-  if(fLogging && flog && (dwEnableLogging > 0))
-  {
-    TEB *teb = GetThreadTEB();
-
-    va_start(argptr, tekst);
-    if(teb) {
-        teb->o.odin.logfile = (DWORD)flog;
-    }
-    vfprintf(flog, tekst, argptr);
-    if(teb) teb->o.odin.logfile = 0;
-    va_end(argptr);
-  }
-  SetFS(sel);
-  return 1;
+        else
+            fLogging = FALSE;
+    }
+
+    if (fLogging && flog && (dwEnableLogging > 0))
+    {
+        TEB *teb = GetThreadTEB();
+
+        va_start(argptr, tekst);
+        if (teb)
+            teb->o.odin.logfile = (DWORD)flog;
+        vfprintf(flog, tekst, argptr);
+        if (teb)
+            teb->o.odin.logfile = 0;
+        va_end(argptr);
+    }
+
+    SetFS(sel);
+    logMutex.leave();
+    return 1;
 }
 //******************************************************************************
@@ -679,25 +693,25 @@
 int SYSTEM WritePrivateLog(void *logfile, const char *tekst, ...)
 {
-  USHORT  sel = RestoreOS2FS();
-  va_list argptr;
-
-  if(fLogging && logfile)
-  {
-    TEB *teb = GetThreadTEB();
-
-    va_start(argptr, tekst);
-    if(teb) {
-        teb->o.odin.logfile = (DWORD)flog;
-    }
-    vfprintf((FILE *)logfile, tekst, argptr);
-    if(teb) teb->o.odin.logfile = 0;
-    va_end(argptr);
-
-    if(tekst[strlen(tekst)-1] != '\n')
-      fprintf((FILE *)logfile, "\n");
-  }
-
-  SetFS(sel);
-  return 1;
+    USHORT  sel = RestoreOS2FS();
+    va_list argptr;
+
+    if (fLogging && logfile)
+    {
+        TEB *teb = GetThreadTEB();
+
+        va_start(argptr, tekst);
+        if (teb)
+            teb->o.odin.logfile = (DWORD)flog;
+        vfprintf((FILE *)logfile, tekst, argptr);
+        if (teb)
+            teb->o.odin.logfile = 0;
+        va_end(argptr);
+
+        if (tekst[strlen(tekst)-1] != '\n')
+            fprintf((FILE *)logfile, "\n");
+    }
+
+    SetFS(sel);
+    return 1;
 }
 //******************************************************************************
