123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- {
- $Id$
- This file is part of the Free Pascal Run time library.
- Copyright (c) 2000 by the Free Pascal development team
- This File contains the OS indenpendend declartions for multi
- threading support in FPC
- See the File COPYING.FPC, included in this distribution,
- for details about the copyright.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- **********************************************************************}
- const
- DefaultStackSize = 32768; { including 16384 margin for stackchecking }
- type
- PEventState = pointer;
- PRTLEvent = pointer; // Windows=thandle, other=pointer to record.
- TThreadFunc = function(parameter : pointer) : ptrint;
- trtlmethod = procedure of object;
- // Function prototypes for TThreadManager Record.
- TBeginThreadHandler = Function (sa : Pointer;stacksize : dword; ThreadFunction : tthreadfunc;p : pointer;creationFlags : dword; var ThreadId : THandle) : DWord;
- TEndThreadHandler = Procedure (ExitCode : DWord);
- // Used for Suspend/Resume/Kill
- TThreadHandler = Function (threadHandle : dword) : dword;
- TThreadSwitchHandler = Procedure;
- TWaitForThreadTerminateHandler = Function (threadHandle : dword; TimeoutMs : longint) : dword; {0=no timeout}
- TThreadSetPriorityHandler = Function (threadHandle : dword; Prio: longint): boolean; {-15..+15, 0=normal}
- TThreadGetPriorityHandler = Function (threadHandle : dword): Integer;
- TGetCurrentThreadIdHandler = Function : dword;
- TCriticalSectionHandler = Procedure (var cs);
- TInitThreadVarHandler = Procedure(var offset : dword;size : dword);
- TRelocateThreadVarHandler = Function(offset : dword) : pointer;
- TAllocateThreadVarsHandler = Procedure;
- TReleaseThreadVarsHandler = Procedure;
- TBasicEventHandler = procedure(state:peventstate);
- TBasicEventWaitForHandler = function (timeout:cardinal;state:peventstate):longint;
- TBasicEventCreateHandler = function (EventAttributes :Pointer; AManualReset,InitialState : Boolean;const Name:ansistring):pEventState;
- TRTLEventHandler = procedure(AEvent:PRTLEvent);
- TRTLCreateEventHandler = function:PRTLEvent;
- TRTLEventSyncHandler = procedure (m:trtlmethod;p:tprocedure);
- TRTLCheckSyncUnixHandler = procedure;
- // TThreadManager interface.
- TThreadManager = Record
- InitManager : Function : Boolean;
- DoneManager : Function : Boolean;
- BeginThread : TBeginThreadHandler;
- EndThread : TEndThreadHandler;
- SuspendThread : TThreadHandler;
- ResumeThread : TThreadHandler;
- KillThread : TThreadHandler;
- ThreadSwitch : TThreadSwitchHandler;
- WaitForThreadTerminate : TWaitForThreadTerminateHandler;
- ThreadSetPriority : TThreadSetPriorityHandler;
- ThreadGetPriority : TThreadGetPriorityHandler;
- GetCurrentThreadId : TGetCurrentThreadIdHandler;
- InitCriticalSection : TCriticalSectionHandler;
- DoneCriticalSection : TCriticalSectionHandler;
- EnterCriticalSection : TCriticalSectionHandler;
- LeaveCriticalSection : TCriticalSectionHandler;
- InitThreadVar : TInitThreadVarHandler;
- RelocateThreadVar : TRelocateThreadVarHandler;
- AllocateThreadVars : TAllocateThreadVarsHandler;
- ReleaseThreadVars : TReleaseThreadVarsHandler;
- BasicEventCreate : TBasicEventCreateHandler; // left in for a while.
- BasicEventDestroy : TBasicEventHandler; // we might need BasicEvent
- BasicEventResetEvent : TBasicEventHandler; // for a real TEvent
- BasicEventSetEvent : TBasicEventHandler;
- BasiceventWaitFOr : TBasicEventWaitForHandler;
- RTLEventCreate : TRTLCreateEventHandler;
- RTLEventDestroy : TRTLEventHandler;
- RTLEventSetEvent : TRTLEventHandler;
- RTLEventStartWait : TRTLEventHandler;
- RTLEventWaitFor : TRTLEventHandler;
- RTLEventSync : TRTLEventSyncHandler;
- RTLChkSyncUnix : TRTLCheckSyncUnixHandler;
- end;
- {*****************************************************************************
- Thread Handler routines
- *****************************************************************************}
- Function GetThreadManager(Var TM : TThreadManager) : Boolean;
- Function SetThreadManager(Const NewTM : TThreadManager; Var OldTM : TThreadManager) : Boolean;
- Function SetThreadManager(Const NewTM : TThreadManager) : Boolean;
- {$ifndef DISABLE_NO_THREAD_MANAGER}
- Procedure SetNoThreadManager;
- {$endif DISABLE_NO_THREAD_MANAGER}
- // Needs to be exported, so the manager can call it.
- {$ifdef HASTHREADVAR}
- procedure InitThreadVars(RelocProc : Pointer);
- {$endif HASTHREADVAR}
- procedure InitThread(stklen:cardinal);
- {*****************************************************************************
- Multithread Handling
- *****************************************************************************}
- function BeginThread(sa : Pointer;stacksize : dword;
- ThreadFunction : tthreadfunc;p : pointer;creationFlags : dword;
- var ThreadId : THandle) : DWord;
- {$ifndef CPU64}
- {$ifndef unix}
- {$endif unix}
- {$endif CPU64}
- { add some simplfied forms which make lifer easier and porting }
- { to other OSes too ... }
- function BeginThread(ThreadFunction : tthreadfunc) : DWord;
- function BeginThread(ThreadFunction : tthreadfunc;p : pointer) : DWord;
- function BeginThread(ThreadFunction : tthreadfunc;p : pointer; var ThreadId : THandle) : DWord;
- {$ifndef CPU64}
- {$ifndef unix}
- {$endif unix}
- {$endif CPU64}
- procedure EndThread(ExitCode : DWord);
- procedure EndThread;
- {some thread support functions}
- function SuspendThread (threadHandle : dword) : dword;
- function ResumeThread (threadHandle : dword) : dword;
- procedure ThreadSwitch; {give time to other threads}
- function KillThread (threadHandle : dword) : dword;
- function WaitForThreadTerminate (threadHandle : dword; TimeoutMs : longint) : dword; {0=no timeout}
- function ThreadSetPriority (threadHandle : dword; Prio: longint): boolean; {-15..+15, 0=normal}
- function ThreadGetPriority (threadHandle : dword): Integer;
- function GetCurrentThreadId : dword;
- { this allows to do a lot of things in MT safe way }
- { it is also used to make the heap management }
- { thread safe }
- procedure InitCriticalSection(var cs : TRTLCriticalSection);
- procedure DoneCriticalsection(var cs : TRTLCriticalSection);
- procedure EnterCriticalsection(var cs : TRTLCriticalSection);
- procedure LeaveCriticalsection(var cs : TRTLCriticalSection);
- function BasicEventCreate(EventAttributes : Pointer; AManualReset,InitialState : Boolean;const Name : ansistring):pEventState;
- procedure basiceventdestroy(state:peventstate);
- procedure basiceventResetEvent(state:peventstate);
- procedure basiceventSetEvent(state:peventstate);
- function basiceventWaitFor(Timeout : Cardinal;state:peventstate) : longint;
- function RTLEventCreate :PRTLEvent;
- procedure RTLeventdestroy(state:pRTLEvent);
- procedure RTLeventSetEvent(state:pRTLEvent);
- procedure RTLeventStartWait(state:pRTLEvent);
- procedure RTLeventWaitFor(state:pRTLEvent);
- procedure RTLeventsync(m:trtlmethod;p:tprocedure);
- procedure RTLchecksynchronize;
- {
- $Log$
- Revision 1.25 2005-01-21 21:43:12 armin
- * applied patch to compile go32v2 from Tomas (tested by John)
- Revision 1.24 2004/12/28 14:20:03 marco
- * tthread patch from neli
- Revision 1.23 2004/12/27 15:28:40 marco
- * checksynchronize now in interface win32 uses the default impl.
- unix uses systhrds, rest empty implementation.
- Revision 1.22 2004/12/23 15:08:58 marco
- * 2nd synchronize attempt. cthreads<->systhrds difference was not ok, but
- only showed on make install should be fixed now.
- Revision 1.21 2004/12/22 21:29:24 marco
- * rtlevent kraam. Checked (compile): Linux, FreeBSD, Darwin, Windows
- Check work: ask Neli.
- Revision 1.20 2004/12/12 14:30:27 peter
- * x86_64 updates
- Revision 1.19 2004/09/19 18:55:30 armin
- * added define DISABLE_NO_THREAD_MANAGER to avoid warnings if thread manager is always present
- Revision 1.18 2004/05/23 20:26:20 marco
- * wrappers and nothread prototypes for the basic* functions
- Revision 1.17 2004/05/23 15:30:29 marco
- * first try basicevent
- Revision 1.16 2004/02/22 23:22:49 florian
- * fixed BeginThread on unix
- Revision 1.15 2004/02/22 16:48:39 florian
- * several 64 bit issues fixed
- Revision 1.14 2003/11/29 17:29:32 michael
- + Added overloaded version of SetThreadManager without old parameter
- Revision 1.13 2003/11/27 10:28:41 michael
- + Patch from peter to fix make cycle
- Revision 1.12 2003/11/26 20:10:59 michael
- + New threadmanager implementation
- Revision 1.11 2003/10/01 21:00:09 peter
- * GetCurrentThreadHandle renamed to GetCurrentThreadId
- Revision 1.10 2003/03/27 17:14:27 armin
- * more platform independent thread routines, needs to be implemented for unix
- Revision 1.9 2002/10/16 19:04:27 michael
- + More system-independent thread routines
- Revision 1.8 2002/10/14 19:39:17 peter
- * threads unit added for thread support
- Revision 1.7 2002/09/07 15:07:46 peter
- * old logs removed and tabs fixed
- Revision 1.6 2002/07/28 20:43:48 florian
- * several fixes for linux/powerpc
- * several fixes to MT
- }
|