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