Windows NT 4.0 source code leak
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.

73 lines
2.1 KiB

4 years ago
  1. // RWSync.h -- Defines the CRWSync class.
  2. #ifndef __RWSYNC_H__
  3. #define __RWSYNC_H__
  4. class CRWSync
  5. {
  6. public:
  7. // Constructor --
  8. CRWSync();
  9. // Destructor --
  10. ~CRWSync();
  11. // Access Functions --
  12. // The CRWSync class provides sychronization between read and write transactions.
  13. //
  14. // A read transaction is bracketed by calls to BeginRead and EndRead. During a
  15. // read transaction no write transactions are allowed. This insures that all of
  16. // the data read during a transaction is mutually consistent. Note that read
  17. // transactions do not conflict with each other. Thus any number of read
  18. // transactions may be active simultaneously.
  19. //
  20. // A write transaction is bracketed by calls to BeginWrite and EndWrite. During a
  21. // write transaction no read transactions are allowed. That's because a write
  22. // transaction usually involves a sequence of changes which make the target data
  23. // object temporarily inconsistent. When a write transaction completes the target
  24. // data is presumed to be internally consistent.
  25. //
  26. // At most one write transaction may be active at a time. Subsequent calls to
  27. // BeginWrite will pend util the preceding write transactions complete.
  28. //
  29. // When contention occurs, write transactions will be given priority over read
  30. // transactions.
  31. ULONG BeginRead();
  32. void EndRead();
  33. inline ULONG BeginWrite() { return HoldForWriting(FALSE); }
  34. void EndWrite();
  35. enum { STARTED= 0, SHUTDOWN= 1 };
  36. protected:
  37. ULONG HoldForWriting(BOOL fForced);
  38. private:
  39. CRITICAL_SECTION m_cs;
  40. ULONG m_cWritersWaiting;
  41. HANDLE m_hEvWriters; // AutoReset
  42. ULONG m_cReadersActive;
  43. ULONG m_cReadersWaiting;
  44. HANDLE m_hEvReaders; // Manually Reset
  45. BOOL m_fState;
  46. enum { INACTIVE = 0, READER_WAITING = 0x1, READER_ACTIVE = 0x2,
  47. WRITER_WAITING = 0x4, WRITER_ACTIVE = 0x8,
  48. SHUTTING_DOWN = 0x10
  49. };
  50. };
  51. #endif // __RWSYNC_H__