systhrdh.inc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2001 by the Free Pascal development team
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. **********************************************************************}
  10. type
  11. IReadWriteSync = interface
  12. {$ifdef FPC_HAS_FEATURE_THREADING}
  13. ['{7B108C52-1D8F-4CDB-9CDF-57E071193D3F}']
  14. procedure BeginRead;
  15. procedure EndRead;
  16. function BeginWrite : boolean;
  17. procedure EndWrite;
  18. {$endif FPC_HAS_FEATURE_THREADING}
  19. end;
  20. TSimpleRWSync = class(TInterfacedObject,IReadWriteSync)
  21. {$ifdef FPC_HAS_FEATURE_THREADING}
  22. private
  23. crit : TRtlCriticalSection;
  24. public
  25. constructor Create; virtual;
  26. destructor Destroy; override;
  27. function Beginwrite : boolean;
  28. procedure Endwrite;
  29. procedure Beginread;
  30. procedure Endread;
  31. {$endif FPC_HAS_FEATURE_THREADING}
  32. end;
  33. TMultiReadExclusiveWriteSynchronizer = class(TInterfacedObject,IReadWriteSync)
  34. {$ifdef FPC_HAS_FEATURE_THREADING}
  35. private
  36. fThreadList: array [0..15] of Pointer;
  37. freaderqueue: peventstate;
  38. fwritelock : TRtlCriticalSection;
  39. fwaitingwriterlock: prtlevent;
  40. fWriterThreadID: TThreadID;
  41. fRevisionLevel: cardinal;
  42. fwriterequests: cardinal;
  43. factivethreads: cardinal;
  44. protected
  45. function ThreadIDtoIndex( aThreadID: TThreadID ): integer; inline;
  46. function GetThreadInfo(AutoCreate: Boolean): Pointer;
  47. procedure RemoveThread(AThreadInfo: Pointer);
  48. public
  49. constructor Create; virtual;
  50. destructor Destroy; override;
  51. function Beginwrite : boolean;
  52. procedure Endwrite;
  53. procedure Beginread;
  54. procedure Endread;
  55. property RevisionLevel: cardinal read fRevisionLevel;
  56. property WriterThreadID: TThreadID read fWriterThreadID;
  57. {$endif FPC_HAS_FEATURE_THREADING}
  58. end;
  59. TMREWException = class(Exception);