|
@@ -94,7 +94,12 @@ var
|
|
|
var
|
|
|
// public names are used by heaptrc unit
|
|
|
threadvarblocksize : dword; public name '_FPC_TlsSize';
|
|
|
- TLSKey : DWord = $ffffffff; public name '_FPC_TlsKey';
|
|
|
+ {$ifdef FPC_HAS_INDIRECT_MAIN_INFORMATION}
|
|
|
+ TLSKey : PDword = nil; public name '_FPC_TlsKey';
|
|
|
+ {$else FPC_HAS_INDIRECT_MAIN_INFORMATION}
|
|
|
+ TLSKeyVar : DWord = $ffffffff;
|
|
|
+ TLSKey : PDWord = @TLSKeyVar; public name '_FPC_TlsKey';
|
|
|
+ {$endif FPC_HAS_INDIRECT_MAIN_INFORMATION}
|
|
|
|
|
|
var
|
|
|
MainThreadIdWin32 : DWORD;
|
|
@@ -121,15 +126,15 @@ var
|
|
|
{ these aren't allocated yet ... }
|
|
|
{ allocate room on the heap for the thread vars }
|
|
|
errorsave:=GetLastError;
|
|
|
- if tlskey=$ffffffff then
|
|
|
+ if tlskey^=$ffffffff then
|
|
|
RunError(226);
|
|
|
- dataindex:=TlsGetValue(tlskey);
|
|
|
+ dataindex:=TlsGetValue(tlskey^);
|
|
|
if dataindex=nil then
|
|
|
begin
|
|
|
dataindex:=pointer(LocalAlloc(LMEM_FIXED or LMEM_ZEROINIT,threadvarblocksize));
|
|
|
if dataindex=nil then
|
|
|
RunError(226);
|
|
|
- TlsSetValue(tlskey,dataindex);
|
|
|
+ TlsSetValue(tlskey^,dataindex);
|
|
|
end;
|
|
|
SetLastError(errorsave);
|
|
|
end;
|
|
@@ -141,10 +146,10 @@ var
|
|
|
{ do not check IsMultiThread, as program could have altered it, out of Delphi habit }
|
|
|
|
|
|
{ the thread attach/detach code uses locks to avoid multiple calls of this }
|
|
|
- if TLSKey=$ffffffff then
|
|
|
+ if TLSKey^=$ffffffff then
|
|
|
begin
|
|
|
{ We're still running in single thread mode, setup the TLS }
|
|
|
- TLSKey:=TlsAlloc;
|
|
|
+ TLSKey^:=TlsAlloc;
|
|
|
InitThreadVars(@SysRelocateThreadvar);
|
|
|
|
|
|
IsMultiThread:=true;
|
|
@@ -154,9 +159,9 @@ var
|
|
|
|
|
|
procedure SysFiniMultithreading;
|
|
|
begin
|
|
|
- if TLSKey<>$ffffffff then
|
|
|
- TlsFree(TLSKey);
|
|
|
- TLSKey:=$ffffffff;
|
|
|
+ if TLSKey^<>$ffffffff then
|
|
|
+ TlsFree(TLSKey^);
|
|
|
+ TLSKey^:=$ffffffff;
|
|
|
end;
|
|
|
|
|
|
function SysRelocateThreadvar(offset : dword) : pointer;
|
|
@@ -165,11 +170,11 @@ var
|
|
|
errorsave : dword;
|
|
|
begin
|
|
|
errorsave:=GetLastError;
|
|
|
- dataindex:=TlsGetValue(tlskey);
|
|
|
+ dataindex:=TlsGetValue(tlskey^);
|
|
|
if dataindex=nil then
|
|
|
begin
|
|
|
SysAllocateThreadVars;
|
|
|
- dataindex:=TlsGetValue(tlskey);
|
|
|
+ dataindex:=TlsGetValue(tlskey^);
|
|
|
InitThread($1000000);
|
|
|
end;
|
|
|
SetLastError(errorsave);
|
|
@@ -181,12 +186,12 @@ var
|
|
|
var
|
|
|
p: pointer;
|
|
|
begin
|
|
|
- if TLSKey<>$ffffffff then
|
|
|
+ if TLSKey^<>$ffffffff then
|
|
|
begin
|
|
|
- p:=TlsGetValue(tlskey);
|
|
|
+ p:=TlsGetValue(tlskey^);
|
|
|
if Assigned(p) then
|
|
|
LocalFree(p);
|
|
|
- TlsSetValue(tlskey, nil);
|
|
|
+ TlsSetValue(tlskey^, nil);
|
|
|
end;
|
|
|
end;
|
|
|
|