mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-11-26 01:37:10 +01:00
amicommon: support for init/exit procedures for threads. will be used by Sockets unit for example, because bsdsocket.library needs to be reopened for each thread
git-svn-id: trunk@30991 -
This commit is contained in:
parent
5955e67c83
commit
5eea4b2846
@ -172,3 +172,66 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ Thread Init/Exit Procedure support }
|
||||||
|
Type
|
||||||
|
PThreadProcInfo = ^TThreadProcInfo;
|
||||||
|
TThreadProcInfo = Record
|
||||||
|
Next : PThreadProcInfo;
|
||||||
|
Proc : TProcedure;
|
||||||
|
End;
|
||||||
|
|
||||||
|
const
|
||||||
|
threadInitProcList :PThreadProcInfo = nil;
|
||||||
|
threadExitProcList :PThreadProcInfo = nil;
|
||||||
|
|
||||||
|
Procedure DoThreadProcChain(p: PThreadProcInfo);
|
||||||
|
Begin
|
||||||
|
while p <> nil do
|
||||||
|
begin
|
||||||
|
p^.proc;
|
||||||
|
p:=p^.next;
|
||||||
|
end;
|
||||||
|
End;
|
||||||
|
|
||||||
|
Procedure AddThreadProc(var procList: PThreadProcInfo; Proc: TProcedure);
|
||||||
|
var
|
||||||
|
P : PThreadProcInfo;
|
||||||
|
Begin
|
||||||
|
New(P);
|
||||||
|
P^.Next:=procList;
|
||||||
|
P^.Proc:=Proc;
|
||||||
|
procList:=P;
|
||||||
|
End;
|
||||||
|
|
||||||
|
Procedure CleanupThreadProcChain(var procList: PThreadProcInfo);
|
||||||
|
var
|
||||||
|
P : PThreadProcInfo;
|
||||||
|
Begin
|
||||||
|
while procList <> nil do
|
||||||
|
begin
|
||||||
|
p:=procList;
|
||||||
|
procList:=procList^.next;
|
||||||
|
dispose(p);
|
||||||
|
end;
|
||||||
|
End;
|
||||||
|
|
||||||
|
Procedure AddThreadInitProc(Proc: TProcedure);
|
||||||
|
Begin
|
||||||
|
AddThreadProc(threadInitProcList,Proc);
|
||||||
|
End;
|
||||||
|
|
||||||
|
Procedure AddThreadExitProc(Proc: TProcedure);
|
||||||
|
Begin
|
||||||
|
AddThreadProc(threadExitProcList,Proc);
|
||||||
|
End;
|
||||||
|
|
||||||
|
Procedure DoThreadInitProcChain;
|
||||||
|
Begin
|
||||||
|
DoThreadProcChain(threadInitProcList);
|
||||||
|
End;
|
||||||
|
|
||||||
|
Procedure DoThreadExitProcChain;
|
||||||
|
Begin
|
||||||
|
DoThreadProcChain(threadExitProcList);
|
||||||
|
End;
|
||||||
|
|||||||
@ -39,3 +39,9 @@ type
|
|||||||
const
|
const
|
||||||
CREATE_SUSPENDED = 1;
|
CREATE_SUSPENDED = 1;
|
||||||
STACK_SIZE_PARAM_IS_A_RESERVATION = 2;
|
STACK_SIZE_PARAM_IS_A_RESERVATION = 2;
|
||||||
|
|
||||||
|
{ Thread Init/Exit Procedure support }
|
||||||
|
Procedure AddThreadInitProc(Proc: TProcedure);
|
||||||
|
Procedure AddThreadExitProc(Proc: TProcedure);
|
||||||
|
Procedure DoThreadInitProcChain;
|
||||||
|
Procedure DoThreadExitProcChain;
|
||||||
|
|||||||
@ -141,6 +141,10 @@ procedure System_exit;
|
|||||||
var
|
var
|
||||||
oldDirLock: LongInt;
|
oldDirLock: LongInt;
|
||||||
begin
|
begin
|
||||||
|
{ Dispose the thread init/exit chains }
|
||||||
|
CleanupThreadProcChain(threadInitProcList);
|
||||||
|
CleanupThreadProcChain(threadExitProcList);
|
||||||
|
|
||||||
{ We must remove the CTRL-C FLAG here because halt }
|
{ We must remove the CTRL-C FLAG here because halt }
|
||||||
{ may call I/O routines, which in turn might call }
|
{ may call I/O routines, which in turn might call }
|
||||||
{ halt, so a recursive stack crash }
|
{ halt, so a recursive stack crash }
|
||||||
|
|||||||
@ -99,6 +99,10 @@ procedure System_exit;
|
|||||||
var
|
var
|
||||||
oldDirLock: LongInt;
|
oldDirLock: LongInt;
|
||||||
begin
|
begin
|
||||||
|
{ Dispose the thread init/exit chains }
|
||||||
|
CleanupThreadProcChain(threadInitProcList);
|
||||||
|
CleanupThreadProcChain(threadExitProcList);
|
||||||
|
|
||||||
{ We must remove the CTRL-C FLAG here because halt }
|
{ We must remove the CTRL-C FLAG here because halt }
|
||||||
{ may call I/O routines, which in turn might call }
|
{ may call I/O routines, which in turn might call }
|
||||||
{ halt, so a recursive stack crash }
|
{ halt, so a recursive stack crash }
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user