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.

120 lines
3.0 KiB

  1. /*++
  2. Copyright (C) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. SCHED.CPP
  5. Abstract:
  6. Implements the CSched class which is a crude schedualer.
  7. History:
  8. --*/
  9. #include "precomp.h"
  10. #include <persistcfg.h>
  11. #include "sched.h"
  12. #include <stdio.H>
  13. #include <helper.h>
  14. CSched::CSched()
  15. {
  16. for(DWORD dwCnt = 0; dwCnt < EOL; dwCnt++)
  17. m_dwDue[dwCnt] = 0xffffffff;
  18. }
  19. void CSched::SetWorkItem(JobType jt, DWORD dwMsFromNow)
  20. {
  21. m_dwDue[jt] = GetTickCount() + dwMsFromNow;
  22. }
  23. DWORD CSched::GetWaitPeriod()
  24. {
  25. DWORD dwCurr = GetTickCount();
  26. DWORD dwRet = INFINITE;
  27. for(DWORD dwCnt = 0; dwCnt < EOL; dwCnt++)
  28. {
  29. if(m_dwDue[dwCnt] == 0xffffffff)
  30. continue;
  31. if(m_dwDue[dwCnt] < dwCurr)
  32. dwRet = 10;
  33. else
  34. {
  35. DWORD dwGap = m_dwDue[dwCnt] - dwCurr;
  36. if(dwGap < dwRet)
  37. dwRet = dwGap;
  38. }
  39. }
  40. return dwRet;
  41. }
  42. bool CSched::IsWorkItemDue(JobType jt)
  43. {
  44. if(m_dwDue[jt] == 0xffffffff)
  45. return FALSE;
  46. DWORD dwCurr = GetTickCount();
  47. return (m_dwDue[jt] <= dwCurr);
  48. }
  49. void CSched::ClearWorkItem(JobType jt)
  50. {
  51. m_dwDue[jt] = INFINITE;
  52. }
  53. void CSched::StartCoreIfEssNeeded()
  54. {
  55. DEBUGTRACE((LOG_WINMGMT,"+ CSched::StartCoreIfEssNeeded\n"));
  56. DWORD dwEssNeedsLoading = 0;
  57. // Get the values from the configuration time
  58. CPersistentConfig per;
  59. per.GetPersistentCfgValue(PERSIST_CFGVAL_CORE_ESS_NEEDS_LOADING, dwEssNeedsLoading);
  60. if(dwEssNeedsLoading)
  61. {
  62. //
  63. // we might have the case of a 'net stop' but wbemcore might still be up
  64. // if it is stillloaded, we have to re-initilaize it
  65. // if it was unloaded, this is the first time load and globals are OK
  66. //
  67. HMODULE hCoreModule = NULL;
  68. if (GetModuleHandleEx(0,__TEXT("wbemcore.dll"),&hCoreModule))
  69. {
  70. OnDelete<HMODULE,BOOL(*)(HMODULE),FreeLibrary> flm(hCoreModule);
  71. HRESULT (STDAPICALLTYPE * pfnReinit)(DWORD) ;
  72. pfnReinit = (HRESULT (STDAPICALLTYPE *)(DWORD))GetProcAddress(hCoreModule, "Reinitialize");
  73. if (NULL == pfnReinit) return;
  74. pfnReinit(0);
  75. }
  76. IWbemLevel1Login * pCore = NULL;
  77. SCODE sc = CoCreateInstance(CLSID_InProcWbemLevel1Login,
  78. NULL,
  79. CLSCTX_INPROC_SERVER ,
  80. IID_IUnknown,
  81. (void**)&pCore);
  82. if(sc == S_OK)
  83. {
  84. IWbemServices * pServ = NULL;
  85. sc = pCore->NTLMLogin(L"Root", NULL, 0, NULL, &pServ);
  86. if(SUCCEEDED(sc))
  87. pServ->Release();
  88. pCore->Release();
  89. }
  90. }
  91. DEBUGTRACE((LOG_WINMGMT,"- CSched::StartCoreIfEssNeeded\n"));
  92. }