Leaked source code of windows server 2003
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.

59 lines
979 B

  1. // RdWrt.h
  2. #pragma once
  3. #ifndef _READWRITE_H_
  4. #define _READWRITE_H_
  5. // this class handles a single-writer, multi-reader threading model
  6. class CReadWrite
  7. {
  8. public:
  9. CReadWrite();
  10. ~CReadWrite();
  11. void EnterReader();
  12. void ExitReader();
  13. void EnterWriter();
  14. void ExitWriter();
  15. private:
  16. HANDLE m_hevtNoReaders;
  17. HANDLE m_hmtxWriter;
  18. HANDLE m_handles[2];
  19. LONG m_cReaders;
  20. };
  21. class CReader
  22. {
  23. public:
  24. CReader( CReadWrite& rw )
  25. : m_rrw( rw )
  26. {
  27. m_rrw.EnterReader();
  28. }
  29. ~CReader()
  30. {
  31. m_rrw.ExitReader();
  32. }
  33. private:
  34. CReadWrite& m_rrw;
  35. };
  36. class CWriter
  37. {
  38. public:
  39. CWriter( CReadWrite& rw )
  40. : m_rrw( rw )
  41. {
  42. m_rrw.EnterWriter();
  43. }
  44. ~CWriter()
  45. {
  46. m_rrw.ExitWriter();
  47. }
  48. private:
  49. CReadWrite& m_rrw;
  50. };
  51. #endif