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.

90 lines
3.0 KiB

  1. #include "svcsync.h"
  2. #include "dbg.h"
  3. #include "tfids.h"
  4. extern HANDLE g_hShellHWDetectionThread = NULL;
  5. extern HANDLE g_hEventInitCompleted = NULL;
  6. HRESULT _CompleteShellHWDetectionInitialization()
  7. {
  8. static BOOL fCompleted = FALSE;
  9. if (!fCompleted)
  10. {
  11. // Just in case race condition of 2 threads in this fct
  12. HANDLE hEvent = InterlockedExchangePointer(
  13. &g_hEventInitCompleted, NULL);
  14. TRACE(TF_SVCSYNC,
  15. TEXT("ShellHWDetection Initialization NOT completed yet"));
  16. if (hEvent)
  17. {
  18. DWORD dwWait = WaitForSingleObject(hEvent, 0);
  19. if (WAIT_OBJECT_0 == dwWait)
  20. {
  21. // It's signaled!
  22. fCompleted = TRUE;
  23. TRACE(TF_SVCSYNC,
  24. TEXT("ShellHWDetectionInitCompleted event was already signaled!"));
  25. }
  26. else
  27. {
  28. // Not signaled
  29. TRACE(TF_SVCSYNC,
  30. TEXT("ShellHWDetectionInitCompleted event was NOT already signaled!"));
  31. if (g_hShellHWDetectionThread)
  32. {
  33. if (!SetThreadPriority(g_hShellHWDetectionThread,
  34. THREAD_PRIORITY_NORMAL))
  35. {
  36. TRACE(TF_SVCSYNC,
  37. TEXT("FAILED to set ShellHWDetection thread priority to NORMAL from ShellCOMServer"));
  38. }
  39. else
  40. {
  41. TRACE(TF_SVCSYNC,
  42. TEXT("Set ShellHWDetection thread priority to NORMAL from ShellCOMServer"));
  43. }
  44. }
  45. Sleep(0);
  46. dwWait = WaitForSingleObject(hEvent, 30000);
  47. if (g_hShellHWDetectionThread)
  48. {
  49. // No code should need this handle anymore. If it's
  50. // signaled it was signaled by the other thread, and will
  51. // not be used over there anymore.
  52. CloseHandle(g_hShellHWDetectionThread);
  53. g_hShellHWDetectionThread = NULL;
  54. }
  55. if (WAIT_OBJECT_0 == dwWait)
  56. {
  57. // It's signaled!
  58. fCompleted = TRUE;
  59. TRACE(TF_SVCSYNC,
  60. TEXT("ShellHWDetection Initialization COMPLETED"));
  61. }
  62. else
  63. {
  64. // Out of luck, the ShellHWDetection service cannot
  65. // complete its initialization...
  66. TRACE(TF_SVCSYNC,
  67. TEXT("ShellHWDetection Initialization lasted more than 30 sec: FAILED, dwWait = 0x%08X"),
  68. dwWait);
  69. }
  70. }
  71. CloseHandle(hEvent);
  72. }
  73. }
  74. return (fCompleted ? S_OK : E_FAIL);
  75. }