]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/libpthread/src/internals.h
update
[l4.git] / l4 / pkg / uclibc / lib / libpthread / src / internals.h
1 /* Linuxthreads - a simple clone()-based implementation of Posix        */
2 /* threads for Linux.                                                   */
3 /* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr)              */
4 /*                                                                      */
5 /* This program is free software; you can redistribute it and/or        */
6 /* modify it under the terms of the GNU Library General Public License  */
7 /* as published by the Free Software Foundation; either version 2       */
8 /* of the License, or (at your option) any later version.               */
9 /*                                                                      */
10 /* This program is distributed in the hope that it will be useful,      */
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of       */
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        */
13 /* GNU Library General Public License for more details.                 */
14
15 #ifndef _INTERNALS_H
16 #define _INTERNALS_H    1
17
18 #include "uClibc-glue.h"
19
20 /* Internal data structures */
21
22 /* Includes */
23
24 #include <limits.h>
25 //l4/#include <signal.h>
26 #include <stdbool.h>
27 #include <unistd.h>
28 //l4/#include <signal.h>
29 #include <bits/stackinfo.h>
30 //l4/#include <bits/sigcontextinfo.h>
31 #include <bits/pthreadtypes.h>
32
33 #include <bits/libc-lock.h>
34
35 #include <l4/sys/ipc.h>
36
37 #ifdef USE_TLS
38 #include <tls.h>
39 #endif
40 #include "descr.h"
41
42 #include "semaphore.h"
43 #include <pthread-functions.h>
44
45 #ifndef THREAD_GETMEM
46 # define THREAD_GETMEM(descr, member) descr->member
47 #endif
48 #ifndef THREAD_GETMEM_NC
49 # define THREAD_GETMEM_NC(descr, member, idx) descr->member[idx]
50 #endif
51 #ifndef THREAD_SETMEM
52 # define THREAD_SETMEM(descr, member, value) descr->member = (value)
53 #endif
54 #ifndef THREAD_SETMEM_NC
55 # define THREAD_SETMEM_NC(descr, member, idx, value) descr->member[idx] = (value)
56 #endif
57
58 #if !defined NOT_IN_libc
59 # define LIBC_THREAD_GETMEM(descr, member) THREAD_GETMEM (descr, member)
60 # define LIBC_THREAD_SETMEM(descr, member, value) \
61   THREAD_SETMEM (descr, member, value)
62 #else
63 # define LIBC_THREAD_GETMEM(descr, member) descr->member
64 # define LIBC_THREAD_SETMEM(descr, member, value) descr->member = (value)
65 #endif
66
67 typedef void (*destr_function)(void *);
68
69 struct pthread_key_struct {
70   int in_use;                   /* already allocated? */
71   destr_function destr;         /* destruction routine */
72 };
73
74 #include <l4/sys/kdebug.h>
75 #define UNIMPL(x...) do { outstring("UNIMPL: " x "\n"); } while(0)
76
77
78 #define PTHREAD_START_ARGS_INITIALIZER(fct) \
79   { (void *(*) (void *)) fct, NULL }
80
81
82 /* The type of thread handles. */
83 typedef l4_utcb_t *pthread_handle;
84
85
86 /* The type of messages sent to the thread manager thread */
87
88 enum pthread_request_rq {                        /* Request kind */
89     REQ_CREATE, REQ_FREE, REQ_PROCESS_EXIT, REQ_MAIN_THREAD_EXIT,
90     REQ_POST, REQ_DEBUG, REQ_KICK, REQ_FOR_EACH_THREAD,
91     REQ_THREAD_EXIT
92 };
93
94 struct pthread_request {
95   pthread_descr req_thread;     /* Thread doing the request */
96   enum pthread_request_rq req_kind;
97   union {                       /* Arguments for request */
98     struct {                    /* For REQ_CREATE: */
99       const pthread_attr_t * attr; /* thread attributes */
100       void * (*fn)(void *);     /*   start function */
101       void * arg;               /*   argument to start function */
102     } create;
103     struct {                    /* For REQ_FREE: */
104       pthread_t thread_id;      /*   identifier of thread to free */
105     } free;
106     struct {                    /* For REQ_PROCESS_EXIT: */
107       int code;                 /*   exit status */
108     } exit;
109     void * post;                /* For REQ_POST: the semaphore */
110     struct {                    /* For REQ_FOR_EACH_THREAD: callback */
111       void (*fn)(void *, pthread_descr);
112       void *arg;
113     } for_each;
114   } req_args;
115 };
116
117
118 /* First free thread */
119 extern l4_utcb_t *__pthread_first_free_handle attribute_hidden;
120
121 /* Descriptor of the main thread */
122
123 extern pthread_descr __pthread_main_thread;
124
125 /* File descriptor for sending requests to the thread manager.
126    Initially -1, meaning that __pthread_initialize_manager must be called. */
127
128 extern l4_cap_idx_t __pthread_manager_request;
129
130 /* Other end of the pipe for sending requests to the thread manager. */
131
132 /* Maximum stack size.  */
133 extern size_t __pthread_max_stacksize;
134
135 /* Default stack size for new threads.  */
136 extern size_t __pthread_default_stacksize;
137
138 /* Pending request for a process-wide exit */
139
140 extern int __pthread_exit_requested, __pthread_exit_code;
141
142 /* Set to 1 by gdb if we're debugging */
143
144 extern __volatile__ int __pthread_threads_debug;
145
146 /* Globally enabled events.  */
147 //extern __volatile__ td_thr_events_t __pthread_threads_events;
148
149 /* Pointer to descriptor of thread with last event.  */
150 //extern __volatile__ pthread_descr __pthread_last_event;
151
152 /* Flag which tells whether we are executing on SMP kernel. */
153 extern int __pthread_smp_kernel;
154
155 inline static void __pthread_send_manager_rq(struct pthread_request *r, int block)
156 {
157   if (l4_is_invalid_cap(__pthread_manager_request))
158     return;
159   __builtin_memcpy(l4_utcb_mr()->mr, r, sizeof(struct pthread_request));
160   l4_msgtag_t tag
161     = l4_msgtag(0,
162                 (sizeof(struct pthread_request) + sizeof(l4_umword_t) - 1) / sizeof(l4_umword_t),
163                 0, L4_MSGTAG_SCHEDULE);
164   if (block)
165     l4_ipc_call(__pthread_manager_request, l4_utcb(), tag, L4_IPC_NEVER);
166   else
167     l4_ipc_send(__pthread_manager_request, l4_utcb(), tag, L4_IPC_NEVER);
168 }
169
170 /* Return the handle corresponding to a thread id */
171
172 static __inline__ pthread_handle thread_handle(pthread_t id)
173 {
174   return (l4_utcb_t*)id; //&__pthread_handles[id % PTHREAD_THREADS_MAX];
175 }
176
177 static inline pthread_descr handle_to_descr(pthread_handle h)
178 { return (pthread_descr)(l4_utcb_tcr_u(h)->user[0]); }
179
180 static inline struct _pthread_fastlock *handle_to_lock(pthread_handle h)
181 { return (struct _pthread_fastlock *)(&l4_utcb_tcr_u(h)->user[1]); }
182
183 /* Validate a thread handle. Must have acquired h->h_spinlock before. */
184
185 static __inline__ int invalid_handle(pthread_handle h, pthread_t id)
186 {
187   return h != id || handle_to_descr(h) == NULL
188     || handle_to_descr(h)->p_tid != id || handle_to_descr(h)->p_terminated;
189 }
190
191 static __inline__ int nonexisting_handle(pthread_handle h, pthread_t id)
192 {
193   return handle_to_descr(h) == NULL || handle_to_descr(h)->p_tid != id;
194 }
195
196 /* Fill in defaults left unspecified by pt-machine.h.  */
197
198 /* We round up a value with page size. */
199 #ifndef page_roundup
200 #define page_roundup(v,p) ((((size_t) (v)) + (p) - 1) & ~((p) - 1))
201 #endif
202
203 /* The page size we can get from the system.  This should likely not be
204    changed by the machine file but, you never know.  */
205 #ifndef PAGE_SIZE
206 #define PAGE_SIZE  (L4_PAGESIZE)
207 #endif
208
209 /* The initial size of the thread stack.  Must be a multiple of PAGE_SIZE.  */
210 #ifndef INITIAL_STACK_SIZE
211 #define INITIAL_STACK_SIZE  (4 * PAGE_SIZE)
212 #endif
213
214 /* Size of the thread manager stack. The "- 32" avoids wasting space
215    with some malloc() implementations. */
216 #ifndef THREAD_MANAGER_STACK_SIZE
217 #define THREAD_MANAGER_STACK_SIZE  (2 * PAGE_SIZE - 32)
218 #endif
219
220 /* The base of the "array" of thread stacks.  The array will grow down from
221    here.  Defaults to the calculated bottom of the initial application
222    stack.  */
223 #ifndef THREAD_STACK_START_ADDRESS
224 #define THREAD_STACK_START_ADDRESS  __pthread_initial_thread_bos
225 #endif
226
227 /* If MEMORY_BARRIER isn't defined in pt-machine.h, assume the
228    architecture doesn't need a memory barrier instruction (e.g. Intel
229    x86).  Still we need the compiler to respect the barrier and emit
230    all outstanding operations which modify memory.  Some architectures
231    distinguish between full, read and write barriers.  */
232
233 #ifndef MEMORY_BARRIER
234 #define MEMORY_BARRIER() __asm__ ("" : : : "memory")
235 #endif
236 #ifndef READ_MEMORY_BARRIER
237 #define READ_MEMORY_BARRIER() MEMORY_BARRIER()
238 #endif
239 #ifndef WRITE_MEMORY_BARRIER
240 #define WRITE_MEMORY_BARRIER() MEMORY_BARRIER()
241 #endif
242
243 /* Max number of times we must spin on a spinlock calling sched_yield().
244    After MAX_SPIN_COUNT iterations, we put the calling thread to sleep. */
245
246 #ifndef MAX_SPIN_COUNT
247 #define MAX_SPIN_COUNT 50
248 #endif
249
250 /* Max number of times the spinlock in the adaptive mutex implementation
251    spins actively on SMP systems.  */
252
253 #ifndef MAX_ADAPTIVE_SPIN_COUNT
254 #define MAX_ADAPTIVE_SPIN_COUNT 100
255 #endif
256
257 /* Duration of sleep (in nanoseconds) when we can't acquire a spinlock
258    after MAX_SPIN_COUNT iterations of sched_yield().
259    With the 2.0 and 2.1 kernels, this MUST BE > 2ms.
260    (Otherwise the kernel does busy-waiting for realtime threads,
261     giving other threads no chance to run.) */
262
263 #ifndef SPIN_SLEEP_DURATION
264 #define SPIN_SLEEP_DURATION 2000001
265 #endif
266
267 /* Defined and used in libc.so.  */
268 extern int __libc_multiple_threads L4_HIDDEN;
269 extern int __librt_multiple_threads;
270
271 /* Debugging */
272
273 #ifdef DEBUG
274 #include <assert.h>
275 #define ASSERT assert
276 #define MSG __pthread_message
277 #else
278 #define ASSERT(x)
279 #define MSG(msg,arg...)
280 #endif
281
282 # define INIT_THREAD_SELF(descr, nr) do { l4_utcb_tcr()->user[0] = (l4_umword_t)descr; } while (0)
283
284
285
286 /* Internal global functions */
287 __BEGIN_DECLS
288 extern int __pthread_l4_initialize_main_thread(pthread_descr th) attribute_hidden;
289 extern void __l4_add_utcbs(l4_addr_t start, l4_addr_t utcbs_end);
290
291
292 extern int __pthread_sched_idle_prio;
293 extern int __pthread_sched_other_prio;
294 extern int __pthread_sched_rr_prio_min;
295 extern int __pthread_sched_rr_prio_max;
296
297
298 extern void __pthread_do_exit (void *retval, char *currentframe)
299      __attribute__ ((__noreturn__));
300 extern void __pthread_destroy_specifics (void);
301 extern void __pthread_perform_cleanup (char *currentframe);
302 extern void __pthread_init_max_stacksize (void);
303 extern int __pthread_initialize_manager (void);
304 extern void __pthread_message (const char * fmt, ...);
305 extern int __pthread_manager (void *reqfd);
306 extern int __pthread_start_manager (pthread_descr mgr) L4_HIDDEN;
307 extern int __pthread_manager_event (void *reqfd);
308 extern void __pthread_manager_sighandler (int sig);
309 extern void __pthread_reset_main_thread (void);
310 extern void __pthread_once_fork_prepare (void);
311 extern void __pthread_once_fork_parent (void);
312 extern void __pthread_once_fork_child (void);
313 extern void __flockfilelist (void);
314 extern void __funlockfilelist (void);
315 extern void __fresetlockfiles (void);
316 extern void __pthread_manager_adjust_prio (int thread_prio);
317 extern void __pthread_initialize_minimal (void);
318
319 extern int __pthread_attr_setguardsize (pthread_attr_t *__attr,
320                                         size_t __guardsize);
321 extern int __pthread_attr_getguardsize (const pthread_attr_t *__attr,
322                                         size_t *__guardsize);
323 #if 0 /* uClibc: deprecated stuff disabled */
324 extern int __pthread_attr_setstackaddr (pthread_attr_t *__attr,
325                                         void *__stackaddr);
326 extern int __pthread_attr_getstackaddr (const pthread_attr_t *__attr,
327                                         void **__stackaddr);
328 #endif
329 extern int __pthread_attr_setstacksize (pthread_attr_t *__attr,
330                                         size_t __stacksize);
331 extern int __pthread_attr_getstacksize (const pthread_attr_t *__attr,
332                                         size_t *__stacksize);
333 extern int __pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr,
334                                     size_t __stacksize);
335 extern int __pthread_attr_getstack (const pthread_attr_t *__attr, void **__stackaddr,
336                                     size_t *__stacksize);
337 extern int __pthread_attr_destroy (pthread_attr_t *attr);
338 extern int __pthread_attr_setdetachstate (pthread_attr_t *attr,
339                                           int detachstate);
340 extern int __pthread_attr_getdetachstate (const pthread_attr_t *attr,
341                                           int *detachstate);
342 extern int __pthread_attr_setschedparam (pthread_attr_t *attr,
343                                          const struct sched_param *param);
344 extern int __pthread_attr_getschedparam (const pthread_attr_t *attr,
345                                          struct sched_param *param);
346 extern int __pthread_attr_setschedpolicy (pthread_attr_t *attr, int policy);
347 extern int __pthread_attr_getschedpolicy (const pthread_attr_t *attr,
348                                           int *policy);
349 extern int __pthread_attr_setinheritsched (pthread_attr_t *attr, int inherit);
350 extern int __pthread_attr_getinheritsched (const pthread_attr_t *attr,
351                                            int *inherit);
352 extern int __pthread_attr_setscope (pthread_attr_t *attr, int scope);
353 extern int __pthread_attr_getscope (const pthread_attr_t *attr, int *scope);
354
355 extern int __pthread_getconcurrency (void);
356 extern int __pthread_setconcurrency (int __level);
357 extern int __pthread_mutex_timedlock (pthread_mutex_t *__mutex,
358                                       const struct timespec *__abstime);
359 extern int __pthread_mutexattr_getpshared (const pthread_mutexattr_t *__attr,
360                                            int *__pshared);
361 extern int __pthread_mutexattr_setpshared (pthread_mutexattr_t *__attr,
362                                            int __pshared);
363 extern int __pthread_mutexattr_gettype (const pthread_mutexattr_t *__attr,
364                                         int *__kind);
365 extern void __pthread_kill_other_threads_np (void);
366 extern int __pthread_mutex_init (pthread_mutex_t *__mutex,
367                                  __const pthread_mutexattr_t *__mutex_attr);
368 extern int __pthread_mutex_destroy (pthread_mutex_t *__mutex);
369 extern int __pthread_mutex_lock (pthread_mutex_t *__mutex);
370 extern int __pthread_mutex_trylock (pthread_mutex_t *__mutex);
371 extern int __pthread_mutex_unlock (pthread_mutex_t *__mutex);
372
373 extern int __pthread_cond_init (pthread_cond_t *cond,
374                                 const pthread_condattr_t *cond_attr);
375 extern int __pthread_cond_destroy (pthread_cond_t *cond);
376 extern int __pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex);
377 extern int __pthread_cond_timedwait (pthread_cond_t *cond,
378                                      pthread_mutex_t *mutex,
379                                      const struct timespec *abstime);
380 extern int __pthread_cond_signal (pthread_cond_t *cond);
381 extern int __pthread_cond_broadcast (pthread_cond_t *cond);
382 extern int __pthread_condattr_init (pthread_condattr_t *attr);
383 extern int __pthread_condattr_destroy (pthread_condattr_t *attr);
384 extern pthread_t __pthread_self (void);
385 extern pthread_descr __pthread_thread_self (void);
386 extern pthread_descr __pthread_self_stack (void) L4_HIDDEN;
387 extern int __pthread_equal (pthread_t thread1, pthread_t thread2);
388 extern void __pthread_exit (void *retval)
389 #if defined NOT_IN_libc && defined IS_IN_libpthread
390         attribute_noreturn
391 #endif
392         ;
393 extern int __pthread_getschedparam (pthread_t thread, int *policy,
394                                     struct sched_param *param) __THROW;
395 extern int __pthread_setschedparam (pthread_t thread, int policy,
396                                     const struct sched_param *param) __THROW;
397 extern int __pthread_setcancelstate (int state, int * oldstate);
398 extern int __pthread_setcanceltype (int type, int * oldtype);
399
400 extern int __pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict __rwlock,
401                                          __const struct timespec *__restrict
402                                          __abstime);
403 extern int __pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict __rwlock,
404                                          __const struct timespec *__restrict
405                                          __abstime);
406 extern int __pthread_rwlockattr_destroy (pthread_rwlockattr_t *__attr);
407
408 extern int __pthread_barrierattr_getpshared (__const pthread_barrierattr_t *
409                                              __restrict __attr,
410                                              int *__restrict __pshared);
411
412 extern int __pthread_spin_lock (pthread_spinlock_t *__lock);
413 extern int __pthread_spin_trylock (pthread_spinlock_t *__lock);
414 extern int __pthread_spin_unlock (pthread_spinlock_t *__lock);
415 extern int __pthread_spin_init (pthread_spinlock_t *__lock, int __pshared);
416 extern int __pthread_spin_destroy (pthread_spinlock_t *__lock);
417
418 /* Global pointers to old or new suspend functions */
419
420 extern void (*__pthread_restart)(pthread_descr);
421 extern void (*__pthread_suspend)(pthread_descr);
422 extern int (*__pthread_timedsuspend)(pthread_descr, const struct timespec *);
423
424 /* Prototypes for some of the new semaphore functions.  */
425 extern int sem_post (sem_t * sem) __THROW;
426 extern int sem_init (sem_t *__sem, int __pshared, unsigned int __value) __THROW;
427 extern int sem_wait (sem_t *__sem);
428 extern int sem_trywait (sem_t *__sem) __THROW;
429 extern int sem_getvalue (sem_t *__restrict __sem, int *__restrict __sval) __THROW;
430 extern int sem_destroy (sem_t *__sem) __THROW;
431
432 /* Prototypes for compatibility functions.  */
433 extern int __pthread_attr_init (pthread_attr_t *__attr);
434 extern int __pthread_create (pthread_t *__restrict __threadp,
435                                  const pthread_attr_t *__attr,
436                                  void *(*__start_routine) (void *),
437                                  void *__restrict __arg);
438
439 /* The functions called the signal events.  */
440 extern void __linuxthreads_create_event (void);
441 extern void __linuxthreads_death_event (void);
442 extern void __linuxthreads_reap_event (void);
443
444 /* This function is called to initialize the pthread library.  */
445 extern void __pthread_initialize (void);
446
447 /* TSD.  */
448 extern int __pthread_internal_tsd_set (int key, const void * pointer);
449 extern void * __pthread_internal_tsd_get (int key);
450 extern void ** __attribute__ ((__const__))
451   __pthread_internal_tsd_address (int key);
452 #if 0
453 /* Sighandler wrappers.  */
454 extern void __pthread_sighandler(int signo, SIGCONTEXT ctx);
455 extern void __pthread_sighandler_rt(int signo, struct siginfo *si,
456                                     struct ucontext *uc);
457 extern void __pthread_null_sighandler(int sig);
458 extern int __pthread_sigaction (int sig, const struct sigaction *act,
459                                 struct sigaction *oact);
460 extern int __pthread_sigwait (const sigset_t *set, int *sig);
461 extern int __pthread_raise (int sig);
462 #endif
463 /* Cancellation.  */
464 extern int __pthread_enable_asynccancel (void) L4_HIDDEN;
465 extern void __pthread_disable_asynccancel (int oldtype)
466   internal_function L4_HIDDEN;
467
468 /* The two functions are in libc.so and not exported.  */
469 extern int __libc_enable_asynccancel (void) L4_HIDDEN;
470 extern void __libc_disable_asynccancel (int oldtype)
471   internal_function L4_HIDDEN;
472
473 /* The two functions are in libc.so and are exported.  */
474 extern int __librt_enable_asynccancel (void);
475 extern void __librt_disable_asynccancel (int oldtype) internal_function;
476
477 extern void __pthread_cleanup_upto (__jmp_buf target,
478                                     char *targetframe) L4_HIDDEN;
479 #if 0
480 extern pid_t __pthread_fork (struct fork_block *b) L4_HIDDEN;
481 #endif
482
483 #define asm_handle(name) _asm_handle(name)
484 #define _asm_handle(name) #name
485 #define ASM_GLOBAL asm_handle(ASM_GLOBAL_DIRECTIVE)
486 #define ASM_CANCEL(name) asm_handle(C_SYMBOL_NAME(name))
487
488 #if !defined NOT_IN_libc
489 # define LIBC_CANCEL_ASYNC() \
490   __libc_enable_asynccancel ()
491 # define LIBC_CANCEL_RESET(oldtype) \
492   __libc_disable_asynccancel (oldtype)
493 # define LIBC_CANCEL_HANDLED() \
494   __asm__ (ASM_GLOBAL " " ASM_CANCEL(__libc_enable_asynccancel)); \
495   __asm__ (ASM_GLOBAL " " ASM_CANCEL(__libc_disable_asynccancel))
496 #elif defined IS_IN_libpthread
497 # define LIBC_CANCEL_ASYNC() \
498   __pthread_enable_asynccancel ()
499 # define LIBC_CANCEL_RESET(oldtype) \
500   __pthread_disable_asynccancel (oldtype)
501 # define LIBC_CANCEL_HANDLED() \
502   __asm__ (ASM_GLOBAL " " ASM_CANCEL(__pthread_enable_asynccancel)); \
503   __asm__ (ASM_GLOBAL " " ASM_CANCEL(__pthread_disable_asynccancel))
504 #elif defined IS_IN_librt
505 # define LIBC_CANCEL_ASYNC() \
506   __librt_enable_asynccancel ()
507 # define LIBC_CANCEL_RESET(oldtype) \
508   __librt_disable_asynccancel (oldtype)
509 # define LIBC_CANCEL_HANDLED() \
510   __asm__ (ASM_GLOBAL " " ASM_CANCEL(__librt_enable_asynccancel)); \
511   __asm__ (ASM_GLOBAL " " ASM_CANCEL(__librt_disable_asynccancel))
512 #else
513 # define LIBC_CANCEL_ASYNC()    0 /* Just a dummy value.  */
514 # define LIBC_CANCEL_RESET(val) ((void)(val)) /* Nothing, but evaluate it.  */
515 # define LIBC_CANCEL_HANDLED()  /* Nothing.  */
516 #endif
517 extern int * __libc_pthread_init (const struct pthread_functions *functions);
518 __END_DECLS
519
520
521 #ifndef USE_TLS
522 # define __manager_thread (&__pthread_manager_thread)
523 #else
524 # define __manager_thread __pthread_manager_threadp
525 #endif
526
527
528 static inline int __pthread_getprio(int policy, int prio);
529 static inline int __pthread_getprio(int policy, int prio)
530 {
531     switch (policy)
532     {
533     case SCHED_OTHER:
534       prio = 0;
535       break;
536     case SCHED_IDLE:
537       prio = 0;
538       break;
539     case SCHED_RR:
540       prio -= __pthread_sched_rr_prio_min;
541       break;
542     case SCHED_L4:
543       break;
544     default:
545       return -1;
546     }
547
548     return prio;
549 }
550
551 static inline int __pthread_l4_getprio(int policy, int posix_prio);
552 static inline int __pthread_l4_getprio(int policy, int posix_prio)
553 {
554   switch (policy)
555     {
556     case SCHED_OTHER:
557       return __pthread_sched_other_prio;
558     case SCHED_IDLE:
559       return __pthread_sched_idle_prio;
560     case SCHED_RR:
561       return __pthread_sched_rr_prio_min + posix_prio;
562     case SCHED_L4:
563       return posix_prio;
564     default:
565       return -1;
566     }
567 }
568
569
570 static inline pthread_descr
571 check_thread_self (void);
572 static inline pthread_descr
573 check_thread_self (void)
574 {
575   pthread_descr self = thread_self ();
576 #if defined THREAD_SELF && defined INIT_THREAD_SELF
577   if (self == __manager_thread)
578     {
579       /* A new thread might get a cancel signal before it is fully
580          initialized, so that the thread register might still point to the
581          manager thread.  Double check that this is really the manager
582          thread.  */
583       self = handle_to_descr(l4_utcb());
584       if (self != __manager_thread)
585         /* Oops, thread_self() isn't working yet..  */
586         INIT_THREAD_SELF(self, self->p_nr);
587     }
588 #endif
589   return self;
590 }
591
592 #endif /* internals.h */