syncobjs.pp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. windows,sysutils;
  17. type
  18. PSecurityAttributes = Windows.PSecurityAttributes;
  19. TSecurityAttributes = Windows.TSecurityAttributes;
  20. TEventHandle = THandle;
  21. {$I syncobh.inc}
  22. implementation
  23. {$I syncob.inc}
  24. procedure TCriticalSection.Acquire;
  25. begin
  26. EnterCriticalSection(CriticalSection);
  27. end;
  28. procedure TCriticalSection.Release;
  29. begin
  30. LeaveCriticalSection(CriticalSection);
  31. end;
  32. constructor TCriticalSection.Create;
  33. begin
  34. inherited Create;
  35. InitializeCriticalSection(CriticalSection);
  36. end;
  37. destructor TCriticalSection.Destroy;
  38. begin
  39. DeleteCriticalSection(CriticalSection);
  40. inherited Destroy;
  41. end;
  42. destructor THandleObject.destroy;
  43. begin
  44. CloseHandle(FHandle);
  45. inherited Destroy;
  46. end;
  47. constructor TEventObject.Create(EventAttributes : PSecurityAttributes;
  48. AManualReset,InitialState : Boolean;const Name : string);
  49. begin
  50. FHandle := CreateEvent(EventAttributes, AManualReset, InitialState, PChar(Name));
  51. end;
  52. destructor TEventObject.destroy;
  53. begin
  54. inherited;
  55. end;
  56. procedure TEventObject.ResetEvent;
  57. begin
  58. Windows.ResetEvent(FHandle)
  59. end;
  60. procedure TEventObject.SetEvent;
  61. begin
  62. Windows.SetEvent(FHandle);
  63. end;
  64. function TEventObject.WaitFor(Timeout : Cardinal) : TWaitResult;
  65. begin
  66. case WaitForSingleObject(Handle, Timeout) of
  67. WAIT_ABANDONED: Result := wrAbandoned;
  68. WAIT_OBJECT_0: Result := wrSignaled;
  69. WAIT_TIMEOUT: Result := wrTimeout;
  70. WAIT_FAILED:
  71. begin
  72. Result := wrError;
  73. FLastError := GetLastError;
  74. end;
  75. else
  76. Result := wrError;
  77. end;
  78. end;
  79. constructor TSimpleEvent.Create;
  80. begin
  81. FHandle := CreateEvent(nil, True, False, nil);
  82. end;
  83. end.