mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-22 18:29:33 +02:00
* Hacking TLS callbacks into proper shape, part 2:
- Completely removed DLL_PROCESS_DETACH callback for executables. Reason: 1) it is executed after RTL has been shut down and called ExitProcess(), at which point it is really not a good idea to do the cleanup. 2) In executable (in contrast with DLL) it is just fine to leave remaining resources alone and let OS reclaim them. * Using 'cvar' for _tls_used and _tls_index to get proper prefixing without $ifdef's. git-svn-id: trunk@17943 -
This commit is contained in:
parent
c529921fc8
commit
ea1e44c036
@ -108,9 +108,9 @@ procedure Exec_Tls_callback(Handle : pointer; reason : Dword; Reserved : pointer
|
|||||||
if IsLibrary then
|
if IsLibrary then
|
||||||
Exit;
|
Exit;
|
||||||
case reason of
|
case reason of
|
||||||
DLL_PROCESS_ATTACH :
|
{ For executables, DLL_PROCESS_ATTACH is called *before* the entry point,
|
||||||
begin
|
and DLL_PROCESS_DETACH is called *after* RTL shuts down and calls ExitProcess.
|
||||||
end;
|
It isn't a good idea to handle resources of the main thread at these points. }
|
||||||
DLL_THREAD_ATTACH :
|
DLL_THREAD_ATTACH :
|
||||||
begin
|
begin
|
||||||
{ !!! SysInitMultithreading must NOT be called here. Windows guarantees that
|
{ !!! SysInitMultithreading must NOT be called here. Windows guarantees that
|
||||||
@ -134,12 +134,6 @@ procedure Exec_Tls_callback(Handle : pointer; reason : Dword; Reserved : pointer
|
|||||||
if TlsGetValue(TLSKey)<>nil then
|
if TlsGetValue(TLSKey)<>nil then
|
||||||
DoneThread; { Assume everything is idempotent there }
|
DoneThread; { Assume everything is idempotent there }
|
||||||
end;
|
end;
|
||||||
DLL_PROCESS_DETACH :
|
|
||||||
begin
|
|
||||||
DoneThread;
|
|
||||||
{ Free TLS resources used by ThreadVars }
|
|
||||||
SysFiniMultiThreading;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -152,27 +146,18 @@ var
|
|||||||
tls_callbacks : pointer; external name '___crt_xl_start__';
|
tls_callbacks : pointer; external name '___crt_xl_start__';
|
||||||
tls_data_start : pointer; external name '___tls_start__';
|
tls_data_start : pointer; external name '___tls_start__';
|
||||||
tls_data_end : pointer; external name '___tls_end__';
|
tls_data_end : pointer; external name '___tls_end__';
|
||||||
{$ifdef win32}
|
|
||||||
tls_index : dword; external name '__tls_index';
|
_tls_index : dword; cvar; external;
|
||||||
{$else not win32}
|
|
||||||
tls_index : dword; external name '_tls_index';
|
|
||||||
{$endif not win32}
|
|
||||||
|
|
||||||
const
|
const
|
||||||
_tls_used : TTlsDirectory = (
|
_tls_used : TTlsDirectory = (
|
||||||
data_start : @tls_data_start;
|
data_start : @tls_data_start;
|
||||||
data_end : @tls_data_end;
|
data_end : @tls_data_end;
|
||||||
index_pointer : @tls_index;
|
index_pointer : @_tls_index;
|
||||||
callbacks_pointer : @tls_callbacks;
|
callbacks_pointer : @tls_callbacks;
|
||||||
zero_fill_size : 0;
|
zero_fill_size : 0;
|
||||||
flags : 0;
|
flags : 0;
|
||||||
); public name
|
); cvar; public;
|
||||||
{ This should be the same name as in mingw/tlsup.c code }
|
|
||||||
{$ifdef win32}
|
|
||||||
'__tls_used';
|
|
||||||
{$else }
|
|
||||||
'_tls_used';
|
|
||||||
{$endif not win32}
|
|
||||||
|
|
||||||
{$endif FPC_USE_TLS_DIRECTORY}
|
{$endif FPC_USE_TLS_DIRECTORY}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user