~ubuntu-branches/debian/lenny/fpc/lenny

« back to all changes in this revision

Viewing changes to rtl/inc/threadh.inc

  • Committer: Bazaar Package Importer
  • Author(s): Mazen Neifer, Torsten Werner, Mazen Neifer
  • Date: 2008-05-17 17:12:11 UTC
  • mfrom: (3.1.9 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080517171211-9qi33xhd9evfa0kg
Tags: 2.2.0-dfsg1-9
[ Torsten Werner ]
* Add Mazen Neifer to Uploaders field.

[ Mazen Neifer ]
* Moved FPC sources into a version dependent directory from /usr/share/fpcsrc
  to /usr/share/fpcsrc/${FPCVERSION}. This allow installing more than on FPC
  release.
* Fixed far call issue in compiler preventing building huge binearies.
  (closes: #477743)
* Updated building dependencies, recomennded and suggested packages.
* Moved fppkg to fp-utils as it is just a helper tool and is not required by
  compiler.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
{
2
 
    $Id: threadh.inc,v 1.18 2004/05/23 20:26:20 marco Exp $
3
 
    This file is part of the Free Pascal Run time library.
4
 
    Copyright (c) 2000 by the Free Pascal development team
5
 
 
6
 
    This File contains the OS indenpendend declartions for multi
7
 
    threading support in FPC
8
 
 
9
 
    See the File COPYING.FPC, included in this distribution,
10
 
    for details about the copyright.
11
 
 
12
 
    This program is distributed in the hope that it will be useful,
13
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
 
 
16
 
 **********************************************************************}
17
 
 
18
 
const
19
 
   DefaultStackSize = 32768; { including 16384 margin for stackchecking }
20
 
 
21
 
 
22
 
type
23
 
  PEventState = pointer;
24
 
  TThreadFunc = function(parameter : pointer) : longint;
25
 
 
26
 
  // Function prototypes for TThreadManager Record.
27
 
  TBeginThreadHandler = Function (sa : Pointer;stacksize : dword; ThreadFunction : tthreadfunc;p : pointer;creationFlags : dword; var ThreadId : THandle) : DWord;
28
 
  TEndThreadHandler = Procedure (ExitCode : DWord);
29
 
  // Used for Suspend/Resume/Kill
30
 
  TThreadHandler = Function (threadHandle : dword) : dword;
31
 
  TThreadSwitchHandler = Procedure;
32
 
  TWaitForThreadTerminateHandler = Function (threadHandle : dword; TimeoutMs : longint) : dword;  {0=no timeout}
33
 
  TThreadSetPriorityHandler = Function (threadHandle : dword; Prio: longint): boolean;            {-15..+15, 0=normal}
34
 
  TThreadGetPriorityHandler = Function (threadHandle : dword): Integer;
35
 
  TGetCurrentThreadIdHandler = Function : dword;
36
 
  TCriticalSectionHandler = Procedure (var cs);
37
 
  TInitThreadVarHandler = Procedure(var offset : dword;size : dword);
38
 
  TRelocateThreadVarHandler = Function(offset : dword) : pointer;
39
 
  TAllocateThreadVarsHandler = Procedure;
40
 
  TReleaseThreadVarsHandler = Procedure;
41
 
  TBasicEventHandler        = procedure(state:peventstate);
42
 
  TBasicEventWaitForHandler = function (timeout:cardinal;state:peventstate):longint;
43
 
  TBasicEventCreateHandler  = function (EventAttributes :Pointer;  AManualReset,InitialState : Boolean;const Name:ansistring):pEventState;
44
 
 
45
 
  // TThreadManager interface.
46
 
  TThreadManager = Record
47
 
    InitManager            : Function : Boolean;
48
 
    DoneManager            : Function : Boolean;
49
 
    BeginThread            : TBeginThreadHandler;
50
 
    EndThread              : TEndThreadHandler;
51
 
    SuspendThread          : TThreadHandler;
52
 
    ResumeThread           : TThreadHandler;
53
 
    KillThread             : TThreadHandler;
54
 
    ThreadSwitch           : TThreadSwitchHandler;
55
 
    WaitForThreadTerminate : TWaitForThreadTerminateHandler;
56
 
    ThreadSetPriority      : TThreadSetPriorityHandler;
57
 
    ThreadGetPriority      : TThreadGetPriorityHandler;
58
 
    GetCurrentThreadId     : TGetCurrentThreadIdHandler;
59
 
    InitCriticalSection    : TCriticalSectionHandler;
60
 
    DoneCriticalSection    : TCriticalSectionHandler;
61
 
    EnterCriticalSection   : TCriticalSectionHandler;
62
 
    LeaveCriticalSection   : TCriticalSectionHandler;
63
 
    InitThreadVar          : TInitThreadVarHandler;
64
 
    RelocateThreadVar      : TRelocateThreadVarHandler;
65
 
    AllocateThreadVars     : TAllocateThreadVarsHandler;
66
 
    ReleaseThreadVars      : TReleaseThreadVarsHandler;
67
 
    BasicEventCreate       : TBasicEventCreateHandler;
68
 
    BasicEventDestroy      : TBasicEventHandler; 
69
 
    BasicEventResetEvent   : TBasicEventHandler; 
70
 
    BasicEventSetEvent     : TBasicEventHandler; 
71
 
    BasiceventWaitFOr      : TBasicEventWaitForHandler;
72
 
  end;
73
 
 
74
 
{*****************************************************************************
75
 
                         Thread Handler routines
76
 
*****************************************************************************}
77
 
 
78
 
 
79
 
Function GetThreadManager(Var TM : TThreadManager) : Boolean;
80
 
Function SetThreadManager(Const NewTM : TThreadManager; Var OldTM : TThreadManager) : Boolean;
81
 
Function SetThreadManager(Const NewTM : TThreadManager) : Boolean;
82
 
Procedure SetNoThreadManager;
83
 
// Needs to be exported, so the manager can call it.
84
 
{$ifdef HASTHREADVAR}
85
 
procedure InitThreadVars(RelocProc : Pointer);
86
 
{$endif HASTHREADVAR}
87
 
procedure InitThread(stklen:cardinal);
88
 
 
89
 
{*****************************************************************************
90
 
                         Multithread Handling
91
 
*****************************************************************************}
92
 
 
93
 
function BeginThread(sa : Pointer;stacksize : dword;
94
 
  ThreadFunction : tthreadfunc;p : pointer;creationFlags : dword;
95
 
  var ThreadId : THandle) : DWord;
96
 
{$ifndef CPU64}
97
 
{$ifndef unix}
98
 
{ Delphi uses a longint for threadid }
99
 
function BeginThread(sa : Pointer;stacksize : dword;
100
 
  ThreadFunction : tthreadfunc;p : pointer;creationFlags : dword;
101
 
  var ThreadId : Longint) : DWord;
102
 
{$endif unix}
103
 
{$endif CPU64}
104
 
 
105
 
{ add some simplfied forms which make lifer easier and porting }
106
 
{ to other OSes too ...                                        }
107
 
function BeginThread(ThreadFunction : tthreadfunc) : DWord;
108
 
function BeginThread(ThreadFunction : tthreadfunc;p : pointer) : DWord;
109
 
function BeginThread(ThreadFunction : tthreadfunc;p : pointer; var ThreadId : THandle) : DWord;
110
 
{$ifndef CPU64}
111
 
{$ifndef unix}
112
 
function BeginThread(ThreadFunction : tthreadfunc;p : pointer; var ThreadId : Longint) : DWord;
113
 
{$endif unix}
114
 
{$endif CPU64}
115
 
 
116
 
procedure EndThread(ExitCode : DWord);
117
 
procedure EndThread;
118
 
 
119
 
{some thread support functions}
120
 
function  SuspendThread (threadHandle : dword) : dword;
121
 
function  ResumeThread  (threadHandle : dword) : dword;
122
 
procedure ThreadSwitch;                                                                {give time to other threads}
123
 
function  KillThread (threadHandle : dword) : dword;
124
 
function  WaitForThreadTerminate (threadHandle : dword; TimeoutMs : longint) : dword;  {0=no timeout}
125
 
function  ThreadSetPriority (threadHandle : dword; Prio: longint): boolean;            {-15..+15, 0=normal}
126
 
function  ThreadGetPriority (threadHandle : dword): Integer;
127
 
function  GetCurrentThreadId : dword;
128
 
 
129
 
 
130
 
{ this allows to do a lot of things in MT safe way }
131
 
{ it is also used to make the heap management      }
132
 
{ thread safe                                      }
133
 
procedure InitCriticalSection(var cs : TRTLCriticalSection);
134
 
procedure DoneCriticalsection(var cs : TRTLCriticalSection);
135
 
procedure EnterCriticalsection(var cs : TRTLCriticalSection);
136
 
procedure LeaveCriticalsection(var cs : TRTLCriticalSection);
137
 
 
138
 
function  BasicEventCreate(EventAttributes : Pointer; AManualReset,InitialState : Boolean;const Name : ansistring):pEventState;
139
 
procedure basiceventdestroy(state:peventstate);
140
 
procedure basiceventResetEvent(state:peventstate);
141
 
procedure basiceventSetEvent(state:peventstate);
142
 
function  basiceventWaitFor(Timeout : Cardinal;state:peventstate) : longint;
143
 
 
144
 
{
145
 
  $Log: threadh.inc,v $
146
 
  Revision 1.18  2004/05/23 20:26:20  marco
147
 
   * wrappers and nothread prototypes for the basic* functions
148
 
 
149
 
  Revision 1.17  2004/05/23 15:30:29  marco
150
 
   * first try basicevent
151
 
 
152
 
  Revision 1.16  2004/02/22 23:22:49  florian
153
 
    * fixed BeginThread on unix
154
 
 
155
 
  Revision 1.15  2004/02/22 16:48:39  florian
156
 
    * several 64 bit issues fixed
157
 
 
158
 
  Revision 1.14  2003/11/29 17:29:32  michael
159
 
  + Added overloaded version of SetThreadManager without old parameter
160
 
 
161
 
  Revision 1.13  2003/11/27 10:28:41  michael
162
 
  + Patch from peter to fix make cycle
163
 
 
164
 
  Revision 1.12  2003/11/26 20:10:59  michael
165
 
  + New threadmanager implementation
166
 
 
167
 
  Revision 1.11  2003/10/01 21:00:09  peter
168
 
    * GetCurrentThreadHandle renamed to GetCurrentThreadId
169
 
 
170
 
  Revision 1.10  2003/03/27 17:14:27  armin
171
 
  * more platform independent thread routines, needs to be implemented for unix
172
 
 
173
 
  Revision 1.9  2002/10/16 19:04:27  michael
174
 
  + More system-independent thread routines
175
 
 
176
 
  Revision 1.8  2002/10/14 19:39:17  peter
177
 
    * threads unit added for thread support
178
 
 
179
 
  Revision 1.7  2002/09/07 15:07:46  peter
180
 
    * old logs removed and tabs fixed
181
 
 
182
 
  Revision 1.6  2002/07/28 20:43:48  florian
183
 
    * several fixes for linux/powerpc
184
 
    * several fixes to MT
185
 
}