bfin: remove inline keyword
[xenomai-head.git] / include / posix / pthread.h
blobcbba26c9b8a2726419cfc1e1c7e7867ad29a02d2
1 /*
2 * Copyright (C) 2005 Philippe Gerum <rpm@xenomai.org>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #ifndef _XENO_POSIX_PTHREAD_H
20 #define _XENO_POSIX_PTHREAD_H
22 #if defined(__KERNEL__) || defined(__XENO_SIM__)
24 #include <nucleus/xenomai.h>
26 #ifdef __KERNEL__
27 #include <linux/types.h>
28 #include <sched.h>
29 #endif /* __KERNEL__ */
31 #ifdef __XENO_SIM__
32 #include <posix_overrides.h>
33 #define PTHREAD_STACK_MIN 8192
34 #else /* __XENO_SIM__ */
35 #define PTHREAD_STACK_MIN 1024
36 #endif /* __XENO_SIM__ */
38 #define PTHREAD_CREATE_JOINABLE 0
39 #define PTHREAD_CREATE_DETACHED 1
41 #define PTHREAD_INHERIT_SCHED 0
42 #define PTHREAD_EXPLICIT_SCHED 1
44 #define PTHREAD_SCOPE_SYSTEM 0
45 #define PTHREAD_SCOPE_PROCESS 1
47 #define PTHREAD_MUTEX_NORMAL 0
48 #define PTHREAD_MUTEX_RECURSIVE 1
49 #define PTHREAD_MUTEX_ERRORCHECK 2
50 #define PTHREAD_MUTEX_DEFAULT 0
52 #define PTHREAD_PRIO_NONE 0
53 #define PTHREAD_PRIO_INHERIT 1
54 #define PTHREAD_PRIO_PROTECT 2
56 #define PTHREAD_PROCESS_PRIVATE 0
57 #define PTHREAD_PROCESS_SHARED 1
59 #define PTHREAD_CANCEL_ENABLE 0
60 #define PTHREAD_CANCEL_DISABLE 1
62 #define PTHREAD_CANCEL_DEFERRED 2
63 #define PTHREAD_CANCEL_ASYNCHRONOUS 3
65 #define PTHREAD_CANCELED ((void *)-2)
67 #define PTHREAD_DESTRUCTOR_ITERATIONS 4
68 #define PTHREAD_KEYS_MAX 128
70 #define PTHREAD_ONCE_INIT { 0x86860808, 0 }
72 struct timespec;
74 struct pse51_thread;
76 typedef struct pse51_thread *pthread_t;
78 typedef struct pse51_threadattr {
80 unsigned magic;
81 int detachstate;
82 size_t stacksize;
83 int inheritsched;
84 int policy;
86 /* Non portable */
87 struct sched_param_ex schedparam_ex;
88 char *name;
89 int fp;
90 xnarch_cpumask_t affinity;
92 } pthread_attr_t;
94 /* pthread_mutexattr_t and pthread_condattr_t fit on 32 bits, for compatibility
95 with libc. */
96 struct pse51_key;
97 typedef struct pse51_key *pthread_key_t;
99 typedef struct pse51_once {
100 unsigned magic;
101 int init_step;
102 } pthread_once_t;
104 #ifdef __KERNEL__
105 /* The following definitions are copied from linuxthread pthreadtypes.h. */
106 struct _pthread_fastlock
108 long int __status;
109 int __spinlock;
112 typedef struct
114 struct _pthread_fastlock __c_lock;
115 long __c_waiting;
116 char __padding[48 - sizeof (struct _pthread_fastlock)
117 - sizeof (long) - sizeof (long long)];
118 long long __align;
119 } pthread_cond_t;
121 typedef struct
123 int __m_reserved;
124 int __m_count;
125 long __m_owner;
126 int __m_kind;
127 struct _pthread_fastlock __m_lock;
128 } pthread_mutex_t;
130 #endif /* __KERNEL__ */
132 #else /* !(__KERNEL__ || __XENO_SIM__) */
134 #pragma GCC system_header
136 #include <sched.h>
137 #include_next <pthread.h>
138 #include <nucleus/thread.h>
139 #include <nucleus/intr.h>
141 struct timespec;
143 #endif /* __KERNEL__ || __XENO_SIM__ */
145 #ifndef PTHREAD_PRIO_NONE
146 #define PTHREAD_PRIO_NONE 0
147 #endif /* !PTHREAD_PRIO_NONE */
148 #ifndef PTHREAD_PRIO_INHERIT
149 #define PTHREAD_PRIO_INHERIT 1
150 #endif /* !PTHREAD_PRIO_INHERIT */
151 #ifndef PTHREAD_PRIO_PROTECT
152 #define PTHREAD_PRIO_PROTECT 2
153 #endif /* !PTHREAD_PRIO_PROTECT */
155 #define PTHREAD_WARNSW XNTRAPSW
156 #define PTHREAD_LOCK_SCHED XNLOCK
157 #define PTHREAD_RPIOFF XNRPIOFF
158 #define PTHREAD_PRIMARY XNTHREAD_STATE_SPARE1
160 #define PTHREAD_INOAUTOENA XN_ISR_NOENABLE
161 #define PTHREAD_IPROPAGATE XN_ISR_PROPAGATE
163 #define PTHREAD_IENABLE 0
164 #define PTHREAD_IDISABLE 1
166 struct pse51_mutexattr {
167 unsigned magic: 24;
168 unsigned type: 2;
169 unsigned protocol: 2;
170 unsigned pshared: 1;
173 struct pse51_condattr {
174 unsigned magic: 24;
175 unsigned clock: 2;
176 unsigned pshared: 1;
179 struct pse51_cond;
181 union __xeno_cond {
182 pthread_cond_t native_cond;
183 struct __shadow_cond {
184 unsigned magic;
185 struct pse51_cond *cond;
186 } shadow_cond;
189 struct pse51_interrupt;
191 typedef struct pse51_interrupt *pthread_intr_t;
193 #if defined(__KERNEL__) || defined(__XENO_SIM__)
194 typedef struct pse51_mutexattr pthread_mutexattr_t;
196 typedef struct pse51_condattr pthread_condattr_t;
198 #ifdef __cplusplus
199 extern "C" {
200 #endif
202 int pthread_attr_init(pthread_attr_t *attr);
204 int pthread_attr_destroy(pthread_attr_t *attr);
206 int pthread_attr_getdetachstate(const pthread_attr_t *attr,
207 int *detachstate);
209 int pthread_attr_setdetachstate(pthread_attr_t *attr,
210 int detachstate);
212 int pthread_attr_getstackaddr(const pthread_attr_t *attr,
213 void **stackaddr);
215 int pthread_attr_setstackaddr(pthread_attr_t *attr,
216 void *stackaddr);
218 int pthread_attr_getstacksize(const pthread_attr_t *attr,
219 size_t *stacksize);
221 int pthread_attr_setstacksize(pthread_attr_t *attr,
222 size_t stacksize);
224 int pthread_attr_getinheritsched(const pthread_attr_t *attr,
225 int *inheritsched);
227 int pthread_attr_setinheritsched(pthread_attr_t *attr,
228 int inheritsched);
230 int pthread_attr_getschedpolicy(const pthread_attr_t *attr,
231 int *policy);
233 int pthread_attr_setschedpolicy(pthread_attr_t *attr,
234 int policy);
236 int pthread_attr_getschedparam(const pthread_attr_t *attr,
237 struct sched_param *par);
239 int pthread_attr_getschedparam_ex(const pthread_attr_t *attr,
240 struct sched_param_ex *par);
242 int pthread_attr_setschedparam(pthread_attr_t *attr,
243 const struct sched_param *par);
245 int pthread_attr_setschedparam_ex(pthread_attr_t *attr,
246 const struct sched_param_ex *par);
248 int pthread_attr_getscope(const pthread_attr_t *attr,
249 int *scope);
251 int pthread_attr_setscope(pthread_attr_t *attr,
252 int scope);
254 int pthread_attr_getname_np(const pthread_attr_t *attr,
255 const char **name);
257 int pthread_attr_setname_np(pthread_attr_t *attr,
258 const char *name);
260 int pthread_attr_getfp_np(const pthread_attr_t *attr,
261 int *use_fp);
263 int pthread_attr_setfp_np(pthread_attr_t *attr,
264 int use_fp);
266 int pthread_attr_getaffinity_np (const pthread_attr_t *attr,
267 xnarch_cpumask_t *mask);
269 int pthread_attr_setaffinity_np (pthread_attr_t *attr,
270 xnarch_cpumask_t mask);
272 int pthread_create(pthread_t *tid,
273 const pthread_attr_t *attr,
274 void *(*start) (void *),
275 void *arg ) __deprecated_in_kernel__;
277 int pthread_detach(pthread_t thread);
279 int pthread_equal(pthread_t t1,
280 pthread_t t2);
282 void pthread_exit(void *value_ptr);
284 int pthread_join(pthread_t thread,
285 void **value_ptr);
287 pthread_t pthread_self(void);
289 int pthread_getschedparam(pthread_t tid,
290 int *pol,
291 struct sched_param *par);
293 int pthread_getschedparam_ex(pthread_t tid,
294 int *pol,
295 struct sched_param_ex *par);
297 int pthread_setschedparam(pthread_t tid,
298 int pol,
299 const struct sched_param *par);
301 int pthread_setschedparam_ex(pthread_t tid,
302 int pol,
303 const struct sched_param_ex *par);
305 int pthread_mutexattr_init(pthread_mutexattr_t *attr);
307 int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
309 int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr,
310 int *type);
312 int pthread_mutexattr_settype(pthread_mutexattr_t *attr,
313 int type);
315 int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr,
316 int *proto);
318 int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr,
319 int proto);
321 int pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr, int *pshared);
323 int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared);
325 int pthread_mutex_init(pthread_mutex_t *mutex,
326 const pthread_mutexattr_t *attr);
328 int pthread_mutex_destroy(pthread_mutex_t *mutex);
330 int pthread_mutex_trylock(pthread_mutex_t *mutex);
332 int pthread_mutex_lock(pthread_mutex_t *mutex);
334 int pthread_mutex_timedlock(pthread_mutex_t *mutex,
335 const struct timespec *to);
337 int pthread_mutex_unlock(pthread_mutex_t *mutex);
339 int pthread_condattr_init(pthread_condattr_t *attr);
341 int pthread_condattr_destroy(pthread_condattr_t *attr);
343 int pthread_condattr_getclock(const pthread_condattr_t *attr,
344 clockid_t *clk_id);
346 int pthread_condattr_setclock(pthread_condattr_t *attr,
347 clockid_t clk_id);
349 int pthread_condattr_getpshared(const pthread_condattr_t *attr, int *pshared);
351 int pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared);
353 int pthread_cond_init(pthread_cond_t *cond,
354 const pthread_condattr_t *attr);
356 int pthread_cond_destroy(pthread_cond_t *cond);
358 int pthread_cond_wait(pthread_cond_t *cond,
359 pthread_mutex_t *mutex);
361 int pthread_cond_timedwait(pthread_cond_t *cond,
362 pthread_mutex_t *mutex,
363 const struct timespec *abstime);
365 int pthread_cond_signal(pthread_cond_t *cond);
367 int pthread_cond_broadcast(pthread_cond_t *cond);
369 int pthread_cancel(pthread_t thread);
371 void pthread_cleanup_push(void (*routine)(void *),
372 void *arg);
374 void pthread_cleanup_pop(int execute);
376 int pthread_setcancelstate(int state,
377 int *oldstate);
379 int pthread_setcanceltype(int type,
380 int *oldtype);
382 void pthread_testcancel(void);
384 int pthread_key_create(pthread_key_t *key,
385 void (*destructor)(void *));
387 int pthread_key_delete(pthread_key_t key);
389 void *pthread_getspecific(pthread_key_t key);
391 int pthread_setspecific(pthread_key_t key,
392 const void *value);
394 int pthread_once(pthread_once_t *once_control,
395 void (*init_routine)(void));
397 int pthread_make_periodic_np(pthread_t thread,
398 struct timespec *starttp,
399 struct timespec *periodtp);
401 int pthread_wait_np(unsigned long *overruns_r);
403 int pthread_set_mode_np(int clrmask,
404 int setmask);
406 int pthread_set_name_np(pthread_t thread,
407 const char *name);
409 int pthread_intr_attach_np(pthread_intr_t *intr,
410 unsigned irq,
411 xnisr_t isr,
412 xniack_t iack);
414 int pthread_intr_detach_np(pthread_intr_t intr);
416 int pthread_intr_control_np(pthread_intr_t intr,
417 int cmd);
419 #ifdef __cplusplus
421 #endif
423 #else /* !(__KERNEL__ || __XENO_SIM__) */
425 struct sched_param_ex;
427 #ifdef __cplusplus
428 extern "C" {
429 #endif
431 #ifndef CONFIG_XENO_HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL
432 int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr,
433 int *proto);
435 int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr,
436 int proto);
437 #endif
439 #ifndef CONFIG_XENO_HAVE_PTHREAD_CONDATTR_SETCLOCK
440 int pthread_condattr_getclock(const pthread_condattr_t *attr,
441 clockid_t *clk_id);
443 int pthread_condattr_setclock(pthread_condattr_t *attr,
444 clockid_t clk_id);
445 #endif
447 int pthread_make_periodic_np(pthread_t thread,
448 struct timespec *starttp,
449 struct timespec *periodtp);
451 int pthread_wait_np(unsigned long *overruns_r);
453 int pthread_set_mode_np(int clrmask,
454 int setmask);
456 int pthread_set_name_np(pthread_t thread,
457 const char *name);
459 int pthread_intr_attach_np(pthread_intr_t *intr,
460 unsigned irq,
461 int mode);
463 int pthread_intr_detach_np(pthread_intr_t intr);
465 int pthread_intr_wait_np(pthread_intr_t intr,
466 const struct timespec *to);
468 int pthread_intr_control_np(pthread_intr_t intr,
469 int cmd);
471 int pthread_getschedparam_ex(pthread_t tid,
472 int *pol,
473 struct sched_param_ex *par);
475 int pthread_setschedparam_ex(pthread_t tid,
476 int pol,
477 const struct sched_param_ex *par);
479 int __real_pthread_create(pthread_t *tid,
480 const pthread_attr_t *attr,
481 void *(*start) (void *),
482 void *arg);
484 int __real_pthread_detach(pthread_t thread);
486 int __real_pthread_getschedparam(pthread_t thread,
487 int *policy,
488 struct sched_param *param);
490 int __real_pthread_setschedparam(pthread_t thread,
491 int policy,
492 const struct sched_param *param);
493 int __real_pthread_yield(void);
495 int __real_pthread_mutexattr_init(pthread_mutexattr_t *attr);
497 int __real_pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
499 int __real_pthread_mutexattr_gettype(const pthread_mutexattr_t *attr,
500 int *type);
502 int __real_pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);
504 #ifdef CONFIG_XENO_HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL
505 int __real_pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr,
506 int *proto);
508 int __real_pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr,
509 int proto);
510 #endif
512 int __real_pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr,
513 int *pshared);
515 int __real_pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
516 int pshared);
518 int __real_pthread_mutex_init(pthread_mutex_t *mutex,
519 const pthread_mutexattr_t *attr);
521 int __real_pthread_mutex_destroy(pthread_mutex_t *mutex);
523 int __real_pthread_mutex_lock(pthread_mutex_t *mutex);
525 int __real_pthread_mutex_timedlock(pthread_mutex_t *mutex,
526 const struct timespec *to);
528 int __real_pthread_mutex_trylock(pthread_mutex_t *mutex);
530 int __real_pthread_mutex_unlock(pthread_mutex_t *mutex);
532 int __real_pthread_condattr_init(pthread_condattr_t *attr);
534 int __real_pthread_condattr_destroy(pthread_condattr_t *attr);
536 int __real_pthread_condattr_getclock(const pthread_condattr_t *attr,
537 clockid_t *clk_id);
539 int __real_pthread_condattr_setclock(pthread_condattr_t *attr,
540 clockid_t clk_id);
542 int __real_pthread_condattr_getpshared(const pthread_condattr_t *attr,
543 int *pshared);
545 int __real_pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared);
547 int __real_pthread_cond_init (pthread_cond_t *cond,
548 const pthread_condattr_t *attr);
550 int __real_pthread_cond_destroy(pthread_cond_t *cond);
552 int __real_pthread_cond_wait(pthread_cond_t *cond,
553 pthread_mutex_t *mutex);
555 int __real_pthread_cond_timedwait(pthread_cond_t *cond,
556 pthread_mutex_t *mutex,
557 const struct timespec *abstime);
559 int __real_pthread_cond_signal(pthread_cond_t *cond);
561 int __real_pthread_cond_broadcast(pthread_cond_t *cond);
563 int __real_pthread_kill(pthread_t tid, int sig);
565 #ifdef __cplusplus
567 #endif
569 #endif /* __KERNEL__ || __XENO_SIM__ */
571 #endif /* _XENO_POSIX_PTHREAD_H */