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 //#include <signal.h>
16 //#include <kernel-features.h>
17 #include <l4/sys/thread.h>
18 #include <stdlib.h>
19 
20 #include <l4/sys/types.h>
21 #include <l4/sys/semaphore.h>
22 
23 /* Primitives for controlling thread execution */
24 
restart(pthread_descr th)25 static __inline__ void restart(pthread_descr th)
26 {
27   l4_semaphore_up(th->p_thsem_cap);
28 }
29 
suspend(pthread_descr self)30 static __inline__ void suspend(pthread_descr self)
31 {
32   l4_semaphore_down(self->p_thsem_cap, L4_IPC_NEVER);
33 }
34 
timedsuspend(pthread_descr self,const struct timespec * abstime)35 static __inline__ int timedsuspend(pthread_descr self,
36 		const struct timespec *abstime)
37 {
38   extern uint64_t __attribute__((weak)) __libc_l4_kclock_offset;
39   uint64_t clock = abstime->tv_sec * 1000000ULL + abstime->tv_nsec / 1000;
40   if (&__libc_l4_kclock_offset)
41     clock -= __libc_l4_kclock_offset;
42   l4_timeout_t timeout = L4_IPC_NEVER;
43   l4_rcv_timeout(l4_timeout_abs_u(clock, 4, l4_utcb()), &timeout);
44   l4_msgtag_t res = l4_semaphore_down(self->p_thsem_cap, timeout);
45   if (l4_error(res) == -(L4_EIPC_LO + L4_IPC_RETIMEOUT))
46     return 0;
47   return 1;
48 }
49