TInterlockedHelper for Delphi interfaces: Spring.Reactive.pas
Posted by jpluimers on 2020/02/25
Reminder so self: [WayBack] sglienke / Spring4D / source / Source / Reactive / Spring.Reactive.pas — Bitbucket fragments:
type TInterlocked = SyncObjs.TInterlocked; TInterlockedHelper = class helper for TInterlocked // TODO: move to Spring.pas class function CompareExchange<T: IInterface>(var Target: T; const Value, Comparand: T): T; overload; static; class function Exchange<T: IInterface>(var Target: T; const Value: T): T; overload; static; end;{$REGION 'TInterlockedHelper'} class function TInterlockedHelper.CompareExchange<T>(var Target: T; const Value, Comparand: T): T; begin Result := Default(T); PPointer(@Result)^ := CompareExchange(PPointer(@Target)^, PPointer(@Value)^, PPointer(@Comparand)^); if PPointer(@Result)^ = PPointer(@Comparand)^ then begin if Assigned(Value) then Value._AddRef; end else if Assigned(Result) then Result._AddRef; end; class function TInterlockedHelper.Exchange<T>(var Target: T; const Value: T): T; begin Result := Default(T); PPointer(@Result)^ := Exchange(PPointer(@Target)^, PPointer(@Value)^); if Assigned(Value) then Value._AddRef; end; {$ENDREGION}a
–jeroen
Leave a comment