1{
2    This file is part of the Free Pascal run time library.
3    Copyright (c) 1999-2000 by Peter Vreman
4    member of the Free Pascal development team.
5
6    See the file COPYING.FPC, included in this distribution,
7    for details about the copyright.
8
9    This file contains a pthread.h headerconversion for Linux.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
15 **********************************************************************}
16
17{*****************************************************************************
18                   Local POSIX Threads (pthread) imports
19*****************************************************************************}
20
21  { Attributes  }
22  const
23     THREAD_PRIORITY_IDLE               = 1;
24     THREAD_PRIORITY_LOWEST             = 15;
25     THREAD_PRIORITY_BELOW_NORMAL       = 30;
26     THREAD_PRIORITY_NORMAL             = 50;
27     THREAD_PRIORITY_ABOVE_NORMAL       = 70;
28     THREAD_PRIORITY_HIGHEST            = 80;
29     THREAD_PRIORITY_TIME_CRITICAL      = 99;
30     //PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP : array [0..5]of Integer = (0, 0, 0, 1, 0, 0);
31
32Type
33   psem_t = ^sem_t;
34   TSemaphore = sem_t;
35   PSemaphore = ^TSemaphore;
36
37{$ifndef FPC_USE_LIBC}
38   tlibc_sigset = array[0..(1024 div 32)-1] of cuLong;
39   plibc_sigset = ^tlibc_sigset;
40{$else not FPC_USE_LIBC}
41   tlibc_sigset = tsigset;
42   plibc_sigset = psigset;
43{$endif not FPC_USE_LIBC}
44
45     TThreadPriority = (tpIdle, tpLowest, tpLower, tpNormal, tpHigher, tpHighest, tpTimeCritical);
46{
47  const
48     Priorities: array [TThreadPriority] of Integer = (
49       THREAD_PRIORITY_IDLE, THREAD_PRIORITY_LOWEST, THREAD_PRIORITY_BELOW_NORMAL,
50       THREAD_PRIORITY_NORMAL, THREAD_PRIORITY_ABOVE_NORMAL,
51       THREAD_PRIORITY_HIGHEST, THREAD_PRIORITY_TIME_CRITICAL
52     );
53}
54  const
55     _POSIX_THREAD_THREADS_MAX = 64;
56     PTHREAD_THREADS_MAX = 512;
57     _POSIX_THREAD_KEYS_MAX = 128;
58     PTHREAD_KEYS_MAX = 128;
59
60  type
61    ppthread_t = ^pthread_t;
62{
63     p_pthread_queue = ^_pthread_queue;
64}
65     ppthread_mutex_t = ^pthread_mutex_t;
66
67     ppthread_cond_t = ^pthread_cond_t;
68
69     { Attributes  }
70
71    const
72      PTHREAD_CREATE_JOINABLE = 0;
73      PTHREAD_CREATE_DETACHED = 1;
74      PTHREAD_INHERIT_SCHED   = 0;
75      PTHREAD_EXPLICIT_SCHED  = 1;
76      PTHREAD_SCOPE_SYSTEM    = 0;
77      PTHREAD_SCOPE_PROCESS   = 1;
78
79    type
80       psched_param = ^sched_param;
81
82       ppthread_attr_t = ^pthread_attr_t;
83
84       ppthread_mutexattr_t = ^pthread_mutexattr_t;
85
86       ppthread_condattr_t = ^pthread_condattr_t;
87
88       ppthread_key_t = ^pthread_key_t;
89
90{      pthread_once_t = cint;
91       ppthread_once_t = ^pthread_once_t;}
92
93    const
94       PTHREAD_ONCE_INIT = 0;
95
96    type
97(*
98       tpcb_routine = Procedure(P:Pointer); cdecl;
99
100       p_pthread_cleanup_buffer = ^_pthread_cleanup_buffer;
101       _pthread_cleanup_buffer = record
102          routine : tpcb_routine;             { Function to call. }
103          arg : Pointer;                      { Its argument.  }
104          canceltype:LongInt;                 { Saved cancellation type. }
105          prev : p_pthread_cleanup_buffer; { Chaining of cleanup functions.  }
106       end;
107*)
108
109     __start_routine_t = function (_para1:pointer):pointer;cdecl;
110     __destr_function_t = procedure (_para1:pointer);cdecl;
111{     t_pthread_cleanup_push_routine = procedure (_para1:pointer);
112     t_pthread_cleanup_push_defer_routine = procedure (_para1:pointer);}
113
114{$ifndef dynpthreads}
115    function pthread_create(__thread:ppthread_t; __attr:ppthread_attr_t;__start_routine: __start_routine_t;__arg:pointer):longint;cdecl;external;
116    function pthread_self:pthread_t;cdecl;external;
117    function pthread_equal(__thread1:pthread_t; __thread2:pthread_t):longint;cdecl;external;
118    procedure pthread_exit(__retval:pointer);cdecl;external;
119    function pthread_join(__th:pthread_t; __thread_return:ppointer):longint;cdecl;external;
120    function pthread_detach(__th:pthread_t):longint;cdecl;external;
121    function pthread_attr_init(__attr:ppthread_attr_t):longint;cdecl;external;
122    function pthread_attr_destroy(__attr:ppthread_attr_t):longint;cdecl;external;
123    function pthread_attr_setdetachstate(__attr:ppthread_attr_t; __detachstate:longint):longint;cdecl;external;
124    function pthread_attr_getdetachstate(__attr:ppthread_attr_t; __detachstate:plongint):longint;cdecl;external;
125    function pthread_attr_setschedparam(__attr:ppthread_attr_t; __param:psched_param):longint;cdecl;external;
126    function pthread_attr_getschedparam(__attr:ppthread_attr_t; __param:psched_param):longint;cdecl;external;
127    function pthread_attr_setschedpolicy(__attr:ppthread_attr_t; __policy:longint):longint;cdecl;external;
128    function pthread_attr_getschedpolicy(__attr:ppthread_attr_t; __policy:plongint):longint;cdecl;external;
129{$ifndef ANDROID}
130    function pthread_attr_setinheritsched(__attr:ppthread_attr_t; __inherit:longint):longint;cdecl;external;
131    function pthread_attr_getinheritsched(__attr:ppthread_attr_t; __inherit:plongint):longint;cdecl;external;
132{$endif}
133    function pthread_attr_setstacksize(p: ppthread_attr_t;s:size_t):cint;cdecl;external;
134    function pthread_attr_getstacksize(p: ppthread_attr_t;s:psize_t):cint;cdecl;external;
135    function pthread_attr_setscope(__attr:ppthread_attr_t; __scope:longint):longint;cdecl;external;
136    function pthread_attr_getscope(__attr:ppthread_attr_t; __scope:plongint):longint;cdecl;external;
137    function pthread_setschedparam(__target_thread:pthread_t; __policy:longint; __param:psched_param):longint;cdecl;external;
138    function pthread_getschedparam(__target_thread:pthread_t; __policy:plongint; __param:psched_param):longint;cdecl;external;
139    function pthread_mutex_init(__mutex:ppthread_mutex_t; __mutex_attr:ppthread_mutexattr_t):longint;cdecl;external;
140    function pthread_mutex_destroy(__mutex:ppthread_mutex_t):longint;cdecl;external;
141    function pthread_mutex_trylock(__mutex:ppthread_mutex_t):longint;cdecl;external;
142    function pthread_mutex_lock(__mutex:ppthread_mutex_t):longint;cdecl;external;
143    function pthread_mutex_unlock(__mutex:ppthread_mutex_t):longint;cdecl;external;
144    function pthread_mutexattr_init(__attr:ppthread_mutexattr_t):longint;cdecl;external;
145    function pthread_mutexattr_destroy(__attr:ppthread_mutexattr_t):longint;cdecl;external;
146{$ifndef ANDROID}
147    function pthread_mutexattr_setkind_np(__attr:ppthread_mutexattr_t; __kind:longint):longint;cdecl;external;
148    function pthread_mutexattr_getkind_np(__attr:ppthread_mutexattr_t; __kind:plongint):longint;cdecl;external;
149{$endif}
150    function pthread_cond_init(__cond:ppthread_cond_t; __cond_attr:ppthread_condattr_t):longint;cdecl;external;
151    function pthread_cond_destroy(__cond:ppthread_cond_t):longint;cdecl;external;
152    function pthread_cond_signal(__cond:ppthread_cond_t):longint;cdecl;external;
153    function pthread_cond_broadcast(__cond:ppthread_cond_t):longint;cdecl;external;
154    function pthread_cond_wait(__cond:ppthread_cond_t; __mutex:ppthread_mutex_t):longint;cdecl;external;
155    function pthread_cond_timedwait(__cond:ppthread_cond_t; __mutex:ppthread_mutex_t; __abstime:ptimespec):longint;cdecl;external;
156{$ifndef ANDROID}
157    function pthread_condattr_init(__attr:ppthread_condattr_t):longint;cdecl;external;
158    function pthread_condattr_destroy(__attr:ppthread_condattr_t):longint;cdecl;external;
159    function pthread_condattr_setclock(__attr:ppthread_condattr_t; __clock_id: longint):longint;cdecl;external;
160{$endif}
161    function pthread_key_create(__key:ppthread_key_t; __destr_function:__destr_function_t):longint;cdecl;external;
162    function pthread_key_delete(__key:pthread_key_t):longint;cdecl;external;
163    function pthread_setspecific(__key:pthread_key_t; __pointer:pointer):longint;cdecl;external;
164    function pthread_getspecific(__key:pthread_key_t):pointer;cdecl;external;
165{    function pthread_once(__once_control:ppthread_once_t; __init_routine:tprocedure ):longint;cdecl;external;}
166{$ifndef ANDROID}
167    function pthread_setcancelstate(__state:longint; __oldstate:plongint):longint;cdecl;external;
168    function pthread_setcanceltype(__type:longint; __oldtype:plongint):longint;cdecl;external;
169    function pthread_cancel(__thread:pthread_t):longint;cdecl;external;
170    procedure pthread_testcancel;cdecl;external;
171{$endif}
172{    procedure _pthread_cleanup_push(__buffer:p_pthread_cleanup_buffer;__routine:t_pthread_cleanup_push_routine; __arg:pointer);cdecl;external; }
173{    procedure _pthread_cleanup_push_defer(__buffer:p_pthread_cleanup_buffer;__routine:t_pthread_cleanup_push_defer_routine; __arg:pointer);cdecl;external;}
174{    function pthread_sigmask(__how:longint; __newmask:plibc_sigset; __oldmask:plibc_sigset):longint;cdecl;external;}
175    function pthread_kill(__thread:pthread_t; __signo:longint):longint;cdecl;external;
176{    function sigwait(__set:plibc_sigset; __sig:plongint):longint;cdecl;external;}
177{$ifndef ANDROID}
178    function pthread_atfork(__prepare:tprocedure ; __parent:tprocedure ; __child:tprocedure ):longint;cdecl;external;
179    procedure pthread_kill_other_threads_np;cdecl;external;
180{$endif}
181    function pthread_sigmask(how: cint; nset: plibc_sigset; oset: plibc_sigset): cint; cdecl; external;
182
183    function sem_init (__sem:Psem_t; __pshared:longint; __value:dword):longint;cdecl;external;
184    function sem_destroy  (__sem:Psem_t):longint;cdecl;external;
185    function sem_close (__sem:Psem_t):longint;cdecl;external;
186    function sem_unlink (__name:Pchar):longint;cdecl;external;
187    function sem_wait (__sem:Psem_t):longint;cdecl;external;
188    function sem_timedwait (__sem:Psem_t; __abs_timeout:ptimespec):longint;cdecl;external;
189    function sem_trywait  (__sem:Psem_t):longint;cdecl;external;
190    function sem_post     (__sem:Psem_t):longint;cdecl;external;
191    function sem_getvalue (__sem:Psem_t; __sval:Plongint):longint;cdecl;external;
192
193    function pthread_mutexattr_settype (__attr: Ppthread_mutexattr_t; Kind:Integer): Integer; cdecl;external;
194    function pthread_setname_np(thread: pthread_t; name: PAnsiChar):cint;cdecl;external;
195
196{$else}
197Var
198    pthread_create : Function(__thread:ppthread_t; __attr:ppthread_attr_t;__start_routine: __start_routine_t;__arg:pointer):longint;cdecl;
199    pthread_self: Function : pthread_t;cdecl;
200    pthread_equal : Function(__thread1:pthread_t; __thread2:pthread_t):longint;cdecl;
201    pthread_exit : procedure (__retval:pointer);cdecl;
202    pthread_join : Function(__th:pthread_t; __thread_return:ppointer):longint;cdecl;
203    pthread_detach : Function(__th:pthread_t):longint;cdecl;
204    pthread_attr_init : Function(__attr:ppthread_attr_t):longint;cdecl;
205    pthread_attr_destroy : Function(__attr:ppthread_attr_t):longint;cdecl;
206    pthread_attr_setdetachstate : Function(__attr:ppthread_attr_t; __detachstate:longint):longint;cdecl;
207    pthread_attr_getdetachstate : Function(__attr:ppthread_attr_t; __detachstate:plongint):longint;cdecl;
208    pthread_attr_setschedparam : Function(__attr:ppthread_attr_t; __param:psched_param):longint;cdecl;
209    pthread_attr_getschedparam : Function(__attr:ppthread_attr_t; __param:psched_param):longint;cdecl;
210    pthread_attr_setschedpolicy : Function(__attr:ppthread_attr_t; __policy:longint):longint;cdecl;
211    pthread_attr_getschedpolicy : Function(__attr:ppthread_attr_t; __policy:plongint):longint;cdecl;
212{$ifndef ANDROID}
213    pthread_attr_setinheritsched : Function(__attr:ppthread_attr_t; __inherit:longint):longint;cdecl;
214    pthread_attr_getinheritsched : Function(__attr:ppthread_attr_t; __inherit:plongint):longint;cdecl;
215{$endif}
216    pthread_attr_setscope : Function(__attr:ppthread_attr_t; __scope:longint):longint;cdecl;
217    pthread_attr_getscope : Function(__attr:ppthread_attr_t; __scope:plongint):longint;cdecl;
218    pthread_setschedparam : Function(__target_thread:pthread_t; __policy:longint; __param:psched_param):longint;cdecl;
219    pthread_getschedparam : Function(__target_thread:pthread_t; __policy:plongint; __param:psched_param):longint;cdecl;
220    pthread_attr_setstacksize : Function(p: ppthread_attr_t;s:size_t):cint;cdecl;
221    pthread_mutex_init : Function(__mutex:ppthread_mutex_t; __mutex_attr:ppthread_mutexattr_t):longint;cdecl;
222    pthread_mutex_destroy : Function(__mutex:ppthread_mutex_t):longint;cdecl;
223    pthread_mutex_trylock : Function(__mutex:ppthread_mutex_t):longint;cdecl;
224    pthread_mutex_lock : Function(__mutex:ppthread_mutex_t):longint;cdecl;
225    pthread_mutex_unlock : Function(__mutex:ppthread_mutex_t):longint;cdecl;
226    pthread_mutexattr_init : Function(__attr:ppthread_mutexattr_t):longint;cdecl;
227    pthread_mutexattr_destroy : Function(__attr:ppthread_mutexattr_t):longint;cdecl;
228{$ifndef ANDROID}
229    pthread_mutexattr_setkind_np : Function(__attr:ppthread_mutexattr_t; __kind:longint):longint;cdecl;
230    pthread_mutexattr_getkind_np : Function(__attr:ppthread_mutexattr_t; __kind:plongint):longint;cdecl;
231{$endif}
232    pthread_cond_init : Function(__cond:ppthread_cond_t; __cond_attr:ppthread_condattr_t):longint;cdecl;
233    pthread_cond_destroy : Function(__cond:ppthread_cond_t):longint;cdecl;
234    pthread_cond_signal : Function(__cond:ppthread_cond_t):longint;cdecl;
235    pthread_cond_broadcast : Function(__cond:ppthread_cond_t):longint;cdecl;
236    pthread_cond_wait : Function(__cond:ppthread_cond_t; __mutex:ppthread_mutex_t):longint;cdecl;
237    pthread_cond_timedwait : Function(__cond:ppthread_cond_t; __mutex:ppthread_mutex_t; __abstime:ptimespec):longint;cdecl;
238{$ifndef ANDROID}
239    pthread_condattr_init : Function(__attr:ppthread_condattr_t):longint;cdecl;
240    pthread_condattr_destroy : Function(__attr:ppthread_condattr_t):longint;cdecl;
241    pthread_condattr_setclock: Function(__attr:ppthread_condattr_t; __clock_id: longint):longint;cdecl;
242{$endif}
243    pthread_key_create : Function(__key:ppthread_key_t; __destr_function:__destr_function_t):longint;cdecl;
244    pthread_key_delete : Function(__key:pthread_key_t):longint;cdecl;
245    pthread_setspecific : Function(__key:pthread_key_t; __pointer:pointer):longint;cdecl;
246    pthread_getspecific : Function(__key:pthread_key_t):pointer;cdecl;
247{    pthread_once : Function(__once_control:ppthread_once_t; __init_routine:tprocedure ):longint;cdecl;}
248{$ifndef ANDROID}
249    pthread_setcancelstate : Function(__state:longint; __oldstate:plongint):longint;cdecl;
250    pthread_setcanceltype : Function(__type:longint; __oldtype:plongint):longint;cdecl;
251    pthread_cancel : Function(__thread:pthread_t):longint;cdecl;
252    pthread_testcancel : Procedure ;cdecl;
253{$endif}
254{    _pthread_cleanup_push : procedure (__buffer:p_pthread_cleanup_buffer;__routine:t_pthread_cleanup_push_routine; __arg:pointer);cdecl;}
255{    _pthread_cleanup_push_defer : procedure (__buffer:p_pthread_cleanup_buffer;__routine:t_pthread_cleanup_push_defer_routine; __arg:pointer);cdecl;}
256{    pthread_sigmask : Function(__how:longint; __newmask:plibc_sigset; __oldmask:plibc_sigset):longint;cdecl;}
257    pthread_kill : Function(__thread:pthread_t; __signo:longint):longint;cdecl;
258{    sigwait : Function(__set:plibc_sigset; __sig:plongint):longint;cdecl;}
259{$ifndef ANDROID}
260    pthread_atfork : Function(__prepare:tprocedure ; __parent:tprocedure ; __child:tprocedure ):longint;cdecl;
261    pthread_kill_other_threads_np : procedure;cdecl;
262{$endif}
263    pthread_sigmask: Function(how: cint; nset: plibc_sigset; oset: plibc_sigset): cint;cdecl;
264
265    sem_init     :   function (__sem:Psem_t; __pshared:longint; __value:dword):longint;cdecl;
266    sem_destroy  :   function (__sem:Psem_t):longint;cdecl;
267    sem_close    :   function (__sem:Psem_t):longint;cdecl;
268    sem_unlink   :   function (__name:Pchar):longint;cdecl;
269    sem_wait     :   function (__sem:Psem_t):longint;cdecl;
270    sem_timedwait:   function (__sem:Psem_t; __abs_timeout:ptimespec):longint;cdecl;
271    sem_trywait  :   function (__sem:Psem_t):longint;cdecl;
272    sem_post     :   function (__sem:Psem_t):longint;cdecl;
273    sem_getvalue :   function (__sem:Psem_t; __sval:Plongint):longint;cdecl;
274
275    pthread_mutexattr_settype : function(__attr: Ppthread_mutexattr_t; Kind:Integer): Integer; cdecl;
276    pthread_setname_np : function(thread: pthread_t; name: PAnsiChar):cint;cdecl;
277
278
279Var
280  PthreadDLL : Pointer;
281
282Function LoadPthreads : Boolean;
283
284begin
285{$ifndef ANDROID}
286  PThreadDLL:=DlOpen('libpthread.so.0',RTLD_LAZY);
287{$else}
288  PThreadDLL := dlopen('libc.so', RTLD_LAZY );
289{$endif}
290  Result:=PThreadDLL<>Nil;
291  If Not Result then
292    exit;
293  Pointer(pthread_create) := dlsym(PthreadDLL,'pthread_create');
294  Pointer(pthread_self) := dlsym(PthreadDLL,'pthread_self');
295  Pointer(pthread_equal) := dlsym(PthreadDLL,'pthread_equal');
296  Pointer(pthread_exit) := dlsym(PthreadDLL,'pthread_exit');
297  Pointer(pthread_join) := dlsym(PthreadDLL,'pthread_join');
298  Pointer(pthread_detach) := dlsym(PthreadDLL,'pthread_detach');
299  Pointer(pthread_attr_init) := dlsym(PthreadDLL,'pthread_attr_init');
300  Pointer(pthread_attr_destroy) := dlsym(PthreadDLL,'pthread_attr_destroy');
301  Pointer(pthread_attr_setdetachstate) := dlsym(PthreadDLL,'pthread_attr_setdetachstate');
302  Pointer(pthread_attr_getdetachstate) := dlsym(PthreadDLL,'pthread_attr_getdetachstate');
303  Pointer(pthread_attr_setschedparam) := dlsym(PthreadDLL,'pthread_attr_setschedparam');
304  Pointer(pthread_attr_getschedparam) := dlsym(PthreadDLL,'pthread_attr_getschedparam');
305  Pointer(pthread_attr_setschedpolicy) := dlsym(PthreadDLL,'pthread_attr_setschedpolicy');
306  Pointer(pthread_attr_getschedpolicy) := dlsym(PthreadDLL,'pthread_attr_getschedpolicy');
307{$ifndef ANDROID}
308  Pointer(pthread_attr_setinheritsched) := dlsym(PthreadDLL,'pthread_attr_setinheritsched');
309  Pointer(pthread_attr_getinheritsched) := dlsym(PthreadDLL,'pthread_attr_getinheritsched');
310{$endif}
311  Pointer(pthread_attr_setscope) := dlsym(PthreadDLL,'pthread_attr_setscope');
312  Pointer(pthread_attr_getscope) := dlsym(PthreadDLL,'pthread_attr_getscope');
313  Pointer(pthread_attr_setstacksize) := dlsym(PthreadDLL,'pthread_attr_setstacksize');
314  Pointer(pthread_setschedparam) := dlsym(PthreadDLL,'pthread_setschedparam');
315  Pointer(pthread_getschedparam) := dlsym(PthreadDLL,'pthread_getschedparam');
316  Pointer(pthread_mutex_init) := dlsym(PthreadDLL,'pthread_mutex_init');
317  Pointer(pthread_mutex_destroy) := dlsym(PthreadDLL,'pthread_mutex_destroy');
318  Pointer(pthread_mutex_trylock) := dlsym(PthreadDLL,'pthread_mutex_trylock');
319  Pointer(pthread_mutex_lock) := dlsym(PthreadDLL,'pthread_mutex_lock');
320  Pointer(pthread_mutex_unlock) := dlsym(PthreadDLL,'pthread_mutex_unlock');
321  Pointer(pthread_mutexattr_init) := dlsym(PthreadDLL,'pthread_mutexattr_init');
322  Pointer(pthread_mutexattr_destroy) := dlsym(PthreadDLL,'pthread_mutexattr_destroy');
323{$ifndef ANDROID}
324  Pointer(pthread_mutexattr_setkind_np) := dlsym(PthreadDLL,'pthread_mutexattr_setkind_np');
325  Pointer(pthread_mutexattr_getkind_np) := dlsym(PthreadDLL,'pthread_mutexattr_getkind_np');
326{$endif}
327  Pointer(pthread_cond_init) := dlsym(PthreadDLL,'pthread_cond_init');
328  Pointer(pthread_cond_destroy) := dlsym(PthreadDLL,'pthread_cond_destroy');
329  Pointer(pthread_cond_signal) := dlsym(PthreadDLL,'pthread_cond_signal');
330  Pointer(pthread_cond_broadcast) := dlsym(PthreadDLL,'pthread_cond_broadcast');
331  Pointer(pthread_cond_wait) := dlsym(PthreadDLL,'pthread_cond_wait');
332  Pointer(pthread_cond_timedwait) := dlsym(PthreadDLL,'pthread_cond_timedwait');
333{$ifndef ANDROID}
334  Pointer(pthread_condattr_init) := dlsym(PthreadDLL,'pthread_condattr_init');
335  Pointer(pthread_condattr_destroy) := dlsym(PthreadDLL,'pthread_condattr_destroy');
336  Pointer(pthread_condattr_setclock) := dlsym(PthreadDLL,'pthread_condattr_setclock');
337{$endif}
338  Pointer(pthread_key_create) := dlsym(PthreadDLL,'pthread_key_create');
339  Pointer(pthread_key_delete) := dlsym(PthreadDLL,'pthread_key_delete');
340  Pointer(pthread_setspecific) := dlsym(PthreadDLL,'pthread_setspecific');
341  Pointer(pthread_getspecific) := dlsym(PthreadDLL,'pthread_getspecific');
342{  Pointer(pthread_once) := dlsym(PthreadDLL,'pthread_once');}
343{$ifndef ANDROID}
344  Pointer(pthread_setcancelstate) := dlsym(PthreadDLL,'pthread_setcancelstate');
345  Pointer(pthread_setcanceltype) := dlsym(PthreadDLL,'pthread_setcanceltype');
346  Pointer(pthread_cancel) := dlsym(PthreadDLL,'pthread_cancel');
347  Pointer(pthread_testcancel) := dlsym(PthreadDLL,'pthread_testcancel');
348{$endif}
349{  Pointer(_pthread_cleanup_push) := dlsym(PthreadDLL,'_pthread_cleanup_push');}
350{  Pointer(_pthread_cleanup_push_defer) := dlsym(PthreadDLL,'_pthread_cleanup_push_defer');}
351{  Pointer(pthread_sigmask) := dlsym(PthreadDLL,'pthread_sigmask');}
352  Pointer(pthread_kill)  := dlsym(PthreadDLL,'pthread_kill');
353{$ifndef ANDROID}
354  Pointer(pthread_atfork):= dlsym(PthreadDLL,'pthread_atfork');
355  Pointer(pthread_kill_other_threads_np) := dlsym(PthreadDLL,'pthread_kill_other_threads_np');
356{$endif}
357  Pointer(pthread_sigmask) := dlsym(PthreadDLL,'pthread_sigmask');
358  Pointer(sem_init     ) := dlsym(PthreadDLL,'sem_init');
359  Pointer(sem_destroy  ) := dlsym(PthreadDLL,'sem_destroy');
360  Pointer(sem_close    ) := dlsym(PthreadDLL,'sem_close');
361  Pointer(sem_unlink   ) := dlsym(PthreadDLL,'sem_unlink');
362  Pointer(sem_wait     ) := dlsym(PthreadDLL,'sem_wait');
363  Pointer(sem_timedwait) := dlsym(PthreadDLL,'sem_timedwait');
364  Pointer(sem_trywait  ) := dlsym(PthreadDLL,'sem_trywait');
365  Pointer(sem_post     ) := dlsym(PthreadDLL,'sem_post');
366  Pointer(sem_getvalue ) := dlsym(PthreadDLL,'sem_getvalue');
367  Pointer(pthread_mutexattr_settype) := dlsym(PthreadDLL,'pthread_mutexattr_settype');
368  Pointer(pthread_setname_np) := dlsym(PthreadDLL,'pthread_setname_np');
369end;
370
371Function UnLoadPthreads : Boolean;
372
373begin
374  Result:=dlclose(PThreadDLL)=0;
375end;
376
377{$endif}
378
379