2
$Id: pthread.inc,v 1.4 2004/05/23 18:49:18 marco Exp $
2
$Id: pthread.inc,v 1.6 2005/02/14 17:13:30 peter Exp $
3
3
This file is part of the Free Pascal run time library.
4
4
Copyright (c) 1999-2000 by Peter Vreman
5
5
member of the Free Pascal development team.
29
29
THREAD_PRIORITY_HIGHEST = 80;
30
30
THREAD_PRIORITY_TIME_CRITICAL = 99;
31
31
PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP : array [0..5]of Integer = (0, 0, 0, 1, 0, 0);
32
PTHREAD_MUTEX_RECURSIVE = 1;
39
TSemLock = __sem_lock_t;
43
__sem_lock: __sem_lock_t;
45
__sem_waiting: pointer;
48
35
TSemaphore = sem_t;
49
36
PSemaphore = ^TSemaphore;
58
45
THREAD_PRIORITY_HIGHEST, THREAD_PRIORITY_TIME_CRITICAL
62
psched_param = ^sched_param;
64
sched_priority : LongInt;
67
ptimespec = ^timespec;
73
50
psigset_t = ^sigset_t;
74
51
sigset_t = DWORD; // unsigned long 32 bits
77
55
_POSIX_THREAD_THREADS_MAX = 64;
80
58
PTHREAD_KEYS_MAX = 128;
84
61
ppthread_t = ^pthread_t;
86
63
p_pthread_queue = ^_pthread_queue;
87
_pthread_queue = record
92
ppthread_mutex_t = PRtlCriticalSection;
93
pthread_mutex_t = TRtlCriticalSection;
65
ppthread_mutex_t = ^pthread_mutex_t;
95
67
ppthread_cond_t = ^pthread_cond_t;
96
pthread_cond_t = record
98
c_waiting : _pthread_queue;
109
77
PTHREAD_SCOPE_PROCESS = 1;
80
psched_param = ^sched_param;
114
82
ppthread_attr_t = ^pthread_attr_t;
115
pthread_attr_t = record
116
detachstate : longint;
117
schedpolicy : longint;
118
schedparam : sched_param;
119
inheritsched : longint;
121
__guardsize : size_t;
122
__stackaddr_set : longint;
123
__stackaddr : pointer;
124
__stacksize : size_t;
127
84
ppthread_mutexattr_t = ^pthread_mutexattr_t;
128
pthread_mutexattr_t = record
131
pthread_mutex_attr_t = pthread_mutexattr_t;
133
86
ppthread_condattr_t = ^pthread_condattr_t;
134
pthread_condattr_t = record
138
88
ppthread_key_t = ^pthread_key_t;
139
pthread_key_t = cardinal;
141
ppthread_once_t = ^pthread_once_t;
142
pthread_once_t = longint;
90
{ pthread_once_t = cint;
91
ppthread_once_t = ^pthread_once_t;}
145
94
PTHREAD_ONCE_INIT = 0;
148
98
tpcb_routine = Procedure(P:Pointer); cdecl;
150
100
p_pthread_cleanup_buffer = ^_pthread_cleanup_buffer;
154
104
canceltype:LongInt; { Saved cancellation type. }
155
105
prev : p_pthread_cleanup_buffer; { Chaining of cleanup functions. }
158
109
__start_routine_t = function (_para1:pointer):pointer;cdecl;
159
110
__destr_function_t = procedure (_para1:pointer);
160
t_pthread_cleanup_push_routine = procedure (_para1:pointer);
161
t_pthread_cleanup_push_defer_routine = procedure (_para1:pointer);
111
{ t_pthread_cleanup_push_routine = procedure (_para1:pointer);
112
t_pthread_cleanup_push_defer_routine = procedure (_para1:pointer);}
163
114
{$ifndef dynpthreads}
164
115
function pthread_create(__thread:ppthread_t; __attr:ppthread_attr_t;__start_routine: __start_routine_t;__arg:pointer):longint;cdecl;external;
202
153
function pthread_key_delete(__key:pthread_key_t):longint;cdecl;external;
203
154
function pthread_setspecific(__key:pthread_key_t; __pointer:pointer):longint;cdecl;external;
204
155
function pthread_getspecific(__key:pthread_key_t):pointer;cdecl;external;
205
function pthread_once(__once_control:ppthread_once_t; __init_routine:tprocedure ):longint;cdecl;external;
156
{ function pthread_once(__once_control:ppthread_once_t; __init_routine:tprocedure ):longint;cdecl;external;}
206
157
function pthread_setcancelstate(__state:longint; __oldstate:plongint):longint;cdecl;external;
207
158
function pthread_setcanceltype(__type:longint; __oldtype:plongint):longint;cdecl;external;
208
159
function pthread_cancel(__thread:pthread_t):longint;cdecl;external;
209
160
procedure pthread_testcancel;cdecl;external;
210
procedure _pthread_cleanup_push(__buffer:p_pthread_cleanup_buffer;__routine:t_pthread_cleanup_push_routine; __arg:pointer);cdecl;external;
211
procedure _pthread_cleanup_push_defer(__buffer:p_pthread_cleanup_buffer;__routine:t_pthread_cleanup_push_defer_routine; __arg:pointer);cdecl;external;
212
function pthread_sigmask(__how:longint; __newmask:psigset_t; __oldmask:psigset_t):longint;cdecl;external;
161
{ procedure _pthread_cleanup_push(__buffer:p_pthread_cleanup_buffer;__routine:t_pthread_cleanup_push_routine; __arg:pointer);cdecl;external; }
162
{ procedure _pthread_cleanup_push_defer(__buffer:p_pthread_cleanup_buffer;__routine:t_pthread_cleanup_push_defer_routine; __arg:pointer);cdecl;external;}
163
{ function pthread_sigmask(__how:longint; __newmask:psigset_t; __oldmask:psigset_t):longint;cdecl;external;}
213
164
function pthread_kill(__thread:pthread_t; __signo:longint):longint;cdecl;external;
214
function sigwait(__set:psigset_t; __sig:plongint):longint;cdecl;external;
165
{ function sigwait(__set:psigset_t; __sig:plongint):longint;cdecl;external;}
215
166
function pthread_atfork(__prepare:tprocedure ; __parent:tprocedure ; __child:tprocedure ):longint;cdecl;external;
216
167
procedure pthread_kill_other_threads_np;cdecl;external;
169
function sem_init (__sem:Psem_t; __pshared:longint; __value:dword):longint;cdecl;external;
170
function sem_destroy (__sem:Psem_t):longint;cdecl;external;
171
function sem_close (__sem:Psem_t):longint;cdecl;external;
172
function sem_unlink (__name:Pchar):longint;cdecl;external;
173
function sem_wait (__sem:Psem_t):longint;cdecl;external;
174
function sem_trywait (__sem:Psem_t):longint;cdecl;external;
175
function sem_post (__sem:Psem_t):longint;cdecl;external;
176
function sem_getvalue (__sem:Psem_t; __sval:Plongint):longint;cdecl;external;
178
function pthread_mutexattr_settype (__attr: Ppthread_mutexattr_t; Kind:Integer): Integer; cdecl;external;
219
182
pthread_create : Function(__thread:ppthread_t; __attr:ppthread_attr_t;__start_routine: __start_routine_t;__arg:pointer):longint;cdecl;
257
220
pthread_key_delete : Function(__key:pthread_key_t):longint;cdecl;
258
221
pthread_setspecific : Function(__key:pthread_key_t; __pointer:pointer):longint;cdecl;
259
222
pthread_getspecific : Function(__key:pthread_key_t):pointer;cdecl;
260
pthread_once : Function(__once_control:ppthread_once_t; __init_routine:tprocedure ):longint;cdecl;
223
{ pthread_once : Function(__once_control:ppthread_once_t; __init_routine:tprocedure ):longint;cdecl;}
261
224
pthread_setcancelstate : Function(__state:longint; __oldstate:plongint):longint;cdecl;
262
225
pthread_setcanceltype : Function(__type:longint; __oldtype:plongint):longint;cdecl;
263
226
pthread_cancel : Function(__thread:pthread_t):longint;cdecl;
264
227
pthread_testcancel : Procedure ;cdecl;
265
_pthread_cleanup_push : procedure (__buffer:p_pthread_cleanup_buffer;__routine:t_pthread_cleanup_push_routine; __arg:pointer);cdecl;
266
_pthread_cleanup_push_defer : procedure (__buffer:p_pthread_cleanup_buffer;__routine:t_pthread_cleanup_push_defer_routine; __arg:pointer);cdecl;
267
pthread_sigmask : Function(__how:longint; __newmask:psigset_t; __oldmask:psigset_t):longint;cdecl;
228
{ _pthread_cleanup_push : procedure (__buffer:p_pthread_cleanup_buffer;__routine:t_pthread_cleanup_push_routine; __arg:pointer);cdecl;}
229
{ _pthread_cleanup_push_defer : procedure (__buffer:p_pthread_cleanup_buffer;__routine:t_pthread_cleanup_push_defer_routine; __arg:pointer);cdecl;}
230
{ pthread_sigmask : Function(__how:longint; __newmask:psigset_t; __oldmask:psigset_t):longint;cdecl;}
268
231
pthread_kill : Function(__thread:pthread_t; __signo:longint):longint;cdecl;
269
sigwait : Function(__set:psigset_t; __sig:plongint):longint;cdecl;
232
{ sigwait : Function(__set:psigset_t; __sig:plongint):longint;cdecl;}
270
233
pthread_atfork : Function(__prepare:tprocedure ; __parent:tprocedure ; __child:tprocedure ):longint;cdecl;
271
234
pthread_kill_other_threads_np : procedure;cdecl;
291
254
PThreadDLL:=DlOpen('libpthread.so.0',RTLD_LAZY);
292
255
Result:=PThreadDLL<>Nil;
295
258
Pointer(pthread_create) := dlsym(PthreadDLL,'pthread_create');
296
259
Pointer(pthread_self) := dlsym(PthreadDLL,'pthread_self');
333
296
Pointer(pthread_key_delete) := dlsym(PthreadDLL,'pthread_key_delete');
334
297
Pointer(pthread_setspecific) := dlsym(PthreadDLL,'pthread_setspecific');
335
298
Pointer(pthread_getspecific) := dlsym(PthreadDLL,'pthread_getspecific');
336
Pointer(pthread_once) := dlsym(PthreadDLL,'pthread_once');
299
{ Pointer(pthread_once) := dlsym(PthreadDLL,'pthread_once');}
337
300
Pointer(pthread_setcancelstate) := dlsym(PthreadDLL,'pthread_setcancelstate');
338
301
Pointer(pthread_setcanceltype) := dlsym(PthreadDLL,'pthread_setcanceltype');
339
302
Pointer(pthread_cancel) := dlsym(PthreadDLL,'pthread_cancel');
340
303
Pointer(pthread_testcancel) := dlsym(PthreadDLL,'pthread_testcancel');
341
Pointer(_pthread_cleanup_push) := dlsym(PthreadDLL,'_pthread_cleanup_push');
342
Pointer(_pthread_cleanup_push_defer) := dlsym(PthreadDLL,'_pthread_cleanup_push_defer');
343
Pointer(pthread_sigmask) := dlsym(PthreadDLL,'pthread_sigmask');
304
{ Pointer(_pthread_cleanup_push) := dlsym(PthreadDLL,'_pthread_cleanup_push');}
305
{ Pointer(_pthread_cleanup_push_defer) := dlsym(PthreadDLL,'_pthread_cleanup_push_defer');}
306
{ Pointer(pthread_sigmask) := dlsym(PthreadDLL,'pthread_sigmask');}
344
307
Pointer(pthread_kill) := dlsym(PthreadDLL,'pthread_kill');
345
308
Pointer(pthread_atfork):= dlsym(PthreadDLL,'pthread_atfork');
346
309
Pointer(pthread_kill_other_threads_np) := dlsym(PthreadDLL,'pthread_kill_other_threads_np');
361
324
Result:=dlclose(PThreadDLL)=0;
367
330
$Log: pthread.inc,v $
368
Revision 1.4 2004/05/23 18:49:18 marco
371
Revision 1.3 2003/11/26 20:10:59 michael
372
+ New threadmanager implementation
374
Revision 1.2 2003/09/14 20:15:01 marco
375
* Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
377
Revision 1.1 2002/10/18 18:03:57 marco
378
* From the original systhrds code.
379
Turned out to be not entirely the same as *BSD's (constants with
380
different names, existing and non existing constants), so I decided to
381
make it platform dependant.
b'\\ No newline at end of file'
331
Revision 1.6 2005/02/14 17:13:30 peter