Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 52 additions & 52 deletions OtlCollections.pas
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,53 @@ destructor TOmniBlockingCollection.Destroy;
inherited Destroy;
end; { TOmniBlockingCollection.Destroy }

function TOmniBlockingCollection.TryAdd(const value: TOmniValue): boolean;
var
{$IFDEF MSWINDOWS}
awaited: cardinal;
{$ELSE}
waitResult: TWaitResult;
Signaller: IOmniSynchro;
{$ENDIF}
begin
obcAddCountAndCompleted.Increment;
try
// IsCompleted can not change during the execution of this function
Result := not IsCompleted;
if Result then begin
obcAccessed := true;
if obcThrottling and (obcApproxCount.Value >= obcHighWaterMark) then begin
{$IFDEF MSWINDOWS}
{$WARN SYMBOL_PLATFORM OFF}
Win32Check(ResetEvent(obcNotOverflow));
{$WARN SYMBOL_PLATFORM ON}
{$ELSE}
obcNotOverflow.Reset;
{$ENDIF ~MSWINDOWS}
// it's possible that messages were removed and obcNotOverflow set *before* the
// previous line has executed so test again ...
if obcThrottling and (obcApproxCount.Value >= obcHighWaterMark) then begin
obcAddCountAndCompleted.Decrement; // Leave the Add temporarily so that CompleteAdding can succeed
{$IFDEF MSWINDOWS}
awaited := DSiWaitForTwoObjects(obcCompletedSignal, obcNotOverflow, false, INFINITE);
obcAddCountAndCompleted.Increment; // Re-enter Add; queue may be now in 'completed' state
if (awaited = WAIT_OBJECT_0) or IsCompleted then begin
{$ELSE}
waitResult := FCompletedWaiter.WaitAny(INFINITE,Signaller);
obcAddCountAndCompleted.Increment;
if ((waitResult = wrSignaled) and (Signaller = obcCompletedSignal)) or IsCompleted then begin
{$ENDIF}
Result := false; // completed
Exit;
end;
end;
end;
obcCollection.Enqueue(value);
obcApproxCount.Increment;
end;
finally obcAddCountAndCompleted.Decrement; end;
end; { TOmniBlockingCollection.TryAdd }

procedure TOmniBlockingCollection.Add(const value: TOmniValue);
begin
if not TryAdd(value) then
Expand Down Expand Up @@ -421,6 +468,11 @@ function TOmniBlockingCollection.IsFinalized: boolean;
Result := IsCompleted and obcCollection.IsEmpty;
end; { TOmniBlockingCollection.IsFinalized }

function TOmniBlockingCollection.Take(var value: TOmniValue): boolean;
begin
Result := TryTake(value, INFINITE);
end; { TOmniBlockingCollection.Take }

