Source code of Windows XP (NT5)
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.

128 lines
3.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: timeserv.cxx
  7. //
  8. // Contents: C++ utilties for the time serve C code
  9. //
  10. // Classes:
  11. //
  12. //
  13. // History: 19-May-94 ArnoldM Created
  14. //
  15. //--------------------------------------------------------------------------
  16. #include <secpch2.hxx>
  17. #pragma hdrstop
  18. // A class for initing the critical section needed by the time set
  19. // code in gettime.c. The code there relies on a critical section to
  20. // serialize the time slew settings. Rather than require each exe
  21. // that uses this library to put in calls to initialize the section and
  22. // to undo any time slew settings on exit, we create this class and use
  23. // a static constructor to do the appropriate calls. It's one of the
  24. // times that using C++ is a pleasure.
  25. //
  26. // The class also winds up owning the Critical Section. This is to create
  27. // the proper dependence on this code module so that the loader loads all of
  28. // the required pieces. Doing this adds a bit more overhead to Enter and
  29. // Leave the critical section, but it's done rarely enough that it shouldn't
  30. // matter.
  31. class _TimeSlew
  32. {
  33. public:
  34. ~_TimeSlew();
  35. _TimeSlew();
  36. // The two wrappers for entering and leaving the critical section.
  37. VOID EnterCS();
  38. VOID LeaveCS();
  39. private:
  40. CRITICAL_SECTION csAdjSection;
  41. };
  42. // No one needs to look at this, ever. Since the class has no state, the
  43. // instance memory consumption should be nil (wonder if it really is?).
  44. static
  45. class _TimeSlew TimeSlew;
  46. // reference the routines in gettime.c we exist to serve
  47. extern "C"
  48. {
  49. VOID
  50. SecMiscTimeSettingInit();
  51. VOID
  52. SecMiscTimeSettingDone();
  53. }
  54. //+--------------------------------------------------------------------------
  55. //
  56. // _TimeSlew::_TimeSlew -- constructor
  57. // and
  58. // _TimeSlew::~_TimeSlew -- destructor
  59. //
  60. // These are simply class wrappers for the C routines in gettime.c
  61. // They provide a way to avoid having to put explicit calls
  62. // into .exes
  63. //
  64. //---------------------------------------------------------------------------
  65. _TimeSlew::_TimeSlew()
  66. {
  67. InitializeCriticalSection(&csAdjSection);
  68. SecMiscTimeSettingInit();
  69. }
  70. _TimeSlew::~_TimeSlew()
  71. {
  72. SecMiscTimeSettingDone();
  73. DeleteCriticalSection(&csAdjSection);
  74. }
  75. //-----------------------------------------------------------------------------
  76. //
  77. // and the rest of the cast
  78. //
  79. //-----------------------------------------------------------------------------
  80. inline
  81. VOID
  82. _TimeSlew::EnterCS()
  83. {
  84. EnterCriticalSection(&csAdjSection);
  85. }
  86. inline
  87. VOID
  88. _TimeSlew::LeaveCS()
  89. {
  90. LeaveCriticalSection(&csAdjSection);
  91. }
  92. //----------------------------------------------------------------------------
  93. //
  94. // API wrappers for the above
  95. //
  96. //----------------------------------------------------------------------------
  97. extern "C"
  98. VOID
  99. SMEnterCriticalSection()
  100. {
  101. TimeSlew.EnterCS();
  102. }
  103. extern "C"
  104. VOID
  105. SMLeaveCriticalSection()
  106. {
  107. TimeSlew.LeaveCS();
  108. }