2
0

syncobjs.pp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. {
  2. This file is part of the Free Component Library (FCL)
  3. Copyright (c) 1998 by Florian Klaempfl
  4. member of the Free Pascal development team
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$mode objfpc}
  12. {$h+}
  13. unit syncobjs;
  14. interface
  15. uses
  16. sysutils;
  17. type
  18. PSecurityAttributes = Pointer;
  19. TEventHandle = Pointer;
  20. const
  21. INFINITE = Cardinal(-1);
  22. type
  23. TWaitResult = (wrSignaled, wrTimeout, wrAbandoned, wrError);
  24. TSynchroObject = class(TObject)
  25. procedure Acquire;virtual;
  26. procedure Release;virtual;
  27. end;
  28. TCriticalSection = class(TSynchroObject)
  29. private
  30. CriticalSection : TRTLCriticalSection;
  31. public
  32. procedure Acquire;override;
  33. procedure Release;override;
  34. procedure Enter;
  35. procedure Leave;
  36. constructor Create;
  37. destructor Destroy;override;
  38. end;
  39. THandleObject = class(TSynchroObject)
  40. protected
  41. FHandle : TEventHandle;
  42. FLastError : Integer;
  43. public
  44. destructor destroy;override;
  45. property Handle : TEventHandle read FHandle;
  46. property LastError : Integer read FLastError;
  47. end;
  48. TEventObject = class(THandleObject)
  49. private
  50. FManualReset: Boolean;
  51. public
  52. constructor Create(EventAttributes : PSecurityAttributes;
  53. AManualReset,InitialState : Boolean;const Name : string);
  54. destructor destroy; override;
  55. procedure ResetEvent;
  56. procedure SetEvent;
  57. function WaitFor(Timeout : Cardinal) : TWaitResult;
  58. Property ManualReset : Boolean read FManualReset;
  59. end;
  60. TEvent = TEventObject;
  61. TSimpleEvent = class(TEventObject)
  62. constructor Create;
  63. end;
  64. implementation
  65. { ---------------------------------------------------------------------
  66. Real syncobjs implementation
  67. ---------------------------------------------------------------------}
  68. procedure TSynchroObject.Acquire;
  69. begin
  70. end;
  71. procedure TSynchroObject.Release;
  72. begin
  73. end;
  74. procedure TCriticalSection.Enter;
  75. begin
  76. Acquire;
  77. end;
  78. procedure TCriticalSection.Leave;
  79. begin
  80. Release;
  81. end;
  82. procedure TCriticalSection.Acquire;
  83. begin
  84. EnterCriticalSection(CriticalSection);
  85. end;
  86. procedure TCriticalSection.Release;
  87. begin
  88. LeaveCriticalSection(CriticalSection);
  89. end;
  90. constructor TCriticalSection.Create;
  91. begin
  92. Inherited Create;
  93. InitCriticalSection(CriticalSection);
  94. end;
  95. destructor TCriticalSection.Destroy;
  96. begin
  97. DoneCriticalSection(CriticalSection);
  98. end;
  99. destructor THandleObject.destroy;
  100. begin
  101. end;
  102. constructor TEventObject.Create(EventAttributes : PSecurityAttributes;
  103. AManualReset,InitialState : Boolean;const Name : string);
  104. begin
  105. FHandle := BasicEventCreate(EventAttributes, AManualReset, InitialState, Name);
  106. FManualReset:=AManualReset;
  107. end;
  108. destructor TEventObject.destroy;
  109. begin
  110. BasicEventDestroy(Handle);
  111. end;
  112. procedure TEventObject.ResetEvent;
  113. begin
  114. BasicEventResetEvent(Handle);
  115. end;
  116. procedure TEventObject.SetEvent;
  117. begin
  118. BasicEventSetEvent(Handle);
  119. end;
  120. function TEventObject.WaitFor(Timeout : Cardinal) : TWaitResult;
  121. begin
  122. Result := TWaitResult(basiceventWaitFor(Timeout, Handle));
  123. if Result = wrError then
  124. FLastError := GetLastOSError;
  125. end;
  126. constructor TSimpleEvent.Create;
  127. begin
  128. inherited Create(nil, True, False, '');
  129. end;
  130. end.