function TOmniBlockingCollection.Next: TOmniValue;
begin
if not Take(Result) then
Expand All @@ -444,11 +496,6 @@ procedure TOmniBlockingCollection.SetThrottling(highWaterMark, lowWaterMark: int
obcThrottling := true;
end; { TOmniBlockingCollection.SetThrottling }

function TOmniBlockingCollection.Take(var value: TOmniValue): boolean;
begin
Result := TryTake(value, INFINITE);
end; { TOmniBlockingCollection.Take }

{$IFDEF OTL_Generics}
{$IFDEF OTL_HasArrayOfT}
{$IFDEF OTL_ERTTI}
Expand Down Expand Up @@ -616,53 +663,6 @@ class function TOmniBlockingCollection.ToArray<T>(const coll: IOmniBlockingColle
{$ENDIF OTL_HasArrayOfT}
{$ENDIF OTL_Generics}

function TOmniBlockingCollection.TryAdd(const value: TOmniValue): boolean;
var
{$IFDEF MSWINDOWS}
awaited: cardinal;
{$ELSE}
waitResult: TWaitResult;
Signaller: IOmniSynchro;
{$ENDIF}
begin
obcAddCountAndCompleted.Increment;
try
// IsCompleted can not change during the execution of this function
Result := not IsCompleted;
if Result then begin
obcAccessed := true;
if obcThrottling and (obcApproxCount.Value >= obcHighWaterMark) then begin
{$IFDEF MSWINDOWS}
{$WARN SYMBOL_PLATFORM OFF}
Win32Check(ResetEvent(obcNotOverflow));
{$WARN SYMBOL_PLATFORM ON}
{$ELSE}
obcNotOverflow.Reset;
{$ENDIF ~MSWINDOWS}
// it's possible that messages were removed and obcNotOverflow set *before* the
// previous line has executed so test again ...
if obcThrottling and (obcApproxCount.Value >= obcHighWaterMark) then begin
obcAddCountAndCompleted.Decrement; // Leave the Add temporarily so that CompleteAdding can succeed
{$IFDEF MSWINDOWS}
awaited := DSiWaitForTwoObjects(obcCompletedSignal, obcNotOverflow, false, INFINITE);
obcAddCountAndCompleted.Increment; // Re-enter Add; queue may be now in 'completed' state
if (awaited = WAIT_OBJECT_0) or IsCompleted then begin
{$ELSE}
waitResult := FCompletedWaiter.WaitAny(INFINITE,Signaller);
obcAddCountAndCompleted.Increment;
if ((waitResult = wrSignaled) and (Signaller = obcCompletedSignal)) or IsCompleted then begin
{$ENDIF}
Result := false; // completed
Exit;
end;
end;
end;
obcCollection.Enqueue(value);
obcApproxCount.Increment;
end;
finally obcAddCountAndCompleted.Decrement; end;
end; { TOmniBlockingCollection.TryAdd }

{$IFDEF MSWINDOWS}
function TOmniBlockingCollection.TryTake(var value: TOmniValue;
timeout_ms: cardinal): boolean;
Expand Down
19 changes: 9 additions & 10 deletions OtlCommon.pas
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ TOmniValueContainer = class;
property OwnsObject: boolean read IsOwnedObject write SetOwnsObject;
{$IFDEF MSWINDOWS}
function CastToAnsiStringDef(const defValue: AnsiString): AnsiString; inline;
function CastToWideStringDef(defValue: WideString): WideString; inline;
function CastToWideStringDef(const defValue: WideString): WideString; inline;
function IsAnsiString: boolean; inline;
function IsWideString: boolean; inline;
function TryCastToAnsiString(var value: AnsiString): boolean;
Expand Down Expand Up @@ -1621,13 +1621,6 @@ constructor TOmniValueContainer.Create;
ovcCount := 0;
end; { TOmniValueContainer.Create }

procedure TOmniValueContainer.Clear; //inline
begin
SetLength(ovcNames, 0);
SetLength(ovcValues, 0);
ovcCount := 0;
end; { TOmniValueContainer.Clear }

procedure TOmniValueContainer.Add(const paramValue: TOmniValue; const paramName: string);
var
idxParam: integer;
Expand All @@ -1652,6 +1645,13 @@ function TOmniValueContainer.AddParam(const paramName: string): integer;
ovcNames[Result] := paramName;
end; { TOmniValueContainer.AddParam }

procedure TOmniValueContainer.Clear; //inline
begin
SetLength(ovcNames, 0);
SetLength(ovcValues, 0);
ovcCount := 0;
end; { TOmniValueContainer.Clear }

procedure TOmniValueContainer.Assign(const parameters: array of TOmniValue);
var
value: TOmniValue;
Expand Down Expand Up @@ -2938,7 +2938,7 @@ function TOmniValue.CastToWideString: WideString;
raise Exception.Create('TOmniValue cannot be converted to WideString');
end; { TOmniValue.CastToWideString }

function TOmniValue.CastToWideStringDef(defValue: WideString): WideString;
function TOmniValue.CastToWideStringDef(const defValue: WideString): WideString;
begin
if not TryCastToWideString(Result) then
Result := defValue;
Expand Down Expand Up @@ -3043,7 +3043,6 @@ function TOmniValue.LogValue(depth: integer): string;
CBoolStr: array [boolean] of string = ('F', 'T');
var
arr: TOmniValueContainer;
autoDestroy: IOmniAutoDestroyObject;
i: integer;
maxItems: integer;
obj: TObject;
Expand Down
50 changes: 25 additions & 25 deletions OtlSync.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1778,6 +1778,14 @@ function TLightweightMREWEx.TryBeginWrite(timeout: cardinal): boolean;

{ Locked<T> }

procedure Locked<T>.Clear;
begin
FLifecycle := nil;
FInitialized := false;
FValue := Default(T);
FOwnsObject := false;
end; { Locked }

constructor Locked<T>.Create(const value: T; ownsObject: boolean);
begin
{$IFDEF OTL_HasLightweightMREW}
Expand Down Expand Up @@ -1850,14 +1858,6 @@ function Locked<T>.BeginWrite: T;
end; { Locked<T>.BeginWrite }
{$ENDIF OTL_HasLightweightMREW}

procedure Locked<T>.Clear;
begin
FLifecycle := nil;
FInitialized := false;
FValue := Default(T);
FOwnsObject := false;
end; { Locked }

{$IFDEF OTL_HasLightweightMREW}
procedure Locked<T>.EndRead;
begin
Expand All @@ -1882,6 +1882,23 @@ function Locked<T>.Enter: T;
Result := FValue;
end; { Locked<T>.Enter }

procedure Locked<T>.Leave;
begin
{$IFDEF OTL_HasLightweightMREW}
FLock.EndWrite;
{$ELSE ~OTL_HasLightweightMREW}
FLock.Release;
{$ENDIF ~OTL_HasLightweightMREW}
{$IFDEF DEBUG}
FLockCount.Decrement;
{$ENDIF DEBUG}
end; { Locked<T>.Leave }

procedure Locked<T>.Release;
begin
Leave;
end; { Locked<T>.Release }

procedure Locked<T>.Free;
begin
if FInitialized then begin
Expand Down Expand Up @@ -1971,18 +1988,6 @@ function Locked<T>.Initialize: T;
end; { Locked<T>.Initialize }
{$ENDIF OTL_ERTTI}

procedure Locked<T>.Leave;
begin
{$IFDEF OTL_HasLightweightMREW}
FLock.EndWrite;
{$ELSE ~OTL_HasLightweightMREW}
FLock.Release;
{$ENDIF ~OTL_HasLightweightMREW}
{$IFDEF DEBUG}
FLockCount.Decrement;
{$ENDIF DEBUG}
end; { Locked<T>.Leave }

procedure Locked<T>.Locked(proc: TProc);
begin
Acquire;
Expand All @@ -1999,11 +2004,6 @@ procedure Locked<T>.Locked(proc: TProcT);
finally Release; end;
end; { Locked<T>.Locked }

procedure Locked<T>.Release;
begin
Leave;
end; { Locked<T>.Release }

{$IFDEF OTL_HasLightweightMREW}
function Locked<T>.TryBeginRead: boolean;
begin
Expand Down
4 changes: 2 additions & 2 deletions src/DSiWin32.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ TDSiFileInfo = class
const workDir: string = ''; wait: boolean = false;
startInfo: PStartupInfo = nil): cardinal; overload;
function DSiExecuteInSession(sessionID: DWORD; const commandLine: string;
var processInfo: TProcessInformation; workDir: string = ''): boolean;
var processInfo: TProcessInformation; const workDir: string = ''): boolean;
function DSiGetProcessAffinity: string;
function DSiGetProcessAffinityMask: DSiNativeUInt;
function DSiGetProcessID(const processName: string; var processID: DWORD): boolean;
Expand Down Expand Up @@ -5398,7 +5398,7 @@ ACCESS_ALLOWED_ACE = record
specified or 0 in other cases.
}
function DSiExecuteInSession(sessionID: DWORD; const commandLine: string;
var processInfo: TProcessInformation; workDir: string): boolean;
var processInfo: TProcessInformation; const workDir: string): boolean;
var
cmdLine : string;
hToken : THandle;
Expand Down
4 changes: 2 additions & 2 deletions src/DetailedRTTI.pas
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ TObjectHelper = class helper for TObject
function RTTIMethodsAsString: string;
end;

