OSDN Git Service

0be59c511ffc3625dd24a49f6b26573a91f0844d
[uclinux-h8/uClibc.git] / libc / sysdeps / linux / common / nanosleep.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * nanosleep() for uClibc
4  *
5  * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
6  *
7  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
8  */
9
10 #include <sys/syscall.h>
11 #include <time.h>
12
13 #ifdef __UCLIBC_HAS_THREADS_NATIVE__
14 #include <sysdep-cancel.h>
15 #include <pthreadP.h>
16 #else
17 #define SINGLE_THREAD_P 1
18 #endif
19
20 #define __NR___syscall_nanosleep __NR_nanosleep
21 static inline _syscall2(int, __syscall_nanosleep, const struct timespec *, req,
22                                                 struct timespec *, rem);
23
24 extern __typeof(nanosleep) __libc_nanosleep;
25
26 int __libc_nanosleep(const struct timespec *req, struct timespec *rem)
27 {
28         if (SINGLE_THREAD_P)
29                 return __syscall_nanosleep(req, rem);
30
31 #ifdef __UCLIBC_HAS_THREADS_NATIVE__
32         int oldtype = LIBC_CANCEL_ASYNC ();
33         int result = __syscall_nanosleep(req, rem);
34         LIBC_CANCEL_RESET (oldtype);
35         return result;
36 #endif
37 }
38
39 libc_hidden_proto(nanosleep)
40 weak_alias(__libc_nanosleep,nanosleep)
41 libc_hidden_weak(nanosleep)