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>
27 #include <linux/types.h>
29 #endif /* __KERNEL__ */
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 }
76 typedef struct pse51_thread
*pthread_t
;
78 typedef struct pse51_threadattr
{
87 struct sched_param_ex schedparam_ex
;
90 xnarch_cpumask_t affinity
;
94 /* pthread_mutexattr_t and pthread_condattr_t fit on 32 bits, for compatibility
97 typedef struct pse51_key
*pthread_key_t
;
99 typedef struct pse51_once
{
105 /* The following definitions are copied from linuxthread pthreadtypes.h. */
106 struct _pthread_fastlock
114 struct _pthread_fastlock __c_lock
;
116 char __padding
[48 - sizeof (struct _pthread_fastlock
)
117 - sizeof (long) - sizeof (long long)];
127 struct _pthread_fastlock __m_lock
;
130 #endif /* __KERNEL__ */
132 #else /* !(__KERNEL__ || __XENO_SIM__) */
134 #pragma GCC system_header
137 #include_next <pthread.h>
138 #include <nucleus/thread.h>
139 #include <nucleus/intr.h>
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
{
169 unsigned protocol
: 2;
173 struct pse51_condattr
{
182 pthread_cond_t native_cond
;
183 struct __shadow_cond
{
185 struct pse51_cond
*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
;
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
,
209 int pthread_attr_setdetachstate(pthread_attr_t
*attr
,
212 int pthread_attr_getstackaddr(const pthread_attr_t
*attr
,
215 int pthread_attr_setstackaddr(pthread_attr_t
*attr
,
218 int pthread_attr_getstacksize(const pthread_attr_t
*attr
,
221 int pthread_attr_setstacksize(pthread_attr_t
*attr
,
224 int pthread_attr_getinheritsched(const pthread_attr_t
*attr
,
227 int pthread_attr_setinheritsched(pthread_attr_t
*attr
,
230 int pthread_attr_getschedpolicy(const pthread_attr_t
*attr
,
233 int pthread_attr_setschedpolicy(pthread_attr_t
*attr
,
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
,
251 int pthread_attr_setscope(pthread_attr_t
*attr
,
254 int pthread_attr_getname_np(const pthread_attr_t
*attr
,
257 int pthread_attr_setname_np(pthread_attr_t
*attr
,
260 int pthread_attr_getfp_np(const pthread_attr_t
*attr
,
263 int pthread_attr_setfp_np(pthread_attr_t
*attr
,
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
,
282 void pthread_exit(void *value_ptr
);
284 int pthread_join(pthread_t thread
,
287 pthread_t
pthread_self(void);
289 int pthread_getschedparam(pthread_t tid
,
291 struct sched_param
*par
);
293 int pthread_getschedparam_ex(pthread_t tid
,
295 struct sched_param_ex
*par
);
297 int pthread_setschedparam(pthread_t tid
,
299 const struct sched_param
*par
);
301 int pthread_setschedparam_ex(pthread_t tid
,
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
,
312 int pthread_mutexattr_settype(pthread_mutexattr_t
*attr
,
315 int pthread_mutexattr_getprotocol(const pthread_mutexattr_t
*attr
,
318 int pthread_mutexattr_setprotocol(pthread_mutexattr_t
*attr
,
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
,
346 int pthread_condattr_setclock(pthread_condattr_t
*attr
,
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 *),
374 void pthread_cleanup_pop(int execute
);
376 int pthread_setcancelstate(int state
,
379 int pthread_setcanceltype(int type
,
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
,
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
,
406 int pthread_set_name_np(pthread_t thread
,
409 int pthread_intr_attach_np(pthread_intr_t
*intr
,
414 int pthread_intr_detach_np(pthread_intr_t intr
);
416 int pthread_intr_control_np(pthread_intr_t intr
,
423 #else /* !(__KERNEL__ || __XENO_SIM__) */
425 struct sched_param_ex
;
431 #ifndef CONFIG_XENO_HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL
432 int pthread_mutexattr_getprotocol(const pthread_mutexattr_t
*attr
,
435 int pthread_mutexattr_setprotocol(pthread_mutexattr_t
*attr
,
439 #ifndef CONFIG_XENO_HAVE_PTHREAD_CONDATTR_SETCLOCK
440 int pthread_condattr_getclock(const pthread_condattr_t
*attr
,
443 int pthread_condattr_setclock(pthread_condattr_t
*attr
,
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
,
456 int pthread_set_name_np(pthread_t thread
,
459 int pthread_intr_attach_np(pthread_intr_t
*intr
,
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
,
471 int pthread_getschedparam_ex(pthread_t tid
,
473 struct sched_param_ex
*par
);
475 int pthread_setschedparam_ex(pthread_t tid
,
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 *),
484 int __real_pthread_detach(pthread_t thread
);
486 int __real_pthread_getschedparam(pthread_t thread
,
488 struct sched_param
*param
);
490 int __real_pthread_setschedparam(pthread_t thread
,
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
,
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
,
508 int __real_pthread_mutexattr_setprotocol(pthread_mutexattr_t
*attr
,
512 int __real_pthread_mutexattr_getpshared(const pthread_mutexattr_t
*attr
,
515 int __real_pthread_mutexattr_setpshared(pthread_mutexattr_t
*attr
,
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
,
539 int __real_pthread_condattr_setclock(pthread_condattr_t
*attr
,
542 int __real_pthread_condattr_getpshared(const pthread_condattr_t
*attr
,
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
);
569 #endif /* __KERNEL__ || __XENO_SIM__ */
571 #endif /* _XENO_POSIX_PTHREAD_H */