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.

93 lines
3.0 KiB

  1. #include "svcsync.h"
  2. #include "dbg.h"
  3. #include "tfids.h"
  4. extern HANDLE g_hShellHWDetectionThread = NULL;
  5. extern const WCHAR g_szShellHWDetectionInitCompleted[] =
  6. TEXT("ShellHWDetectionInitCompleted");
  7. HRESULT _CompleteShellHWDetectionInitialization()
  8. {
  9. static BOOL fCompleted = FALSE;
  10. if (!fCompleted)
  11. {
  12. HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE,
  13. g_szShellHWDetectionInitCompleted);
  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. // Just in case race condition of 2 threads in this fct
  32. HANDLE hTmp = InterlockedCompareExchangePointer(
  33. &g_hShellHWDetectionThread, NULL,
  34. g_hShellHWDetectionThread);
  35. if (hTmp)
  36. {
  37. if (!SetThreadPriority(hTmp, THREAD_PRIORITY_NORMAL))
  38. {
  39. TRACE(TF_SVCSYNC,
  40. TEXT("FAILED to set ShellHWDetection thread priority to NORMAL from ShellCOMServer"));
  41. }
  42. else
  43. {
  44. TRACE(TF_SVCSYNC,
  45. TEXT("Set ShellHWDetection thread priority to NORMAL from ShellCOMServer"));
  46. }
  47. }
  48. Sleep(0);
  49. dwWait = WaitForSingleObject(hEvent, 30000);
  50. if (hTmp)
  51. {
  52. // No code should need this handle anymore. If it's
  53. // signaled it was signaled by the other thread, and will
  54. // not be used over there anymore.
  55. CloseHandle(hTmp);
  56. }
  57. if (WAIT_OBJECT_0 == dwWait)
  58. {
  59. // It's signaled!
  60. fCompleted = TRUE;
  61. TRACE(TF_SVCSYNC,
  62. TEXT("ShellHWDetection Initialization COMPLETED"));
  63. }
  64. else
  65. {
  66. // Out of luck, the ShellHWDetection service cannot
  67. // complete its initialization...
  68. TRACE(TF_SVCSYNC,
  69. TEXT("ShellHWDetection Initialization lasted more than 30 sec: FAILED, dwWait = 0x%08X"),
  70. dwWait);
  71. }
  72. }
  73. CloseHandle(hEvent);
  74. }
  75. }
  76. return (fCompleted ? S_OK : E_FAIL);
  77. }