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.

96 lines
1.9 KiB

  1. /*
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. swmr.h
  5. Abstract:
  6. This module contains the Single writer-Multi reader access structures
  7. Also the lock-list-count structures.
  8. Author:
  9. Jameel Hyder (microsoft!jameelh)
  10. Revision History:
  11. 25 Apr 1992 Initial Version
  12. Notes: Tab stop: 4
  13. --*/
  14. #ifndef _SWMR_
  15. #define _SWMR_
  16. #if DBG
  17. #define SWMR_SIGNATURE *(DWORD *)"SWMR"
  18. #define VALID_SWMR(pSwmr) (((pSwmr) != NULL) && \
  19. ((pSwmr)->Signature == SWMR_SIGNATURE))
  20. #else
  21. #define VALID_SWMR(pSwmr) ((pSwmr) != NULL)
  22. #endif
  23. #define SWMR_SOMEONE_WAITING( _pSwmr ) ((_pSwmr)->swmr_cExclWaiting || \
  24. (_pSwmr)->swmr_cSharedWaiting)
  25. typedef struct _SingleWriterMultiReader
  26. {
  27. #if DBG
  28. DWORD Signature;
  29. #endif
  30. BYTE swmr_cOwnedExclusive; // # of times a single thread has owned it exclusively
  31. BYTE swmr_cExclWaiting; // Number of writers waiting
  32. BYTE swmr_cSharedOwners; // Count of threads owning shared access
  33. BYTE swmr_cSharedWaiting; // Count of threads waiting for shared access
  34. PETHREAD swmr_ExclusiveOwner; // Owning thread for exclusive access
  35. KSEMAPHORE swmr_ExclSem; // semaphore for Exclusive owners
  36. KSEMAPHORE swmr_SharedSem; // Semaphore for Shared owners
  37. } SWMR, *PSWMR;
  38. extern
  39. VOID FASTCALL
  40. AfpSwmrInitSwmr(
  41. IN OUT PSWMR pSwmr
  42. );
  43. extern
  44. VOID FASTCALL
  45. AfpSwmrAcquireShared(
  46. IN PSWMR pSwmr
  47. );
  48. VOID FASTCALL
  49. AfpSwmrAcquireExclusive(
  50. IN PSWMR pSwmr
  51. );
  52. extern
  53. VOID FASTCALL
  54. AfpSwmrRelease(
  55. IN PSWMR pSwmr
  56. );
  57. extern
  58. BOOLEAN FASTCALL
  59. AfpSwmrUpgradeToExclusive(
  60. IN PSWMR pSwmr
  61. );
  62. extern
  63. VOID FASTCALL
  64. AfpSwmrDowngradeToShared(
  65. IN PSWMR pSwmr
  66. );
  67. #define AfpSwmrLockedShared(pSwmr) \
  68. (((pSwmr)->swmr_cSharedOwners != 0) && \
  69. ((pSwmr)->swmr_cOwnedExclusive == 0))
  70. #define AfpSwmrLockedExclusive(pSwmr) \
  71. (((pSwmr)->swmr_cOwnedExclusive != 0) && \
  72. ((pSwmr)->swmr_ExclusiveOwner == PsGetCurrentThread()))
  73. #endif // _SWMR_
  74.