123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- {
- This file is part of the Free Component Library (FCL)
- Copyright (c) 1998 by Florian Klaempfl
- member of the Free Pascal development team
- See the file COPYING.FPC, included in this distribution,
- for details about the copyright.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- **********************************************************************}
- {$mode objfpc}
- {$h+}
- unit syncobjs;
- interface
- uses
- sysutils;
- type
- PSecurityAttributes = Pointer;
- TEventHandle = Pointer;
- const
- INFINITE = Cardinal(-1);
- type
- TWaitResult = (wrSignaled, wrTimeout, wrAbandoned, wrError);
- TSynchroObject = class(TObject)
- procedure Acquire;virtual;
- procedure Release;virtual;
- end;
- TCriticalSection = class(TSynchroObject)
- private
- CriticalSection : TRTLCriticalSection;
- public
- procedure Acquire;override;
- procedure Release;override;
- procedure Enter;
- procedure Leave;
- constructor Create;
- destructor Destroy;override;
- end;
- THandleObject = class(TSynchroObject)
- protected
- FHandle : TEventHandle;
- FLastError : Integer;
- public
- destructor destroy;override;
- property Handle : TEventHandle read FHandle;
- property LastError : Integer read FLastError;
- end;
- TEventObject = class(THandleObject)
- private
- FManualReset: Boolean;
- public
- constructor Create(EventAttributes : PSecurityAttributes;
- AManualReset,InitialState : Boolean;const Name : string);
- destructor destroy; override;
- procedure ResetEvent;
- procedure SetEvent;
- function WaitFor(Timeout : Cardinal) : TWaitResult;
- Property ManualReset : Boolean read FManualReset;
- end;
- TEvent = TEventObject;
- TSimpleEvent = class(TEventObject)
- constructor Create;
- end;
- implementation
- { ---------------------------------------------------------------------
- Real syncobjs implementation
- ---------------------------------------------------------------------}
- procedure TSynchroObject.Acquire;
- begin
- end;
- procedure TSynchroObject.Release;
- begin
- end;
- procedure TCriticalSection.Enter;
- begin
- Acquire;
- end;
- procedure TCriticalSection.Leave;
- begin
- Release;
- end;
- procedure TCriticalSection.Acquire;
- begin
- EnterCriticalSection(CriticalSection);
- end;
- procedure TCriticalSection.Release;
- begin
- LeaveCriticalSection(CriticalSection);
- end;
- constructor TCriticalSection.Create;
- begin
- Inherited Create;
- InitCriticalSection(CriticalSection);
- end;
- destructor TCriticalSection.Destroy;
- begin
- DoneCriticalSection(CriticalSection);
- end;
- destructor THandleObject.destroy;
- begin
- end;
- constructor TEventObject.Create(EventAttributes : PSecurityAttributes;
- AManualReset,InitialState : Boolean;const Name : string);
- begin
- FHandle := BasicEventCreate(EventAttributes, AManualReset, InitialState, Name);
- FManualReset:=AManualReset;
- end;
- destructor TEventObject.destroy;
- begin
- BasicEventDestroy(Handle);
- end;
- procedure TEventObject.ResetEvent;
- begin
- BasicEventResetEvent(Handle);
- end;
- procedure TEventObject.SetEvent;
- begin
- BasicEventSetEvent(Handle);
- end;
- function TEventObject.WaitFor(Timeout : Cardinal) : TWaitResult;
- begin
- Result := TWaitResult(basiceventWaitFor(Timeout, Handle));
- if Result = wrError then
- FLastError := GetLastOSError;
- end;
- constructor TSimpleEvent.Create;
- begin
- inherited Create(nil, True, False, '');
- end;
- end.
|