diff options
Diffstat (limited to 'libc/sysdeps/linux/common')
-rw-r--r-- | libc/sysdeps/linux/common/bits/uClibc_mutex.h | 56 | ||||
-rw-r--r-- | libc/sysdeps/linux/common/bits/uClibc_stdio.h | 73 | ||||
-rw-r--r-- | libc/sysdeps/linux/common/pause.c | 30 |
3 files changed, 76 insertions, 83 deletions
diff --git a/libc/sysdeps/linux/common/bits/uClibc_mutex.h b/libc/sysdeps/linux/common/bits/uClibc_mutex.h index e31767787..14aeb9c80 100644 --- a/libc/sysdeps/linux/common/bits/uClibc_mutex.h +++ b/libc/sysdeps/linux/common/bits/uClibc_mutex.h @@ -12,7 +12,8 @@ #ifdef __UCLIBC_HAS_THREADS__ -#include <bits/pthreadtypes.h> +#include <pthread.h> +#include <bits/uClibc_pthread.h> #define __UCLIBC_MUTEX_TYPE pthread_mutex_t @@ -61,53 +62,6 @@ #define __UCLIBC_MUTEX_UNLOCK(M) \ __UCLIBC_MUTEX_CONDITIONAL_UNLOCK(M, 1) -#ifdef __USE_STDIO_FUTEXES__ - -#include <bits/stdio-lock.h> - -#define __UCLIBC_IO_MUTEX(M) _IO_lock_t M -#define __UCLIBC_IO_MUTEX_LOCK(M) _IO_lock_lock(M) -#define __UCLIBC_IO_MUTEX_UNLOCK(M) _IO_lock_unlock(M) -#define __UCLIBC_IO_MUTEX_TRYLOCK(M) _IO_lock_trylock(M) -#define __UCLIBC_IO_MUTEX_INIT(M,I) _IO_lock_t M = I -#define __UCLIBC_IO_MUTEX_EXTERN(M) extern _IO_lock_t M - -#define __UCLIBC_IO_MUTEX_CONDITIONAL_LOCK(M,C) \ - if (C) { \ - _IO_lock_lock(M); \ - } - -#define __UCLIBC_IO_MUTEX_CONDITIONAL_UNLOCK(M,C) \ - if (C) { \ - _IO_lock_unlock(M); \ - } - -#define __UCLIBC_IO_MUTEX_AUTO_LOCK(M,A,V) \ - __UCLIBC_IO_MUTEX_CONDITIONAL_LOCK(M,((A=(V))) == 0) - -#define __UCLIBC_IO_MUTEX_AUTO_UNLOCK(M,A) \ - __UCLIBC_IO_MUTEX_CONDITIONAL_UNLOCK(M,((A) ==0)) - -#define __UCLIBC_IO_MUTEX_LOCK_CANCEL_UNSAFE(M) \ - __UCLIBC_IO_MUTEX_LOCK(M) -#define __UCLIBC_IO_MUTEX_UNLOCK_CANCEL_UNSAFE(M) \ - __UCLIBC_IO_MUTEX_UNLOCK(M) -#define __UCLIBC_IO_MUTEX_TRYLOCK_CANCEL_UNSAFE(M) \ - __UCLIBC_IO_MUTEX_TRYLOCK(M) - -#else -#define __UCLIBC_IO_MUTEX(M) __UCLIBC_MUTEX(M) -#define __UCLIBC_IO_MUTEX_LOCK(M) __UCLIBC_MUTEX_CONDITIONAL_LOCK(M, 1) -#define __UCLIBC_IO_MUTEX_UNLOCK(M) __UCLIBC_MUTEX_CONDITIONAL_UNLOCK(M, 1) -#define __UCLIBC_IO_MUTEX_TRYLOCK(M) __UCLIBC_MUTEX_TRYLOCK_CANCEL_UNSAFE -#define __UCLIBC_IO_MUTEX_INIT(M,I) __UCLIBC_MUTEX_INIT(M,I) -#define __UCLIBC_IO_MUTEX_EXTERN(M) __UCLIBC_MUTEX_EXTERN(M) - -#define __UCLIBC_IO_MUTEX_AUTO_LOCK(M,A,V) __UCLIBC_MUTEX_AUTO_LOCK(M,A,V) -#define __UCLIBC_IO_MUTEX_AUTO_UNLOCK(M,A) __UCLIBC_MUTEX_AUTO_UNLOCK(M,A) - -#endif - #else #define __UCLIBC_MUTEX(M) void *__UCLIBC_MUTEX_DUMMY_ ## M @@ -129,12 +83,6 @@ #define __UCLIBC_MUTEX_LOCK(M) ((void)0) #define __UCLIBC_MUTEX_UNLOCK(M) ((void)0) -#define __UCLIBC_IO_MUTEX_LOCK(M) ((void)0) -#define __UCLIBC_IO_MUTEX_UNLOCK(M) ((void)0) -#define __UCLIBC_IO_MUTEX_TRYLOCK(M) ((void)0) -#define __UCLIBC_IO_MUTEX_INIT(M,I) extern void *__UCLIBC_MUTEX_DUMMY_ ## M -#define __UCLIBC_IO_MUTEX_EXTERN(M) extern void *__UCLIBC_MUTEX_DUMMY_ ## M #endif - #endif /* _UCLIBC_MUTEX_H */ diff --git a/libc/sysdeps/linux/common/bits/uClibc_stdio.h b/libc/sysdeps/linux/common/bits/uClibc_stdio.h index 0af2d5db5..101944acb 100644 --- a/libc/sysdeps/linux/common/bits/uClibc_stdio.h +++ b/libc/sysdeps/linux/common/bits/uClibc_stdio.h @@ -117,6 +117,9 @@ /**********************************************************************/ #include <bits/uClibc_mutex.h> +#ifdef __USE_STDIO_FUTEXES__ +#include <bits/stdio-lock.h> +#endif /* user_locking * 0 : do auto locking/unlocking @@ -132,28 +135,64 @@ #define __STDIO_AUTO_THREADLOCK_VAR \ __UCLIBC_MUTEX_AUTO_LOCK_VAR(__infunc_user_locking) +#ifdef __USE_STDIO_FUTEXES__ + +#define __STDIO_SET_USER_LOCKING(__stream) ((__stream)->__user_locking = 1) + +#define __STDIO_AUTO_THREADLOCK(__stream) \ + if ((__infunc_user_locking = (__stream)->__user_locking) == 0) { \ + _IO_lock_lock((__stream)->_lock); \ + } + +#define __STDIO_AUTO_THREADUNLOCK(__stream) \ + if (__infunc_user_locking == 0) { \ + _IO_lock_unlock((__stream)->_lock); \ + } + +#define __STDIO_ALWAYS_THREADLOCK(__stream) \ + _IO_lock_lock((__stream)->_lock) + +#define __STDIO_ALWAYS_THREADTRYLOCK(__stream) \ + _IO_lock_trylock((__stream)->_lock) + +#define __STDIO_ALWAYS_THREADUNLOCK(__stream) \ + _IO_lock_unlock((__stream)->_lock) + +#define __STDIO_ALWAYS_THREADLOCK_CANCEL_UNSAFE(__stream) \ + _IO_lock_lock_cancel_unsafe((__stream)->__lock) + +#define __STDIO_ALWAYS_THREADTRYLOCK_CANCEL_UNSAFE(__stream) \ + _IO_lock_trylock_cancel_unsafe((__stream)->__lock) + +#define __STDIO_ALWAYS_THREADUNLOCK_CANCEL_UNSAFE(__stream) \ + _IO_lock_unlock_cancel_unsafe((__stream)->__lock) + +#else /* __USE_STDIO_FUTEXES__ */ + #define __STDIO_AUTO_THREADLOCK(__stream) \ - __UCLIBC_IO_MUTEX_AUTO_LOCK((__stream)->__lock, __infunc_user_locking, \ + __UCLIBC_MUTEX_AUTO_LOCK((__stream)->__lock, __infunc_user_locking, \ (__stream)->__user_locking) #define __STDIO_AUTO_THREADUNLOCK(__stream) \ - __UCLIBC_IO_MUTEX_AUTO_UNLOCK((__stream)->__lock, __infunc_user_locking) + __UCLIBC_MUTEX_AUTO_UNLOCK((__stream)->__lock, __infunc_user_locking) #define __STDIO_ALWAYS_THREADLOCK(__stream) \ - __UCLIBC_IO_MUTEX_LOCK((__stream)->__lock) + __UCLIBC_MUTEX_LOCK((__stream)->__lock) #define __STDIO_ALWAYS_THREADUNLOCK(__stream) \ - __UCLIBC_IO_MUTEX_UNLOCK((__stream)->__lock) + __UCLIBC_MUTEX_UNLOCK((__stream)->__lock) #define __STDIO_ALWAYS_THREADLOCK_CANCEL_UNSAFE(__stream) \ - __UCLIBC_IO_MUTEX_LOCK_CANCEL_UNSAFE((__stream)->__lock) + __UCLIBC_MUTEX_LOCK_CANCEL_UNSAFE((__stream)->__lock) #define __STDIO_ALWAYS_THREADTRYLOCK_CANCEL_UNSAFE(__stream) \ - __UCLIBC_IO_MUTEX_TRYLOCK_CANCEL_UNSAFE((__stream)->__lock) + __UCLIBC_MUTEX_TRYLOCK_CANCEL_UNSAFE((__stream)->__lock) #define __STDIO_ALWAYS_THREADUNLOCK_CANCEL_UNSAFE(__stream) \ - __UCLIBC_IO_MUTEX_UNLOCK_CANCEL_UNSAFE((__stream)->__lock) + __UCLIBC_MUTEX_UNLOCK_CANCEL_UNSAFE((__stream)->__lock) + +#endif #ifdef __UCLIBC_HAS_THREADS__ #define __STDIO_SET_USER_LOCKING(__stream) ((__stream)->__user_locking = 1) @@ -161,13 +200,11 @@ #define __STDIO_SET_USER_LOCKING(__stream) ((void)0) #endif -#ifdef __UCLIBC_HAS_THREADS__ #ifdef __USE_STDIO_FUTEXES__ #define STDIO_INIT_MUTEX(M) _IO_lock_init(M) #else #define STDIO_INIT_MUTEX(M) __stdio_init_mutex(& M) #endif -#endif /**********************************************************************/ @@ -283,7 +320,11 @@ struct __STDIO_FILE_STRUCT { #endif #ifdef __UCLIBC_HAS_THREADS__ int __user_locking; - __UCLIBC_IO_MUTEX(__lock); +#ifdef __USE_STDIO_FUTEXES__ + _IO_lock_t _lock; +#else + __UCLIBC_MUTEX(__lock); +#endif #endif /* Everything after this is unimplemented... and may be trashed. */ #if __STDIO_BUILTIN_BUF_SIZE > 0 @@ -359,9 +400,17 @@ extern void _stdio_term(void) attribute_hidden; extern struct __STDIO_FILE_STRUCT *_stdio_openlist; #ifdef __UCLIBC_HAS_THREADS__ -__UCLIBC_IO_MUTEX_EXTERN(_stdio_openlist_add_lock); +#ifdef __USE_STDIO_FUTEXES__ +extern _IO_lock_t _stdio_openlist_add_lock; +#else +__UCLIBC_MUTEX_EXTERN(_stdio_openlist_add_lock); +#endif #ifdef __STDIO_BUFFERS -__UCLIBC_IO_MUTEX_EXTERN(_stdio_openlist_del_lock); +#ifdef __USE_STDIO_FUTEXES__ +extern _IO_lock_t _stdio_openlist_del_lock; +#else +__UCLIBC_MUTEX_EXTERN(_stdio_openlist_del_lock); +#endif extern volatile int _stdio_openlist_use_count; /* _stdio_openlist_del_lock */ extern int _stdio_openlist_del_count; /* _stdio_openlist_del_lock */ #endif diff --git a/libc/sysdeps/linux/common/pause.c b/libc/sysdeps/linux/common/pause.c index 31d3563fb..22a039b4f 100644 --- a/libc/sysdeps/linux/common/pause.c +++ b/libc/sysdeps/linux/common/pause.c @@ -10,23 +10,19 @@ #define __UCLIBC_HIDE_DEPRECATED__ #include <sys/syscall.h> #include <unistd.h> -#include <sysdep-cancel.h> -/* Suspend the process until a signal arrives. - This always returns -1 and sets errno to EINTR. */ -int -__libc_pause (void) -{ - sigset_t set; - - __sigemptyset (&set); - sigprocmask (SIG_BLOCK, NULL, &set); - - /* pause is a cancellation point, but so is sigsuspend. - So no need for anything special here. */ +extern __typeof(pause) __libc_pause; +#ifdef __NR_pause +#define __NR___libc_pause __NR_pause +_syscall0(int, __libc_pause); +#else +#include <signal.h> +libc_hidden_proto(__sigpause) +libc_hidden_proto(sigblock) - return sigsuspend (&set); +int __libc_pause(void) +{ + return (__sigpause(sigblock(0), 0)); } -weak_alias (__libc_pause, pause) - -LIBC_CANCEL_HANDLED (); /* sigsuspend handles our cancellation. */ +#endif +weak_alias(__libc_pause,pause) |