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.

81 lines
1.8 KiB

  1. /*++
  2. Copyright (c) 1995-2000 Microsoft Corporation
  3. Module Name:
  4. locking.h
  5. Abstract:
  6. Private header file for locking/synchronization functions
  7. within SPUTILS
  8. Author:
  9. Ted Miller (tedm) 31-Mar-1995
  10. Revision History:
  11. Jamie Hunter (JamieHun) Jun-27-2000
  12. Moved out of SetupAPI
  13. --*/
  14. //
  15. // Locking functions. These functions are used to make various parts of
  16. // the DLL multithread-safe. The basic idea is to have a mutex and an event.
  17. // The mutex is used to synchronize access to the structure being guarded.
  18. // The event is only signalled when the structure being guarded is destroyed.
  19. // To gain access to the guarded structure, a routine waits on both the mutex
  20. // and the event. If the event gets signalled, then the structure was destroyed.
  21. // If the mutex gets signalled, then the thread has access to the structure.
  22. //
  23. typedef struct _MYLOCK {
  24. HANDLE Handles[2];
  25. } MYLOCK, *PMYLOCK;
  26. //
  27. // Indices into Locks array in string table structure.
  28. //
  29. #define TABLE_DESTROYED_EVENT 0
  30. #define TABLE_ACCESS_MUTEX 1
  31. BOOL
  32. __inline
  33. BeginSynchronizedAccess(
  34. IN PMYLOCK Lock
  35. )
  36. {
  37. DWORD d = WaitForMultipleObjects(2,Lock->Handles,FALSE,INFINITE);
  38. //
  39. // Success if the mutex object satisfied the wait;
  40. // Failure if the table destroyed event satisified the wait, or
  41. // the mutex was abandoned, etc.
  42. //
  43. return((d - WAIT_OBJECT_0) == TABLE_ACCESS_MUTEX);
  44. }
  45. VOID
  46. __inline
  47. EndSynchronizedAccess(
  48. IN PMYLOCK Lock
  49. )
  50. {
  51. ReleaseMutex(Lock->Handles[TABLE_ACCESS_MUTEX]);
  52. }
  53. BOOL
  54. _pSpUtilsInitializeSynchronizedAccess(
  55. OUT PMYLOCK Lock
  56. );
  57. VOID
  58. _pSpUtilsDestroySynchronizedAccess(
  59. IN OUT PMYLOCK Lock
  60. );
  61. #define InitializeSynchronizedAccess _pSpUtilsInitializeSynchronizedAccess
  62. #define DestroySynchronizedAccess _pSpUtilsDestroySynchronizedAccess