Ignore:
Timestamp:
Sep 14, 2002, 3:49:39 PM (23 years ago)
Author:
sandervl
Message:

WaitForSingleObject, (Msg)WaitForMultipleObjects: If dwTimeout is not 0 and smaller than 20 ms, then temporarily change thread priority to time critical to make sure we don't get a late timeout

File:
1 edited

Legend:

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

    r8952 r9235  
    1 /* $Id: HandleManager.cpp,v 1.90 2002-08-01 16:02:40 sandervl Exp $ */
     1/* $Id: HandleManager.cpp,v 1.91 2002-09-14 13:49:39 sandervl Exp $ */
    22
    33/*
     
    19821982  }
    19831983
     1984  //If the timeout is less than 20 milliseconds (and not zero), then we are likely to
     1985  //return too late if the thread priority isn't time critical (time slices
     1986  //of 32 ms)
     1987  //To avoid this problem, we temporarily switch to time critical priority.
     1988  HANDLE hThread          = GetCurrentThread();
     1989  DWORD  dwThreadPriority = GetThreadPriority(hThread);
     1990
     1991  if(dwTimeout && dwTimeout < 20 && dwThreadPriority != THREAD_PRIORITY_TIME_CRITICAL) {
     1992      dprintf(("Temporarily change priority to THREAD_PRIORITY_TIME_CRITICAL for better timing"));
     1993      SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
     1994      //round to 8 ms units to get more precise timeouts
     1995      if(dwTimeout > 8)
     1996          dwTimeout = (dwTimeout/8)*8;
     1997  }
     1998  else dwThreadPriority = -1;
     1999
    19842000  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
    19852001  dwResult = pHMHandle->pDeviceHandler->WaitForSingleObject(&pHMHandle->hmHandleData,
    19862002                                                            dwTimeout);
    19872003
     2004  //Restore thread priority if we previously changed it
     2005  if(dwThreadPriority != -1) {
     2006      SetThreadPriority(hThread, dwThreadPriority);
     2007  }
    19882008  return (dwResult);                                  /* deliver return code */
    19892009}
     
    29823002  }
    29833003
     3004  //If the timeout is less than 20 milliseconds (and not zero), then we are likely to
     3005  //return too late if the thread priority isn't time critical (time slices
     3006  //of 32 ms)
     3007  //To avoid this problem, we temporarily switch to time critical priority.
     3008  HANDLE hThread          = GetCurrentThread();
     3009  DWORD  dwThreadPriority = GetThreadPriority(hThread);
     3010
     3011  if(dwTimeout && dwTimeout < 20 && dwThreadPriority != THREAD_PRIORITY_TIME_CRITICAL) {
     3012      dprintf(("Temporarily change priority to THREAD_PRIORITY_TIME_CRITICAL for better timing"));
     3013      SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
     3014      //round to 8 ms units to get more precise timeouts
     3015      if(dwTimeout > 8)
     3016          dwTimeout = (dwTimeout/8)*8;
     3017  }
     3018  else dwThreadPriority = -1;
     3019
    29843020  // OK, now forward to Open32.
    29853021  // @@@PH: Note this will fail on handles that do NOT belong to Open32
     
    29903026                                  dwTimeout);
    29913027
     3028  //Restore old thread priority if we changed it before
     3029  if(dwThreadPriority != -1) {
     3030      SetThreadPriority(hThread, dwThreadPriority);
     3031  }
     3032
    29923033  return (rc);                            // OK, done
    29933034#endif
     
    31123153  }
    31133154
     3155  //If the timeout is less than 20 milliseconds (and not zero), then we are likely to
     3156  //return too late if the thread priority isn't time critical (time slices
     3157  //of 32 ms)
     3158  //To avoid this problem, we temporarily switch to time critical priority.
     3159  HANDLE hThread          = GetCurrentThread();
     3160  DWORD  dwThreadPriority = GetThreadPriority(hThread);
     3161
     3162  if(dwTimeout && dwTimeout < 20 && dwThreadPriority != THREAD_PRIORITY_TIME_CRITICAL) {
     3163      dprintf(("Temporarily change priority to THREAD_PRIORITY_TIME_CRITICAL for better timing"));
     3164      SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
     3165      //round to 8 ms units to get more precise timeouts
     3166      if(dwTimeout > 8)
     3167          dwTimeout = (dwTimeout/8)*8;
     3168  }
     3169  else dwThreadPriority = -1;
     3170
    31143171  // OK, now forward to Open32.
    31153172  // @@@PH: Note this will fail on handles that do NOT belong to Open32
     
    31193176                                     fWaitAll, dwTimeout,
    31203177                                     dwWakeMask);
     3178
     3179  //Restore old thread priority if we changed it before
     3180  if(dwThreadPriority != -1) {
     3181      SetThreadPriority(hThread, dwThreadPriority);
     3182  }
    31213183
    31223184  dprintf2(("MsgWaitForMultipleObjects returned %d", rc));
Note: See TracChangeset for help on using the changeset viewer.