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.

92 lines
2.2 KiB

  1. /*++
  2. Copyright (C) 1998-2001 Microsoft Corporation
  3. Module Name:
  4. CLICNT.CPP
  5. Abstract:
  6. Call Result Class
  7. History:
  8. 26-Mar-98 a-davj Created.
  9. --*/
  10. #include "precomp.h"
  11. #include <wbemcore.h>
  12. // This keeps track of when the core can be unloaded
  13. CClientCnt gClientCounter;
  14. extern long g_lInitCount; // 0 DURING INTIALIZATION, 1 OR MORE LATER ON!
  15. extern ULONG g_cLock;
  16. CClientCnt::CClientCnt():m_Count(0)
  17. {
  18. InitializeListHead(&m_Head); // SEC:REVIEWED 2002-03-22 : No check
  19. }
  20. CClientCnt::~CClientCnt()
  21. {
  22. CInCritSec ics(&m_csEntering); // SEC:REVIEWED 2002-03-22 : No check, assumes entry
  23. RemoveEntryList(&m_Head);
  24. InitializeListHead(&m_Head);
  25. m_Count = 0;
  26. }
  27. bool CClientCnt::AddClientPtr(LIST_ENTRY * pEntry)
  28. {
  29. CInCritSec ics(&m_csEntering); // SEC:REVIEWED 2002-03-22 : No check, assumes entry
  30. InterlockedIncrement(&m_Count);
  31. InsertTailList(&m_Head,pEntry);
  32. return true;
  33. }
  34. bool CClientCnt::RemoveClientPtr(LIST_ENTRY * pEntry)
  35. {
  36. CInCritSec ics(&m_csEntering); // SEC:REVIEWED 2002-03-22 : No check, assumes entry
  37. LONG lRet = InterlockedDecrement(&m_Count);
  38. RemoveEntryList(pEntry);
  39. InitializeListHead(pEntry); // SEC:REVIEWED 2002-03-22 : No check
  40. if (0 == lRet) SignalIfOkToUnload();
  41. return true;
  42. }
  43. bool CClientCnt::OkToUnload()
  44. {
  45. CInCritSec ics(&m_csEntering); // SEC:REVIEWED 2002-03-22 : No check, assumes entry
  46. // We can shut down if we have 0 counts, and if we are not in the middle of initialization
  47. if( 0 == m_Count &&
  48. 0 != g_lInitCount &&
  49. 0 == g_cLock)
  50. return true;
  51. else
  52. return false;
  53. }
  54. void CClientCnt::SignalIfOkToUnload()
  55. {
  56. // count our locks
  57. if(OkToUnload() && g_lInitCount != -1)
  58. {
  59. HANDLE hCanShutdownEvent = NULL;
  60. DEBUGTRACE((LOG_WBEMCORE,"Core can now unload\n"));
  61. hCanShutdownEvent = OpenEvent(EVENT_MODIFY_STATE, FALSE, TEXT("WINMGMT_COREDLL_CANSHUTDOWN"));
  62. if(hCanShutdownEvent)
  63. {
  64. SetEvent(hCanShutdownEvent);
  65. CloseHandle(hCanShutdownEvent);
  66. }
  67. }
  68. }