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.

82 lines
3.4 KiB

  1. //============================================================================
  2. // Copyright (c) 1995, Microsoft Corporation
  3. //
  4. // File: sync.h
  5. //
  6. // History:
  7. // Abolade Gbadegesin September-8-1995 Created.
  8. //
  9. // Contains structures and macros used to implement synchronization.
  10. //============================================================================
  11. #ifndef _SYNC_H_
  12. #define _SYNC_H_
  13. //----------------------------------------------------------------------------
  14. // struct: READ_WRITE_LOCK
  15. //
  16. // This implements a multiple-reader/single-writer locking scheme
  17. //
  18. typedef RTL_RESOURCE READ_WRITE_LOCK, *PREAD_WRITE_LOCK;
  19. #define CREATE_READ_WRITE_LOCK(pRWL) \
  20. RtlInitializeResource((pRWL))
  21. #define DELETE_READ_WRITE_LOCK(pRWL) \
  22. RtlDeleteResource((pRWL))
  23. #define READ_WRITE_LOCK_CREATED(pRWL) (TRUE)
  24. #define ACQUIRE_READ_LOCK(pRWL) \
  25. RtlAcquireResourceShared((pRWL),TRUE)
  26. #define RELEASE_READ_LOCK(pRWL) \
  27. RtlReleaseResource((pRWL))
  28. #define ACQUIRE_WRITE_LOCK(pRWL) \
  29. RtlAcquireResourceExclusive((pRWL),TRUE)
  30. #define RELEASE_WRITE_LOCK(pRWL) \
  31. RtlReleaseResource((pRWL))
  32. #define READ_LOCK_TO_WRITE_LOCK(pRWL) \
  33. RtlConvertSharedToExclusive((pRWL))
  34. #define WRITE_LOCK_TO_READ_LOCK(pRWL) \
  35. RtlConvertExclusiveToShared((pRWL))
  36. //----------------------------------------------------------------------------
  37. // struct: LOCKED_LIST
  38. //
  39. // type definition for generic locked list
  40. // access is sychronized with a critical section
  41. // the LIST_ENTRY field must be the first field in structs linked
  42. // together by this construct, in order for the destruction of the
  43. // list to work correctly (i.e. in order for HeapFree(RemoveHeadList(l))
  44. // to free the correct pointer).
  45. //
  46. typedef struct _LOCKED_LIST {
  47. LIST_ENTRY LL_Head;
  48. CRITICAL_SECTION LL_Lock;
  49. DWORD LL_Created;
  50. } LOCKED_LIST, *PLOCKED_LIST;
  51. // macro functions for manipulating the locked list
  52. //
  53. #define CREATE_LOCKED_LIST(pLL) \
  54. InitializeListHead(&(pLL)->LL_Head); \
  55. InitializeCriticalSection(&(pLL)->LL_Lock); \
  56. (pLL)->LL_Created = 0x12345678
  57. #define LOCKED_LIST_CREATED(pLL) \
  58. ((pLL)->LL_Created == 0x12345678)
  59. #define DELETE_LOCKED_LIST(pLL) { \
  60. PLIST_ENTRY _ple; \
  61. (pLL)->LL_Created = 0; \
  62. DeleteCriticalSection(&(pLL)->LL_Lock); \
  63. while (!IsListEmpty(&(pLL)->LL_Head)) { \
  64. _ple = RemoveHeadList(&(pLL)->LL_Head); \
  65. BOOTP_FREE(_ple); \
  66. } \
  67. }
  68. #define ACQUIRE_LIST_LOCK(pLL) \
  69. EnterCriticalSection(&(pLL)->LL_Lock)
  70. #define RELEASE_LIST_LOCK(pLL) \
  71. LeaveCriticalSection(&(pLL)->LL_Lock)
  72. #endif // _SYNC_H_