@@ -123,8 +123,8 @@ TPollAsyncConnection = class(TSynPersistent)
123
123
// - uses its own reentrant implementation, faster/lighter than TOSLock
124
124
fRW: array [boolean] of record
125
125
Lock: PtrUInt;
126
- ThreadID: TThreadID;
127
- RentrantCount: integer;
126
+ ThreadID: TThreadID; // pointer on POSIX, DWORD on Windows
127
+ ReentrantCount: TThreadID; // fake integer, but aligned to ThreadID field
128
128
end ;
129
129
// / low-level TLS context
130
130
fSecure: INetTls;
@@ -1474,16 +1474,16 @@ function TPollAsyncConnection.TryLock(writer: boolean): boolean;
1474
1474
if Lock <> 0 then
1475
1475
if ThreadID = tid then
1476
1476
begin
1477
- inc(RentrantCount);
1477
+ inc(PInteger(@ReentrantCount)^); // counter stored as TThreadID field
1478
1478
result := true;
1479
1479
end
1480
1480
else
1481
1481
exit
1482
- else if LockedExc(Lock, 1 , 0 ) then
1482
+ else if LockedExc(Lock, 1 , 0 ) then // this thread we acquired this lock
1483
1483
begin
1484
1484
include(fFlags, fWasActive);
1485
1485
ThreadID := tid;
1486
- RentrantCount := 1 ;
1486
+ ReentrantCount := TThreadID( 1 ); // reset reentrant counter
1487
1487
result := true;
1488
1488
end ;
1489
1489
end ;
@@ -1493,8 +1493,8 @@ procedure TPollAsyncConnection.UnLock(writer: boolean);
1493
1493
if self <> nil then
1494
1494
with fRW[writer and fLockMax] do
1495
1495
begin
1496
- dec(RentrantCount);
1497
- if RentrantCount <> 0 then
1496
+ dec(PInteger(@ReentrantCount)^); // counter stored as TThreadID field
1497
+ if ReentrantCount <> TThreadID( 0 ) then
1498
1498
exit;
1499
1499
Lock := 0 ;
1500
1500
ThreadID := TThreadID(0 );
@@ -1638,7 +1638,8 @@ function TPollReadSockets.UnsetPending(tag: TPollSocketTag): boolean;
1638
1638
(TPollAsyncConnection(tag).fHandle <> 0 ) and
1639
1639
// another atpReadPending thread may currently own this connection
1640
1640
// (occurs if PollForPendingEvents was called in between)
1641
- (TPollAsyncConnection(tag).fRW[{ write=} false].RentrantCount = 0 ) then
1641
+ (TPollAsyncConnection(tag).fRW[{ write=} false].
1642
+ ReentrantCount = TThreadID(0 )) then
1642
1643
begin
1643
1644
exclude(TPollAsyncConnection(tag).fFlags, fReadPending);
1644
1645
result := true;
@@ -1743,13 +1744,15 @@ function TPollAsyncSockets.Stop(connection: TPollAsyncConnection;
1743
1744
{ $ifdef USE_WINIOCP}
1744
1745
fDebugLog.Add.Log(sllDebug, ' Stop(%) sock=% handle=% r=% w=%' ,
1745
1746
[caller, pointer(sock), connection.Handle,
1746
- connection.fRW[false].RentrantCount ,
1747
- connection.fRW[true].RentrantCount ], self);
1747
+ PInteger(@ connection.fRW[false].ReentrantCount)^ ,
1748
+ PInteger(@ connection.fRW[true].ReentrantCount)^ ], self);
1748
1749
{ $else}
1749
1750
fDebugLog.Add.Log(sllDebug, ' Stop(%) sock=% handle=% r=%% w=%%' ,
1750
1751
[caller, pointer(sock), connection.Handle,
1751
- connection.fRW[false].RentrantCount, _SUB[fSubRead in connection.fFlags],
1752
- connection.fRW[true].RentrantCount, _SUB[fSubWrite in connection.fFlags]],
1752
+ PInteger(@connection.fRW[false].ReentrantCount)^,
1753
+ _SUB[fSubRead in connection.fFlags],
1754
+ PInteger(@connection.fRW[true].ReentrantCount)^,
1755
+ _SUB[fSubWrite in connection.fFlags]],
1753
1756
self);
1754
1757
{ $endif USE_WINIOCP}
1755
1758
if sock <> nil then
0 commit comments