From 6c5471f324423ce4e005d66377b9b4eb81bc952b Mon Sep 17 00:00:00 2001 From: florian Date: Wed, 9 Apr 2008 21:27:11 +0000 Subject: [PATCH] * don't destroy LastError when resolving a threadvar on windows, resolves #10205 (?) git-svn-id: trunk@10621 - --- rtl/objpas/classes/lists.inc | 3 --- rtl/win/sysos.inc | 3 +++ rtl/win/systhrd.inc | 39 +++++++++++++++++++++++++++--------- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/rtl/objpas/classes/lists.inc b/rtl/objpas/classes/lists.inc index 24bb1021d9..0521d14f51 100644 --- a/rtl/objpas/classes/lists.inc +++ b/rtl/objpas/classes/lists.inc @@ -826,7 +826,6 @@ destructor TThreadList.Destroy; end; - procedure TThreadList.Add(Item: Pointer); begin LockList; @@ -876,5 +875,3 @@ procedure TThreadList.UnlockList; begin System.LeaveCriticalSection(FLock); end; - - diff --git a/rtl/win/sysos.inc b/rtl/win/sysos.inc index 40d1b13ad6..83bcbbee23 100644 --- a/rtl/win/sysos.inc +++ b/rtl/win/sysos.inc @@ -173,6 +173,9 @@ threadvar function GetLastError : DWORD; {$ifdef wince}cdecl{$else}stdcall{$endif};external KernelDLL name 'GetLastError'; + procedure SetLastError(dwErrCode : DWORD); + {$ifdef wince}cdecl{$else}stdcall{$endif};external KernelDLL name 'SetLastError'; + { time and date functions } function GetTickCount : longint; {$ifdef wince}cdecl{$else}stdcall{$endif};external KernelDLL name 'GetTickCount'; diff --git a/rtl/win/systhrd.inc b/rtl/win/systhrd.inc index 38761b04f0..16434fb578 100644 --- a/rtl/win/systhrd.inc +++ b/rtl/win/systhrd.inc @@ -99,20 +99,41 @@ CONST TlsSetValue(tlskey,dataindex); end; + function SysRelocateThreadvar(offset : dword) : pointer; - var + var dataindex : pointer; + errorsave : dword; begin - dataindex := TlsGetValue(tlskey); - if dataindex = nil then begin - SysAllocateThreadVars; - dataindex := TlsGetValue(tlskey); +{$ifdef dummy} + { I've no clue why this doesn't read dataindex, imo it should (FK) } + asm + movl TLSKey,%edx + movl $0x2c,%eax + movl %fs:(%eax),%eax + movl (%eax,%edx,4),%eax + movl %eax,dataindex end; + if DataIndex=nil then + begin + errorsave:=GetLastError; + SysAllocateThreadVars; + DataIndex:=TlsGetValue(tlskey); + SetLastError(errorsave); + end; +{$else win32} + errorsave:=GetLastError; + dataindex:=TlsGetValue(tlskey); + if dataindex=nil then + begin + SysAllocateThreadVars; + dataindex:=TlsGetValue(tlskey); + end; + SetLastError(errorsave); +{$endif win32} SysRelocateThreadvar:=DataIndex+Offset; -{ - begin - SysRelocateThreadvar:=TlsGetValue(tlskey)+Offset; -} end; + end; + procedure SysReleaseThreadVars; begin