Changeset 846 for trunk/dll/comp.c


Ignore:
Timestamp:
Sep 27, 2007, 11:16:00 PM (18 years ago)
Author:
Steven Levine
Message:

Correct ULONGLONG size formatting to avoid traps

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/comp.c

    r841 r846  
    3636  20 Aug 07 SHL Revert to DosSleep(0)
    3737  20 Aug 07 SHL Use GetMSecTimer for timing
     38  20 Aug 07 SHL A few more speed up tweaks.  Some experimental timing code
    3839  26 Aug 07 GKY DosSleep(1) in loops changed to (0)
     40  27 Sep 07 SHL Correct ULONGLONG size formatting
    3941
    4042***********************************************************************/
     
    121123          strcpy(enddir, pffb->achName);
    122124          if (!(pffb->attrFile & FILE_DIRECTORY))
     125            // 27 Sep 07 SHL fixme to use CommaFmtULL
    123126            fprintf(fp,
    124                     "\"%s\",%u,%lu,%04u/%02u/%02u,%02u:%02u:%02u,%lu,%lu,N\n",
     127                    "\"%s\",%u,%llu,%04u/%02u/%02u,%02u:%02u:%02u,%lu,%lu,N\n",
    125128                    mask,
    126129                    enddir - mask,
     
    132135                    pffb->ftimeLastWrite.minutes,
    133136                    pffb->ftimeLastWrite.twosecs,
    134                     pffb->attrFile, (pffb->cbList > 4) ? (pffb->cbList / 2) : 0);
     137                    pffb->attrFile,
     138                    pffb->cbList > 4 ? pffb->cbList / 2 : 0);
    135139          // Skip . and ..
    136140          else if (recurse &&
     
    372376
    373377  case WM_DESTROY:
    374     DosSleep(50);//05 Aug 07 GKY 100
     378    DosSleep(50);                       // 05 Aug 07 GKY 100
    375379    break;
    376380  }
     
    482486              else
    483487                cmp->cmp->totalright--;
    484               DosSleep(0); //8-26-07 GKY 1
     488              DosSleep(0);              // 8-26-07 GKY 1
    485489            }
    486490            break;
     
    750754    return;
    751755  }
     756
     757  // DbgMsg(pszSrcFile, __LINE__, "FillDirList start %s", str);
    752758
    753759  maskstr = xmalloc(CCHMAXPATH, pszSrcFile, __LINE__);
     
    816822
    817823    DosFindClose(hDir);
    818     DosSleep(1);
     824    DosSleep(0);
    819825  }
    820826
     
    826832  free(maskstr);
    827833  free(pffbArray);
     834
     835  // DbgMsg(pszSrcFile, __LINE__, "FillDirList finish %s", str);
    828836}
    829837
     
    836844
    837845  return stricmp(fl1->fname, fl2->fname);
     846}
     847
     848// 20 Aug 07 SHL experimental fixme
     849
     850typedef struct {
     851  // Caller must init
     852  UINT sleepTime;               // How long to sleep
     853  UINT interval;                // How often to sleep
     854  // Owned by SleepIfNeeded
     855  UINT modulo;                  // How often to call GetMSecTimer
     856  UINT cntr;                    // Call counter
     857  ULONG lastMSec;               // Last time DosSleep invoked
     858} SLEEP_DESC;
     859
     860VOID SleepIfNeeded(BOOL id, UINT interval, UINT sleepTime)
     861{
     862  static ULONG lastMSec[10];
     863  static UINT cntr;
     864  static UINT modulo = 32;
     865  BOOL yes = ++cntr >= modulo;
     866
     867  if (yes) {
     868    ULONG newMSec = GetMSecTimer();
     869    // 1st time will have large difference, but don't care
     870    ULONG diff = newMSec - lastMSec[id];
     871    cntr = 0;
     872    yes = diff >= interval;
     873    // Try to tune modulo counter to approx 12% error
     874    if (yes) {
     875      lastMSec[id] = newMSec;
     876      if (diff >= interval + (interval / 8) && modulo > 0)
     877        modulo--;
     878    }
     879    else {
     880      if (diff < interval - (interval / 8))
     881        modulo++;
     882    }
     883    DosSleep(sleepTime);
     884  }
    838885}
    839886
     
    847894  BOOL notified = FALSE;
    848895
     896#if 0
    849897  ULONG lastMSec = GetMSecTimer();
    850898  ULONG ul;
     899#endif
    851900
    852901  HWND hwndLeft, hwndRight;
     
    858907    _endthread();
    859908  }
     909
     910  // DbgMsg(pszSrcFile, __LINE__, "FillCnrsThread enter");
    860911
    861912  DosError(FERR_DISABLEHARDERR);
     
    873924      INT l;
    874925      INT r;
    875       ULONG cntr;
     926      UINT cntr;
    876927      FILELIST **filesl = NULL;
    877928      FILELIST **filesr = NULL;
     
    916967      if (filesl)
    917968        qsort(filesl, numfilesl, sizeof(CHAR *), CompNames);
     969
     970      // DbgMsg(pszSrcFile, __LINE__, "FillCnrsThread sorted filesl");
    918971
    919972      // Build list of all files in right directory
     
    9971050                      if (p) {
    9981051                        p++;
     1052                        // 27 Sep 07 SHL fixme to do ULONGLONG conversion
    9991053                        fb4.cbFile = atol(p);
    10001054                        p = strchr(p, ',');
     
    10621116        qsort(filesr, numfilesr, sizeof(CHAR *), CompNames);
    10631117
     1118      // DbgMsg(pszSrcFile, __LINE__, "FillCnrsThread sorted filesr");
     1119
    10641120      // We now have two lists of files, both sorted.
    10651121      // Count total number of container entries required on each side
     
    11151171
    11161172      if (recsNeeded) {
     1173
     1174        // DbgMsg(pszSrcFile, __LINE__, "FillCnrsThread filling");
    11171175
    11181176        pcil = pcilFirst;
     
    13241382            DosSleep(0);
    13251383          cntr++;
    1326 #else
    1327           if ((cntr++ % 500) == 0) {
     1384#endif
     1385#if 0                                   // 20 Aug 07 SHL
     1386          if (cntr++ % 256 == 0) {
    13281387            ul = GetMSecTimer();
    1329             if (ul - lastMSec >= 1000) {
     1388            if (ul - lastMSec >= 200) {
    13301389              lastMSec = ul;
    13311390              DosSleep(1);
    13321391            }
    13331392          }
     1393#endif
     1394#if 1                                   // 20 Aug 07 SHL
     1395          SleepIfNeeded(0, 500, 1);
    13341396#endif
    13351397
     
    13811443        cmp->cmp->totalright = numfilesr;
    13821444
     1445        // DbgMsg(pszSrcFile, __LINE__, "FillCnrsThread filled");
     1446
    13831447      } // if recsNeeded
    13841448
    13851449      Deselect(hwndLeft);
    13861450      Deselect(hwndRight);
     1451
     1452      // DbgMsg(pszSrcFile, __LINE__, "FillCnrsThread deselected");
    13871453
    13881454      if (!PostMsg(cmp->hwnd, UM_CONTAINER_FILLED, MPVOID, MPVOID))
    13891455        WinSendMsg(cmp->hwnd, UM_CONTAINER_FILLED, MPVOID, MPVOID);
    13901456      notified = TRUE;
     1457
     1458      // DbgMsg(pszSrcFile, __LINE__, "FillCnrsThread FILLED posted");
    13911459
    13921460      if (filesl)
     
    14041472  free(cmp);
    14051473  DosPostEventSem(CompactSem);
     1474
     1475  // DbgMsg(pszSrcFile, __LINE__, "FillCnrsThread exit");
    14061476}
    14071477
     
    14091479#define hwndLeft        (WinWindowFromID(hwnd,COMP_LEFTDIR))
    14101480#define hwndRight       (WinWindowFromID(hwnd,COMP_RIGHTDIR))
     1481
     1482// 20 Aug 07 SHL fixme experimental
     1483
     1484BOOL NeedGUIUpdate(BOOL id)
     1485{
     1486  static ULONG lastMSec[10];
     1487  static UINT cntr;
     1488  static UINT modulo = 32;
     1489  BOOL yes = ++cntr >= modulo;
     1490
     1491  if (yes) {
     1492    ULONG newMSec = GetMSecTimer();
     1493    // 1st time will have large difference, but don't care
     1494    ULONG diff = newMSec - lastMSec[id];
     1495    cntr = 0;
     1496    yes = diff >= 500;
     1497    // Try to tune modulo counter to 10% error
     1498    if (yes) {
     1499      lastMSec[id] = newMSec;
     1500      if (diff >= 550 && modulo > 0)
     1501        modulo--;
     1502    }
     1503    else {
     1504      if (diff < 450)
     1505        modulo++;
     1506    }
     1507  }
     1508  return yes;
     1509}
    14111510
    14121511//=== CompareDlgProc() Compare directories dialog procedure ===
     
    16211720      CHAR s[81];
    16221721
     1722      // DbgMsg(pszSrcFile, __LINE__, "CompareDlgProc UM_CONTAINER_FILLED enter");
     1723
    16231724      cmp->filling = FALSE;
    16241725      WinEnableWindow(hwndLeft, TRUE);
     
    16701771      else
    16711772        WinSetDlgItemText(hwnd, COMP_NOTE, GetPString(IDS_COMPREADYTEXT));
     1773
     1774      // DbgMsg(pszSrcFile, __LINE__, "CompareDlgProc UM_CONTAINER_FILLED exit");
     1775
    16721776    }
    16731777    break;
     
    18481952                }
    18491953                if (SHORT1FROMMP(mp1) == COMP_LEFTDIR) {
    1850                   if (WinIsWindowEnabled(hwndLeft) || !(cmp->selleft % 50)) {
     1954                  // if (WinIsWindowEnabled(hwndLeft) || !(cmp->selleft % 50)) {
     1955                  if (WinIsWindowEnabled(hwndLeft) || NeedGUIUpdate(0)) {
    18511956                    sprintf(s, " %d", cmp->selleft);
    18521957                    WinSetDlgItemText(hwnd, COMP_SELLEFT, s);
     
    18541959                }
    18551960                else {
    1856                   if (WinIsWindowEnabled(hwndRight) || !(cmp->selright % 50)) {
     1961                  // if (WinIsWindowEnabled(hwndRight) || !(cmp->selright % 50)) {
     1962                  if (WinIsWindowEnabled(hwndRight) || NeedGUIUpdate(1)) {
    18571963                    sprintf(s, " %d", cmp->selright);
    18581964                    WinSetDlgItemText(hwnd, COMP_SELRIGHT, s);
Note: See TracChangeset for help on using the changeset viewer.