function DescriptionOfMethod( Obj: TObject; MethodName: string ): string;
function DescriptionOfMethod( Obj: TObject; const MethodName: string ): string;

{$ENDIF HAS_RECORDHELPERS}
implementation
Expand All @@ -62,7 +62,7 @@ implementation

{$IFDEF HAS_RECORDHELPERS}

function DescriptionOfMethod( Obj: TObject; MethodName: string ): string;
function DescriptionOfMethod( Obj: TObject; const MethodName: string ): string;
var
header: PMethodInfoHeader;
headerEnd: Pointer;
Expand Down
10 changes: 5 additions & 5 deletions src/GpLists.pas
Original file line number Diff line number Diff line change
Expand Up @@ -8181,6 +8181,11 @@ procedure TGpSkipList<T, K>.Clear;
Initialize;
end; { TGpSkipList }

function TGpSkipList<T,K>.GetKey(const el: T): K;
begin
Result := FGetKey(el);
end; { TGpSkipList<T,K> }

function TGpSkipList<T,K>.Compare(const key: K; el: TGpSkipListEl<T>): integer;
begin
Result := Compare(key, GetKey(el.Element));
Expand Down Expand Up @@ -8313,11 +8318,6 @@ function TGpSkipList<T,K>.GetEnumerator: TGpSkipListEnumerator<T>;
Result := TGpSkipListEnumerator<T>.Create(FHead, FTail);
end; { TGpSkipList }

function TGpSkipList<T,K>.GetKey(const el: T): K;
begin
Result := FGetKey(el);
end; { TGpSkipList<T,K> }

procedure TGpSkipList<T, K>.Initialize;
var
iPtr: integer;
Expand Down
Loading
Loading