|
@@ -8050,18 +8050,24 @@ begin
|
|
if not Assigned(GRttiPool[PoolIndex]) then
|
|
if not Assigned(GRttiPool[PoolIndex]) then
|
|
pool := TRttiPool.Create; { Heuristically pre-create. }
|
|
pool := TRttiPool.Create; { Heuristically pre-create. }
|
|
repeat
|
|
repeat
|
|
|
|
+{$ifdef FPC_HAS_FEATURE_THREADING}
|
|
EnterCriticalSection(PoolLock);
|
|
EnterCriticalSection(PoolLock);
|
|
|
|
+{$endif}
|
|
if PoolRefCount[PoolIndex] = 0 then
|
|
if PoolRefCount[PoolIndex] = 0 then
|
|
if Assigned(pool) then
|
|
if Assigned(pool) then
|
|
GRttiPool[PoolIndex] := specialize Exchange<TRttiPool>(pool, nil)
|
|
GRttiPool[PoolIndex] := specialize Exchange<TRttiPool>(pool, nil)
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
|
|
+{$ifdef FPC_HAS_FEATURE_THREADING}
|
|
LeaveCriticalSection(PoolLock);
|
|
LeaveCriticalSection(PoolLock);
|
|
|
|
+{$endif}
|
|
pool := TRttiPool.Create; { Create outside of the lock and retry. }
|
|
pool := TRttiPool.Create; { Create outside of the lock and retry. }
|
|
continue;
|
|
continue;
|
|
end;
|
|
end;
|
|
inc(PoolRefCount[PoolIndex]);
|
|
inc(PoolRefCount[PoolIndex]);
|
|
|
|
+{$ifdef FPC_HAS_FEATURE_THREADING}
|
|
LeaveCriticalSection(PoolLock);
|
|
LeaveCriticalSection(PoolLock);
|
|
|
|
+{$endif}
|
|
break;
|
|
break;
|
|
until false;
|
|
until false;
|
|
pool.Free;
|
|
pool.Free;
|
|
@@ -8081,11 +8087,15 @@ procedure FreePools;
|
|
var
|
|
var
|
|
iPool: boolean;
|
|
iPool: boolean;
|
|
begin
|
|
begin
|
|
|
|
+{$ifdef FPC_HAS_FEATURE_THREADING}
|
|
EnterCriticalSection(PoolLock);
|
|
EnterCriticalSection(PoolLock);
|
|
|
|
+{$endif}
|
|
for iPool in boolean do
|
|
for iPool in boolean do
|
|
if PoolRefCount[iPool] = 0 then
|
|
if PoolRefCount[iPool] = 0 then
|
|
specialize Exchange<TRttiPool>(GRttiPool[iPool], nil).Free;
|
|
specialize Exchange<TRttiPool>(GRttiPool[iPool], nil).Free;
|
|
|
|
+{$ifdef FPC_HAS_FEATURE_THREADING}
|
|
LeaveCriticalSection(PoolLock);
|
|
LeaveCriticalSection(PoolLock);
|
|
|
|
+{$endif}
|
|
end;
|
|
end;
|
|
|
|
|
|
class function TRttiContext.Create: TRttiContext;
|
|
class function TRttiContext.Create: TRttiContext;
|
|
@@ -8125,11 +8135,15 @@ begin
|
|
if FPoolIndex < 0 then
|
|
if FPoolIndex < 0 then
|
|
exit;
|
|
exit;
|
|
toFree := nil;
|
|
toFree := nil;
|
|
|
|
+{$ifdef FPC_HAS_FEATURE_THREADING}
|
|
EnterCriticalSection(PoolLock);
|
|
EnterCriticalSection(PoolLock);
|
|
|
|
+{$endif}
|
|
dec(PoolRefCount[boolean(FPoolIndex)]);
|
|
dec(PoolRefCount[boolean(FPoolIndex)]);
|
|
if (PoolRefCount[boolean(FPoolIndex)] = 0) and (FKeepContextCounter <= 0) then
|
|
if (PoolRefCount[boolean(FPoolIndex)] = 0) and (FKeepContextCounter <= 0) then
|
|
toFree := specialize Exchange<TRttiPool>(GRttiPool[boolean(FPoolIndex)], nil);
|
|
toFree := specialize Exchange<TRttiPool>(GRttiPool[boolean(FPoolIndex)], nil);
|
|
|
|
+{$ifdef FPC_HAS_FEATURE_THREADING}
|
|
LeaveCriticalSection(PoolLock);
|
|
LeaveCriticalSection(PoolLock);
|
|
|
|
+{$endif}
|
|
FPoolIndex := -1;
|
|
FPoolIndex := -1;
|
|
toFree.Free; { Free outside of the lock. }
|
|
toFree.Free; { Free outside of the lock. }
|
|
end;
|
|
end;
|
|
@@ -8577,12 +8591,16 @@ end;
|
|
{$endif}
|
|
{$endif}
|
|
|
|
|
|
initialization
|
|
initialization
|
|
|
|
+{$ifdef FPC_HAS_FEATURE_THREADING}
|
|
InitCriticalSection(PoolLock);
|
|
InitCriticalSection(PoolLock);
|
|
|
|
+{$endif}
|
|
InitDefaultFunctionCallManager;
|
|
InitDefaultFunctionCallManager;
|
|
{$ifdef SYSTEM_HAS_INVOKE}
|
|
{$ifdef SYSTEM_HAS_INVOKE}
|
|
InitSystemFunctionCallManager;
|
|
InitSystemFunctionCallManager;
|
|
{$endif}
|
|
{$endif}
|
|
finalization
|
|
finalization
|
|
FreePools;
|
|
FreePools;
|
|
|
|
+{$ifdef FPC_HAS_FEATURE_THREADING}
|
|
DoneCriticalSection(PoolLock);
|
|
DoneCriticalSection(PoolLock);
|
|
|
|
+{$endif}
|
|
end.
|
|
end.
|