Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
2.1 KiB

  1. /*
  2. *
  3. * NOTES:
  4. *
  5. * REVISIONS:
  6. * ane16Dec92: added automatic kick off of timer thread and changed to use
  7. * threadable class
  8. * pcy16Jan93: TimerManager is now a second timer, not a msec timer (i hope
  9. * we dont have to change this back)
  10. * TSC20May93: Created from os2timmn.cxx
  11. * TSC28May93: Added defines, see ntthrdbl.cxx for details
  12. * pcy29May96: Reverted Wait back to Sleep since Peek/Post was using 100% CPU
  13. * srt21Oct96: Changed Wait to timedWait so thread could be exited faster
  14. * tjg26Jan98: Added Stop method
  15. *
  16. * v-stebe 29Jul2000 Fixed PREfix errors (bug #46373)
  17. */
  18. #include "cdefine.h"
  19. #include <windows.h>
  20. #include "apc.h"
  21. #include "_defs.h"
  22. #include "err.h"
  23. #include "list.h"
  24. #include "timerman.h"
  25. #include "eventime.h"
  26. #include "nttimmn.h"
  27. #include "utils.h"
  28. #undef GIVEUPCPU
  29. #define GIVEUPCPU 2000
  30. /*
  31. C+
  32. Name :TimerManager
  33. Synop :Constructor. INitializes the list.
  34. */
  35. NTTimerManager::NTTimerManager(PMainApplication anApplication)
  36. : TimerManager(anApplication)
  37. //c-
  38. {
  39. NTTimerLoop *timerLoop = new NTTimerLoop (this);
  40. theTimerThread = new Thread (timerLoop);
  41. if (theTimerThread != NULL) {
  42. theTimerThread->Start();
  43. }
  44. }
  45. /*
  46. C+
  47. Name :~TimerManager
  48. Synop :Destroys the internal list.
  49. */
  50. NTTimerManager::~NTTimerManager()
  51. //c-
  52. {
  53. if (theTimerThread)
  54. {
  55. theTimerThread->ExitWait();
  56. delete theTimerThread;
  57. theTimerThread = NULL;
  58. }
  59. }
  60. VOID NTTimerManager:: Wait(ULONG aMilliSecondDelay)
  61. {
  62. Sleep(aMilliSecondDelay);
  63. }
  64. VOID NTTimerManager::Stop()
  65. {
  66. if (theTimerThread) {
  67. theTimerThread->ExitWait();
  68. delete theTimerThread;
  69. theTimerThread = NULL;
  70. }
  71. }
  72. NTTimerLoop::NTTimerLoop (PNTTimerManager aMgr) : theManager(aMgr)
  73. {
  74. SetThreadName("NT Timer Loop");
  75. }
  76. VOID NTTimerLoop::ThreadMain()
  77. {
  78. while (ExitNow() == FALSE)
  79. {
  80. if (!theManager->ExecuteTimer()) {
  81. #if (C_OS & C_NT)
  82. TimedWait(GIVEUPCPU);
  83. #else
  84. theManager->Wait(GIVEUPCPU);
  85. #endif
  86. }
  87. }
  88. DoneExiting();
  89. }