Ignore:
Timestamp:
Feb 1, 2012, 3:14:45 PM (14 years ago)
Author:
dmik
Message:

Serialize each log statement using mutex.

This finally fixes the longstanding problem when multiple threads
intermix parts of their statements lines in the log file making it
totally unreadable.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/dbglog.cpp

    r21958 r21959  
    301301#endif
    302302
     303static VMutex logMutex;
     304
    303305static void win32modname (ULONG eip, char *szModName, int cbModName)
    304306{
     
    321323    TEB *teb = GetThreadTEB();
    322324
     325    logMutex.enter();
     326
    323327    pszLastLogEntry = tekst;
    324328
     
    393397        {
    394398            SetFS(sel);
     399            logMutex.leave();
    395400            return 1;
    396401        }
     
    400405    {
    401406        if (flog)
    402             fflush( flog);
     407            fflush(flog);
     408
    403409        SetFS(sel);
     410        logMutex.leave();
    404411        return 1;
    405412    }
     
    491498#ifdef LOG_TIME
    492499                fprintf(flog,
    493                         "tXX --- O %02d:%02d:%02d.%03d: ",
     500                        "t-- --- O %02d:%02d:%02d.%03d: ",
    494501                        h, m, s, ms);
    495502#else
    496503#ifdef SHOW_FPU_CONTROLREG
    497504                fprintf(flog,
    498                         "tXX --- O ---: ");
     505                        "t-- --- O ---: ");
    499506#else
    500507                fprintf(flog,
    501                         "tXX --- O: ");
     508                        "t-- --- O: ");
    502509#endif
    503510#endif
     
    615622
    616623    SetFS(sel);
     624    logMutex.leave();
    617625    return 1;
    618626}
     
    621629int SYSTEM WriteLogNoEOL(const char *tekst, ...)
    622630{
    623   USHORT  sel = RestoreOS2FS();
    624   va_list argptr;
    625 
    626   ODIN_HEAPCHECK();
    627 
    628   if(!init)
    629   {
    630     init = TRUE;
     631    USHORT  sel = RestoreOS2FS();
     632    va_list argptr;
     633
     634    logMutex.enter();
     635
     636    ODIN_HEAPCHECK();
     637
     638    if (!init)
     639    {
     640        init = TRUE;
    631641
    632642#ifdef DEFAULT_LOGGING_OFF
    633     if(getenv("WIN32LOG_ENABLED")) {
    634 #else
    635     if(!getenv("NOWIN32LOG")) {
    636 #endif
    637         char logname[CCHMAXPATH];
    638 
    639         sprintf(logname, "odin32_%d.log", getpid());
    640         flog = fopen(logname, "w");
    641         if(flog == NULL) {//probably running exe on readonly device
    642             sprintf(logname, "%sodin32_%d.log", kernel32Path, getpid());
     643        if(getenv("WIN32LOG_ENABLED"))
     644        {
     645#else
     646        if (!getenv("NOWIN32LOG"))
     647        {
     648#endif
     649            char logname[CCHMAXPATH];
     650
     651            sprintf(logname, "odin32_%d.log", getpid());
    643652            flog = fopen(logname, "w");
     653            if(flog == NULL) {//probably running exe on readonly device
     654                sprintf(logname, "%sodin32_%d.log", kernel32Path, getpid());
     655                flog = fopen(logname, "w");
     656            }
    644657        }
    645     }
    646     else
    647       fLogging = FALSE;
    648   }
    649 
    650   if(fLogging && flog && (dwEnableLogging > 0))
    651   {
    652     TEB *teb = GetThreadTEB();
    653 
    654     va_start(argptr, tekst);
    655     if(teb) {
    656         teb->o.odin.logfile = (DWORD)flog;
    657     }
    658     vfprintf(flog, tekst, argptr);
    659     if(teb) teb->o.odin.logfile = 0;
    660     va_end(argptr);
    661   }
    662   SetFS(sel);
    663   return 1;
     658        else
     659            fLogging = FALSE;
     660    }
     661
     662    if (fLogging && flog && (dwEnableLogging > 0))
     663    {
     664        TEB *teb = GetThreadTEB();
     665
     666        va_start(argptr, tekst);
     667        if (teb)
     668            teb->o.odin.logfile = (DWORD)flog;
     669        vfprintf(flog, tekst, argptr);
     670        if (teb)
     671            teb->o.odin.logfile = 0;
     672        va_end(argptr);
     673    }
     674
     675    SetFS(sel);
     676    logMutex.leave();
     677    return 1;
    664678}
    665679//******************************************************************************
     
    679693int SYSTEM WritePrivateLog(void *logfile, const char *tekst, ...)
    680694{
    681   USHORT  sel = RestoreOS2FS();
    682   va_list argptr;
    683 
    684   if(fLogging && logfile)
    685   {
    686     TEB *teb = GetThreadTEB();
    687 
    688     va_start(argptr, tekst);
    689     if(teb) {
    690         teb->o.odin.logfile = (DWORD)flog;
    691     }
    692     vfprintf((FILE *)logfile, tekst, argptr);
    693     if(teb) teb->o.odin.logfile = 0;
    694     va_end(argptr);
    695 
    696     if(tekst[strlen(tekst)-1] != '\n')
    697       fprintf((FILE *)logfile, "\n");
    698   }
    699 
    700   SetFS(sel);
    701   return 1;
     695    USHORT  sel = RestoreOS2FS();
     696    va_list argptr;
     697
     698    if (fLogging && logfile)
     699    {
     700        TEB *teb = GetThreadTEB();
     701
     702        va_start(argptr, tekst);
     703        if (teb)
     704            teb->o.odin.logfile = (DWORD)flog;
     705        vfprintf((FILE *)logfile, tekst, argptr);
     706        if (teb)
     707            teb->o.odin.logfile = 0;
     708        va_end(argptr);
     709
     710        if (tekst[strlen(tekst)-1] != '\n')
     711            fprintf((FILE *)logfile, "\n");
     712    }
     713
     714    SetFS(sel);
     715    return 1;
    702716}
    703717//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.