1 { *************************************************************************** }
3 { Kylix and Delphi Cross-Platform Visual Component Library }
5 { Copyright (c) 1997, 2001 Borland Software Corporation }
7 { *************************************************************************** }
27 PSecurityAttributes
= pointer;
30 TSynchroObject
= class(TObject
)
32 procedure Acquire
; virtual;
33 procedure Release
; virtual;
36 THandleObject
= class(TSynchroObject
)
42 destructor Destroy
; override;
43 property LastError
: Integer read FLastError
;
44 property Handle
: THandle read FHandle
;
48 TWaitResult
= (wrSignaled
, wrTimeout
, wrAbandoned
, wrError
);
50 TEvent
= class(THandleObject
)
54 FManualReset
: Boolean;
57 constructor Create(EventAttributes
: PSecurityAttributes
; ManualReset
,
58 InitialState
: Boolean; const Name
: string);
59 function WaitFor(Timeout
: LongWord
): TWaitResult
;
64 TSimpleEvent
= class(TEvent
)
69 TCriticalSection
= class(TSynchroObject
)
71 FSection
: TRTLCriticalSection
;
74 destructor Destroy
; override;
75 procedure Acquire
; override;
76 procedure Release
; override;
85 procedure TSynchroObject
.Acquire
;
89 procedure TSynchroObject
.Release
;
96 destructor THandleObject
.Destroy
;
105 constructor TEvent
.Create(EventAttributes
: PSecurityAttributes
; ManualReset
,
106 InitialState
: Boolean; const Name
: string);
109 FHandle
:= CreateEvent(EventAttributes
, ManualReset
, InitialState
, PChar(Name
));
121 FManualReset
:= ManualReset
;
123 sem_init(FEvent
, False, Value
);
127 function TEvent
.WaitFor(Timeout
: LongWord
): TWaitResult
;
130 case WaitForSingleObject(Handle
, Timeout
) of
131 WAIT_ABANDONED
: Result
:= wrAbandoned
;
132 WAIT_OBJECT_0
: Result
:= wrSignaled
;
133 WAIT_TIMEOUT
: Result
:= wrTimeout
;
137 FLastError
:= GetLastError
;
144 if Timeout
= LongWord($FFFFFFFF) then
147 Result
:= wrSignaled
;
149 else if FManualReset
then
156 procedure TEvent
.SetEvent
;
159 Windows
.SetEvent(Handle
);
166 sem_getvalue(FEvent
, I
);
172 procedure TEvent
.ResetEvent
;
175 Windows
.ResetEvent(Handle
);
178 while sem_trywait(FEvent
) = 0 do { nothing };
184 constructor TSimpleEvent
.Create
;
186 inherited Create(nil, True, False, '');
191 constructor TCriticalSection
.Create
;
194 InitializeCriticalSection(FSection
);
197 destructor TCriticalSection
.Destroy
;
199 DeleteCriticalSection(FSection
);
203 procedure TCriticalSection
.Acquire
;
205 EnterCriticalSection(FSection
);
208 procedure TCriticalSection
.Release
;
210 LeaveCriticalSection(FSection
);
213 procedure TCriticalSection
.Enter
;
218 procedure TCriticalSection
.Leave
;