From dcbb5bac16cd56f0b055f78d1b8feb85e474da5e Mon Sep 17 00:00:00 2001 From: florian Date: Fri, 26 Jan 2001 16:37:54 +0000 Subject: [PATCH] *** empty log message *** --- rtl/inc/threadh.inc | 7 +++++- rtl/win32/system.pp | 51 ++++++++++++++++++++++++++++++++++++-------- rtl/win32/thread.inc | 30 ++++++++++++++++++++------ 3 files changed, 72 insertions(+), 16 deletions(-) diff --git a/rtl/inc/threadh.inc b/rtl/inc/threadh.inc index edfe97e29f..401fede419 100644 --- a/rtl/inc/threadh.inc +++ b/rtl/inc/threadh.inc @@ -16,6 +16,8 @@ **********************************************************************} {$ifdef MT} +type + TThreadFunc = function(parameter : pointer) : longint; {***************************************************************************** Multithread Handling *****************************************************************************} @@ -45,7 +47,10 @@ procedure LeaveCriticalsection(var cs : tcriticalsection); { $Log$ - Revision 1.3 2001-01-24 21:47:18 florian + Revision 1.4 2001-01-26 16:37:54 florian + *** empty log message *** + + Revision 1.3 2001/01/24 21:47:18 florian + more MT stuff added Revision 1.2 2001/01/05 17:35:50 florian diff --git a/rtl/win32/system.pp b/rtl/win32/system.pp index 4eabeef94a..b55d5c32c7 100644 --- a/rtl/win32/system.pp +++ b/rtl/win32/system.pp @@ -28,6 +28,20 @@ interface { include system-independent routine headers } {$I systemh.inc} +type + { the fields of this record are os dependent } + { and they shouldn't be used in a program } + { only the type TCriticalSection is important } + TCriticalSection = packed record + DebugInfo : pointer; + LockCount : longint; + RecursionCount : longint; + OwningThread : DWord; + LockSemaphore : DWord; + Reserved : DWord; + end; + + { include threading stuff } {$i threadh.inc} @@ -283,9 +297,6 @@ begin sbrk:=l; end; -{ include threading stuff, this is os independend part } -{$I thread.inc} - { include standard heap management } {$I heap.inc} @@ -649,6 +660,23 @@ begin end; +{***************************************************************************** + Thread Handling +*****************************************************************************} + +const + fpucw : word = $1332; + +procedure InitFPU;assembler; + + asm + fninit + fldcw fpucw + end; + +{ include threading stuff, this is os independend part } +{$I thread.inc} + {***************************************************************************** SystemUnit Initialization *****************************************************************************} @@ -794,9 +822,6 @@ var to check if the call stack can be written on exceptions } _SS : longint; -const - fpucw : word = $1332; - procedure Exe_entry;[public, alias : '_FPC_EXE_Entry']; begin IsLibrary:=false; @@ -812,8 +837,7 @@ procedure Exe_entry;[public, alias : '_FPC_EXE_Entry']; movl %eax,Win32StackTop movw %ss,%bp movl %ebp,_SS - fninit - fldcw fpucw + call InitFPU xorl %ebp,%ebp call PASCALMAIN popl %ebp @@ -860,6 +884,9 @@ var DLL_THREAD_ATTACH : begin inc(Thread_count); +{$ifdef MT} + AllocateThreadVars; +{$endif MT} if assigned(Dll_Thread_Attach_Hook) then Dll_Thread_Attach_Hook(DllParam); Dll_entry:=true; { return value is ignored } @@ -869,6 +896,9 @@ var dec(Thread_count); if assigned(Dll_Thread_Detach_Hook) then Dll_Thread_Detach_Hook(DllParam); +{$ifdef MT} + ReleaseThreadVars; +{$endif MT} Dll_entry:=true; { return value is ignored } end; DLL_PROCESS_DETACH : @@ -1393,7 +1423,10 @@ end. { $Log$ - Revision 1.4 2001-01-24 21:47:38 florian + Revision 1.5 2001-01-26 16:38:03 florian + *** empty log message *** + + Revision 1.4 2001/01/24 21:47:38 florian + more MT stuff added Revision 1.3 2001/01/05 15:44:35 florian diff --git a/rtl/win32/thread.inc b/rtl/win32/thread.inc index 83c36eba7b..66b0876e95 100644 --- a/rtl/win32/thread.inc +++ b/rtl/win32/thread.inc @@ -41,6 +41,14 @@ function CreateThread(lpThreadAttributes : pointer; external 'kernel32' name 'CreateThread'; procedure ExitThread(dwExitCode : DWord); external 'kernel32' name 'ExitThread'; +function GlobalAlloc(uFlags:UINT; dwBytes:DWORD):Pointer; + external 'kernel32' name 'GlobalAlloc'; +function GlobalFree(hMem : Pointer):Pointer; external 'kernel32' name 'GlobalFree'; + +const + { GlobalAlloc, GlobalFlags } + GMEM_FIXED = 0; + GMEM_ZEROINIT = 64; procedure init_threadvar(var offset : dword;size : dword);[public,alias: 'FPC_INIT_THREADVAR']; @@ -72,6 +80,17 @@ procedure AllocateThreadVars; TlsSetValue(dataindex,threadvars); end; +procedure ReleaseThreadVars; + + var + threadvars : pointer; + + begin + { release thread vars } + threadvars:=TlsGetValue(dataindex); + GlobalFree(threadvars); + end; + procedure InitThread; begin @@ -88,13 +107,9 @@ procedure InitThread; procedure DoneThread; - var - threadvars : pointer; - begin { release thread vars } - threadvars:=TlsGetValue(dataindex); - GlobalFree(threadvars); + ReleaseThreadVars; end; function ThreadMain(param : pointer) : dword;stdcall; @@ -220,7 +235,10 @@ procedure LeaveCriticalSection(var cs : tcriticalsection); { $Log$ - Revision 1.2 2001-01-24 21:47:38 florian + Revision 1.3 2001-01-26 16:38:03 florian + *** empty log message *** + + Revision 1.2 2001/01/24 21:47:38 florian + more MT stuff added Revision 1.1 2001/01/01 19:06:36 florian