FpDebug: fix compile win32

This commit is contained in:
Martin 2024-07-11 00:05:52 +02:00
parent b55faa7970
commit c424cf492d
2 changed files with 38 additions and 38 deletions

View File

@ -40,8 +40,8 @@ unit FpDbgUtil;
interface interface
uses uses
Classes, SysUtils, fgl, math, LazUTF8, lazCollections,
{$IFDEF WINDOWS} Windows, {$ENDIF} {$IFDEF WINDOWS} Windows, {$ENDIF}
Classes, SysUtils, fgl, math, LazUTF8, lazCollections,
UTF8Process, {$ifdef FORCE_LAZLOGGER_DUMMY} LazLoggerDummy {$else} LazLoggerBase {$endif}, syncobjs; UTF8Process, {$ifdef FORCE_LAZLOGGER_DUMMY} LazLoggerDummy {$else} LazLoggerBase {$endif}, syncobjs;
type type
@ -66,7 +66,7 @@ type
EVENT_DONE_INDICATOR = Pointer(1); EVENT_DONE_INDICATOR = Pointer(1);
private private
FWorkerItemEventPtr: PPRTLEvent; FWorkerItemEventPtr: PPRTLEvent;
FState: Cardinal; FState: cardinal;
FError: Exception; FError: Exception;
FRefCnt: LongInt; FRefCnt: LongInt;
FStopRequested: Boolean; FStopRequested: Boolean;
@ -222,12 +222,19 @@ function ReadSignedFromExpression(var CurInstr: Pointer; ASize: Integer): Int64;
type type
{$IFDEF WINDOWS} {$IFDEF WINDOWS}
M128A = Windows.TM128A; {$ifdef cpux86_64}
{$ELSE} M128A = Windows.TM128A;
M128A = record {$ELSE}
M128A = record
Low: QWord; Low: QWord;
High: Int64; High: Int64;
end; end;
{$ENDIF}
{$ELSE}
M128A = record
Low: QWord;
High: Int64;
end;
{$ENDIF} {$ENDIF}
PM128A = ^M128A; PM128A = ^M128A;
@ -588,7 +595,7 @@ end;
destructor TFpGlobalThreadWorkerQueue.Destroy; destructor TFpGlobalThreadWorkerQueue.Destroy;
begin begin
Assert(InterLockedExchangeAdd(FRefCnt, 0) = 0); Assert(system.InterLockedExchangeAdd(FRefCnt, 0) = 0);
inherited Destroy; inherited Destroy;
end; end;
@ -615,12 +622,12 @@ end;
function TFpThreadWorkerItem.GetIsDone: Boolean; function TFpThreadWorkerItem.GetIsDone: Boolean;
begin begin
Result := InterLockedExchangeAdd(FState, 0) = TWSTATE_DONE; Result := system.InterLockedExchangeAdd(FState, 0) = TWSTATE_DONE;
end; end;
function TFpThreadWorkerItem.GetIsCancelled: Boolean; function TFpThreadWorkerItem.GetIsCancelled: Boolean;
begin begin
Result := InterLockedExchangeAdd(FState, 0) = TWSTATE_CANCEL; Result := system.InterLockedExchangeAdd(FState, 0) = TWSTATE_CANCEL;
end; end;
procedure TFpThreadWorkerItem.DoExecute; procedure TFpThreadWorkerItem.DoExecute;
@ -630,7 +637,7 @@ end;
procedure TFpThreadWorkerItem.DoFinished; procedure TFpThreadWorkerItem.DoFinished;
begin begin
if InterLockedExchangeAdd(FRefCnt, 0) <= 0 then if system.InterLockedExchangeAdd(FRefCnt, 0) <= 0 then
Destroy; Destroy;
end; end;
@ -644,7 +651,7 @@ var
OldState: Cardinal; OldState: Cardinal;
Evnt: PPRTLEvent; Evnt: PPRTLEvent;
begin begin
OldState := InterlockedCompareExchange(FState, TWSTATE_RUNNING, TWSTATE_NEW); OldState := system.InterlockedCompareExchange(FState, TWSTATE_RUNNING, TWSTATE_NEW);
DebugLn(FLogGroup, '%s!%s Executing WorkItem: %s "%s" StopRequested=%s', [dbgsThread, DbgSTime, dbgsWorkItemState(OldState), DebugText, dbgs(StopRequested)]); DebugLn(FLogGroup, '%s!%s Executing WorkItem: %s "%s" StopRequested=%s', [dbgsThread, DbgSTime, dbgsWorkItemState(OldState), DebugText, dbgs(StopRequested)]);
if (OldState in [TWSTATE_NEW, TWSTATE_WAIT_WORKER]) then begin if (OldState in [TWSTATE_NEW, TWSTATE_WAIT_WORKER]) then begin
@ -655,18 +662,18 @@ begin
DoExecute; DoExecute;
finally finally
DebugLnExit(FLogGroup); DebugLnExit(FLogGroup);
OldState := InterLockedExchange(FState, TWSTATE_DONE); OldState := system.InterLockedExchange(FState, TWSTATE_DONE);
if (OldState in [TWSTATE_WAITING, TWSTATE_WAIT_WORKER, TWSTATE_CANCEL]) then begin if (OldState in [TWSTATE_WAITING, TWSTATE_WAIT_WORKER, TWSTATE_CANCEL]) then begin
// The FState is in TWSTATE_WAIT___ or TWSTATE_CANCEL // The FState is in TWSTATE_WAIT___ or TWSTATE_CANCEL
// => so the event will exist, until it returned from RTLEventWaitFor // => so the event will exist, until it returned from RTLEventWaitFor
// It is save to access // It is save to access
Evnt := InterlockedExchange(FWorkerItemEventPtr, EVENT_DONE_INDICATOR); Evnt := system.InterlockedExchange(FWorkerItemEventPtr, EVENT_DONE_INDICATOR);
if Evnt <> nil then if Evnt <> nil then
RTLEventSetEvent(Evnt^); RTLEventSetEvent(Evnt^);
end end
else else
// If other threads have a ref, they may call WaitForFinish and read data from this. // If other threads have a ref, they may call WaitForFinish and read data from this.
if (InterLockedExchangeAdd(FRefCnt, 0) > 1) then if (system.InterLockedExchangeAdd(FRefCnt, 0) > 1) then
WriteBarrier; WriteBarrier;
DebugLn(FLogGroup, '%s!%s Finished WorkItem: %s "%s" StopRequested=%s', [dbgsThread, DbgSTime, dbgsWorkItemState(OldState), DebugText, dbgs(StopRequested)]); DebugLn(FLogGroup, '%s!%s Finished WorkItem: %s "%s" StopRequested=%s', [dbgsThread, DbgSTime, dbgsWorkItemState(OldState), DebugText, dbgs(StopRequested)]);
end; end;
@ -684,7 +691,7 @@ begin
belongs to the thread, until it has been waited for belongs to the thread, until it has been waited for
- If there is an ExistingEvnt, it must be SET once our event was waited for. - If there is an ExistingEvnt, it must be SET once our event was waited for.
*) *)
ExistingEvnt := InterlockedExchange(FWorkerItemEventPtr, AnEvntPtr); ExistingEvnt := system.InterlockedExchange(FWorkerItemEventPtr, AnEvntPtr);
if ExistingEvnt <> nil then begin if ExistingEvnt <> nil then begin
// Someone is already waiting for this Item // Someone is already waiting for this Item
@ -715,7 +722,7 @@ var
ExistingEvntPtr: PPRTLEvent; ExistingEvntPtr: PPRTLEvent;
begin begin
Result := False; Result := False;
ExistingEvntPtr := InterlockedExchange(FWorkerItemEventPtr, EVENT_DONE_INDICATOR); ExistingEvntPtr := system.InterlockedExchange(FWorkerItemEventPtr, EVENT_DONE_INDICATOR);
if (ExistingEvntPtr <> nil) and (ExistingEvntPtr^ <> nil) and (ExistingEvntPtr^ <> AnEvnt) then begin // Some one else is waiting if (ExistingEvntPtr <> nil) and (ExistingEvntPtr^ <> nil) and (ExistingEvntPtr^ <> AnEvnt) then begin // Some one else is waiting
RTLEventSetEvent(ExistingEvntPtr^); RTLEventSetEvent(ExistingEvntPtr^);
RTLEventWaitFor(AnEvnt); RTLEventWaitFor(AnEvnt);
@ -760,7 +767,7 @@ begin
*) *)
if AWaitForExecInThread then begin if AWaitForExecInThread then begin
OldState := InterlockedExchange(FState, TWSTATE_WAIT_WORKER); OldState := system.InterlockedExchange(FState, TWSTATE_WAIT_WORKER);
DebugLn(FLogGroup, '%s!%s WaitForFinish (WITH exe): %s "%s" StopRequested=%s', [dbgsThread, DbgSTime, dbgsWorkItemState(OldState), DebugText, dbgs(StopRequested)]); DebugLn(FLogGroup, '%s!%s WaitForFinish (WITH exe): %s "%s" StopRequested=%s', [dbgsThread, DbgSTime, dbgsWorkItemState(OldState), DebugText, dbgs(StopRequested)]);
assert(not (OldState in [TWSTATE_WAITING, TWSTATE_WAIT_WORKER, TWSTATE_CANCEL]), 'TFpThreadWorkerItem.WaitForFinish: not (OldState in [TWSTATE_WAITING, TWSTATE_WAIT_WORKER, TWSTATE_CANCEL])'); assert(not (OldState in [TWSTATE_WAITING, TWSTATE_WAIT_WORKER, TWSTATE_CANCEL]), 'TFpThreadWorkerItem.WaitForFinish: not (OldState in [TWSTATE_WAITING, TWSTATE_WAIT_WORKER, TWSTATE_CANCEL])');
if (OldState in [TWSTATE_NEW, TWSTATE_RUNNING]) then begin if (OldState in [TWSTATE_NEW, TWSTATE_RUNNING]) then begin
@ -777,13 +784,13 @@ begin
end end
else else
begin begin
OldState := InterlockedExchange(FState, TWSTATE_WAITING); OldState := system.InterlockedExchange(FState, TWSTATE_WAITING);
DebugLn(FLogGroup, '%s!%s WaitForFinish (NO exe): %s "%s" StopRequested=%s', [dbgsThread, DbgSTime, dbgsWorkItemState(OldState), DebugText, dbgs(StopRequested)]); DebugLn(FLogGroup, '%s!%s WaitForFinish (NO exe): %s "%s" StopRequested=%s', [dbgsThread, DbgSTime, dbgsWorkItemState(OldState), DebugText, dbgs(StopRequested)]);
assert(not (OldState in [TWSTATE_WAITING, TWSTATE_WAIT_WORKER, TWSTATE_CANCEL]), 'TFpThreadWorkerItem.WaitForFinish: not (OldState in [TWSTATE_WAITING, TWSTATE_WAIT_WORKER, TWSTATE_CANCEL])'); assert(not (OldState in [TWSTATE_WAITING, TWSTATE_WAIT_WORKER, TWSTATE_CANCEL]), 'TFpThreadWorkerItem.WaitForFinish: not (OldState in [TWSTATE_WAITING, TWSTATE_WAIT_WORKER, TWSTATE_CANCEL])');
if OldState = TWSTATE_NEW then begin if OldState = TWSTATE_NEW then begin
DoExecute; DoExecute;
InterLockedExchange(FState, TWSTATE_DONE); system.InterLockedExchange(FState, TWSTATE_DONE);
MaybeWaitForEvent(Evnt); MaybeWaitForEvent(Evnt);
end end
else else
@ -832,7 +839,7 @@ begin
*) *)
OldState := InterLockedExchange(FState, TWSTATE_CANCEL); // Prevent thread form executing this OldState := system.InterLockedExchange(FState, TWSTATE_CANCEL); // Prevent thread form executing this
Debugln(FLogGroup, '%s!%s WaitForCancel: %s "%s"', [dbgsThread, DbgSTime, dbgsWorkItemState(OldState), DebugText]); Debugln(FLogGroup, '%s!%s WaitForCancel: %s "%s"', [dbgsThread, DbgSTime, dbgsWorkItemState(OldState), DebugText]);
assert(not (OldState in [TWSTATE_WAITING, TWSTATE_WAIT_WORKER]), 'TFpThreadWorkerItem.WaitForCancel: not (OldState in [TWSTATE_WAITING, TWSTATE_WAIT_WORKER])'); assert(not (OldState in [TWSTATE_WAITING, TWSTATE_WAIT_WORKER]), 'TFpThreadWorkerItem.WaitForCancel: not (OldState in [TWSTATE_WAITING, TWSTATE_WAIT_WORKER])');
if OldState = TWSTATE_RUNNING then begin if OldState = TWSTATE_RUNNING then begin
@ -870,13 +877,13 @@ end;
function TFpThreadWorkerItem.RefCount: Integer; function TFpThreadWorkerItem.RefCount: Integer;
begin begin
Result := InterLockedExchangeAdd(FRefCnt, 0); Result := system.InterLockedExchangeAdd(FRefCnt, 0);
end; end;
procedure TFpThreadWorkerItem.RequestStop; procedure TFpThreadWorkerItem.RequestStop;
begin begin
FStopRequested := True; FStopRequested := True;
InterlockedCompareExchange(FState, TWSTATE_CANCEL, TWSTATE_NEW); // if not running, then WaitForcancel system.InterlockedCompareExchange(FState, TWSTATE_CANCEL, TWSTATE_NEW); // if not running, then WaitForcancel
end; end;
function TFpThreadWorkerItem.DebugText: String; function TFpThreadWorkerItem.DebugText: String;
@ -989,17 +996,17 @@ end;
function TFpThreadWorkerQueue.GetCurrentCount: Integer; function TFpThreadWorkerQueue.GetCurrentCount: Integer;
begin begin
Result := InterLockedExchangeAdd(FCurrentCount, 0); Result := system.InterLockedExchangeAdd(FCurrentCount, 0);
end; end;
function TFpThreadWorkerQueue.GetIdleThreadCount: integer; function TFpThreadWorkerQueue.GetIdleThreadCount: integer;
begin begin
Result := InterLockedExchangeAdd(FIdleThreadCount, 0); Result := system.InterLockedExchangeAdd(FIdleThreadCount, 0);
end; end;
function TFpThreadWorkerQueue.GetWantedCount: Integer; function TFpThreadWorkerQueue.GetWantedCount: Integer;
begin begin
Result := InterLockedExchangeAdd(FWantedCount, 0); Result := system.InterLockedExchangeAdd(FWantedCount, 0);
end; end;
procedure TFpThreadWorkerQueue.SetThreadCount(AValue: integer); procedure TFpThreadWorkerQueue.SetThreadCount(AValue: integer);
@ -1011,7 +1018,7 @@ begin
{$ENDIF} {$ENDIF}
FThreadMonitor.Enter; FThreadMonitor.Enter;
try try
InterLockedExchange(FWantedCount, AValue); system.InterLockedExchange(FWantedCount, AValue);
FWantedCount := AValue; FWantedCount := AValue;
c := FWorkerThreadList.Count; c := FWorkerThreadList.Count;
@ -1020,14 +1027,14 @@ begin
dec(c); dec(c);
PushItem(TFpThreadWorkerTerminateItem.Create); // will terminate one thread, if no more work is to be done PushItem(TFpThreadWorkerTerminateItem.Create); // will terminate one thread, if no more work is to be done
end; end;
InterLockedExchange(FCurrentCount, FWorkerThreadList.Count); system.InterLockedExchange(FCurrentCount, FWorkerThreadList.Count);
end end
else else
begin begin
// increase // increase
FWorkerThreadList.Count := AValue; FWorkerThreadList.Count := AValue;
InterLockedExchange(FCurrentCount, AValue); system.InterLockedExchange(FCurrentCount, AValue);
while c < AValue do begin while c < AValue do begin
FWorkerThreadList[c] := TFpWorkerThread.Create(Self); FWorkerThreadList[c] := TFpWorkerThread.Create(Self);
inc(c); inc(c);
@ -1040,7 +1047,7 @@ end;
function TFpThreadWorkerQueue.GetRtlEvent: PRTLEvent; function TFpThreadWorkerQueue.GetRtlEvent: PRTLEvent;
begin begin
Result := InterlockedExchange(FMainWaitEvent, nil); Result := system.InterlockedExchange(FMainWaitEvent, nil);
if Result = nil then if Result = nil then
Result := RTLEventCreate; Result := RTLEventCreate;
end; end;
@ -1049,7 +1056,7 @@ procedure TFpThreadWorkerQueue.FreeRtrEvent(AnEvent: PRTLEvent);
begin begin
assert(AnEvent <> nil, 'TFpThreadWorkerQueue.FreeRtrEvent: AnEvent <> nil'); assert(AnEvent <> nil, 'TFpThreadWorkerQueue.FreeRtrEvent: AnEvent <> nil');
RTLEventResetEvent(AnEvent); RTLEventResetEvent(AnEvent);
AnEvent := InterlockedExchange(FMainWaitEvent, AnEvent); AnEvent := system.InterlockedExchange(FMainWaitEvent, AnEvent);
if AnEvent <> nil then if AnEvent <> nil then
RTLEventDestroy(AnEvent); RTLEventDestroy(AnEvent);
end; end;
@ -1059,7 +1066,7 @@ begin
FThreadMonitor.Enter; FThreadMonitor.Enter;
try try
FWorkerThreadList.Remove(Item); FWorkerThreadList.Remove(Item);
InterLockedExchange(FCurrentCount, FWorkerThreadList.Count); system.InterLockedExchange(FCurrentCount, FWorkerThreadList.Count);
finally finally
FThreadMonitor.Leave; FThreadMonitor.Leave;
end; end;

View File

@ -39,6 +39,7 @@ interface
{$ifdef windows} {$ifdef windows}
uses uses
FpDbgUtil,
Windows; Windows;
{$endif} {$endif}
@ -131,14 +132,6 @@ type
PWOW64_CONTEXT = ^WOW64_CONTEXT; PWOW64_CONTEXT = ^WOW64_CONTEXT;
{$ifdef cpui386} {$ifdef cpui386}
M128A = record
Low: ULONGLONG;
High: LONGLONG;
end;
_M128A = M128A;
TM128A = M128A;
PM128A = TM128A;
TCONTEXT = record TCONTEXT = record
ContextFlags : DWORD; ContextFlags : DWORD;
Dr0 : DWORD; Dr0 : DWORD;