summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author"Steven J. Hill" <sjhill@realitydiluted.com>2005-08-09 05:50:49 +0000
committer"Steven J. Hill" <sjhill@realitydiluted.com>2005-08-09 05:50:49 +0000
commit75f9a2b1874f3c50727c6b91fd5b5735a2a5deb3 (patch)
tree04a04dac7fd6a10c123dea261b22e7e331d33dd2
parent7eca0902fd7bbdb04ea83f967b0a198335c8d5db (diff)
downloaduClibc-alpine-75f9a2b1874f3c50727c6b91fd5b5735a2a5deb3.tar.bz2
uClibc-alpine-75f9a2b1874f3c50727c6b91fd5b5735a2a5deb3.tar.xz
In reality, the futex support that was originally added was only for STDIO operations internal to libc. The futexes should not be visible to anything other than libc. These changes clean up futex and STDIO.
-rw-r--r--extra/Configs/Config.in19
-rw-r--r--include/netdb.h16
-rw-r--r--libc/stdio/Makefile4
-rw-r--r--libc/stdio/_fopen.c4
-rw-r--r--libc/stdio/_stdio.c12
-rw-r--r--libc/stdio/_stdio.h2
-rw-r--r--libc/stdio/scanf.c6
-rw-r--r--libc/stdio/vdprintf.c2
-rw-r--r--libc/stdio/vsnprintf.c6
-rw-r--r--libc/stdio/vswprintf.c2
-rw-r--r--libc/sysdeps/linux/common/bits/errno.h4
-rw-r--r--libc/sysdeps/linux/common/bits/uClibc_stdio.h8
12 files changed, 48 insertions, 37 deletions
diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in
index cac37b058..605c49baa 100644
--- a/extra/Configs/Config.in
+++ b/extra/Configs/Config.in
@@ -321,7 +321,6 @@ config PTHREADS_NATIVE
bool "Native POSIX Threading (NPTL) Support"
depends on UCLIBC_HAS_THREADS
default n
- select UCLIBC_HAS_FUTEXES
help
If you want to compile uClibc with NPTL support, then answer Y.
@@ -356,16 +355,6 @@ config PTHREADS_DEBUG_SUPPORT
If you are doing development and want to debug applications using
uClibc's pthread library, answer Y. Otherwise, answer N.
-config UCLIBC_HAS_FUTEXES
- bool "Fast user mutexes (futex) Support"
- default n
- depends on PTHREADS_NATIVE
- help
- If you want to compile uClibc to use fast user mutexes, also
- known as futexes, answer Y. Otherwise, answer N.
-
- NOTE: Futexes are only supported with Linux 2.6 kernels.
-
config UCLIBC_HAS_LFS
bool "Large File Support"
default y
@@ -1041,6 +1030,14 @@ config UCLIBC_HAS_GNU_GETOPT
Most people will answer Y.
+config UCLIBC_HAS_STDIO_FUTEXES
+ bool "Use futexes for multithreaded I/O locking"
+ default n
+ depends on PTHREADS_NATIVE
+ help
+ If you want to compile uClibc to use futexes for low-level
+ I/O locking, answer Y. Otherwise, answer N.
+
endmenu
diff --git a/include/netdb.h b/include/netdb.h
index 1bea76efc..94d80f205 100644
--- a/include/netdb.h
+++ b/include/netdb.h
@@ -53,12 +53,11 @@
__BEGIN_DECLS
-#ifdef __PTHREADS_NATIVE__
-#include <tls.h>
-extern __thread int h_errno attribute_tls_model_ie;
-#else
/* Error status for non-reentrant lookup functions. */
+#ifndef __PTHREADS_NATIVE__
extern int h_errno;
+#else
+#define h_errno (*__h_errno_location ())
#endif
/* Function to get address of global `h_errno' variable. */
@@ -459,4 +458,13 @@ extern int getnameinfo (__const struct sockaddr *__restrict __sa,
__END_DECLS
+#ifdef _LIBC
+# ifdef __PTHREADS_NATIVE__
+# include <tls.h>
+# undef h_errno
+# define h_errno h_errno /* For #ifndef h_errno tests. */
+extern __thread int h_errno attribute_tls_model_ie;
+# endif
+#endif
+
#endif /* netdb.h */
diff --git a/libc/stdio/Makefile b/libc/stdio/Makefile
index e17d9faa5..684380ef0 100644
--- a/libc/stdio/Makefile
+++ b/libc/stdio/Makefile
@@ -121,6 +121,10 @@ ifeq ($(strip $(UCLIBC_HAS_LFS)),y)
OBJS += $(CLOBJS)
endif
+ifeq ($(UCLIBC_HAS_STDIO_FUTEXES),y)
+CFLAGS += -D__USE_STDIO_FUTEXES__
+endif
+
OBJ_LIST=../obj.stdio
all: $(OBJ_LIST)
diff --git a/libc/stdio/_fopen.c b/libc/stdio/_fopen.c
index b1722fef2..bba8cfdfd 100644
--- a/libc/stdio/_fopen.c
+++ b/libc/stdio/_fopen.c
@@ -98,7 +98,7 @@ FILE *_stdio_fopen(intptr_t fname_or_mode,
#ifdef __UCLIBC_HAS_THREADS__
/* We only initialize the mutex in the non-freopen case. */
/* stream->__user_locking = _stdio_user_locking; */
-#ifdef __UCLIBC_HAS_FUTEXES__
+#ifdef __USE_STDIO_FUTEXES__
_IO_lock_init (stream->_lock);
#else
__stdio_init_mutex(&stream->__lock);
@@ -194,7 +194,7 @@ FILE *_stdio_fopen(intptr_t fname_or_mode,
#ifdef __UCLIBC_HAS_THREADS__
/* Even in the freopen case, we reset the user locking flag. */
stream->__user_locking = _stdio_user_locking;
-#ifdef __UCLIBC_HAS_FUTEXES__
+#ifdef __USE_STDIO_FUTEXES__
/* _IO_lock_init (stream->_lock); */
#else
/* __stdio_init_mutex(&stream->__lock); */
diff --git a/libc/stdio/_stdio.c b/libc/stdio/_stdio.c
index 671f1e14c..b21beb728 100644
--- a/libc/stdio/_stdio.c
+++ b/libc/stdio/_stdio.c
@@ -73,7 +73,7 @@
#endif
#ifdef __UCLIBC_HAS_THREADS__
-#ifdef __UCLIBC_HAS_FUTEXES__
+#ifdef __USE_STDIO_FUTEXES__
#define __STDIO_FILE_INIT_THREADSAFE \
2, _LIBC_LOCK_RECURSIVE_INITIALIZER,
#else
@@ -156,8 +156,8 @@ FILE *__stdout = _stdio_streams + 1; /* For putchar() macro. */
FILE *_stdio_openlist = _stdio_streams;
# ifdef __UCLIBC_HAS_THREADS__
-# ifdef __UCLIBC_HAS_FUTEXES__
-# include <bits/stdio-lock.h>
+# ifdef __USE_STDIO_FUTEXES__
+# include <bits/stdio-lock.h>
_IO_lock_t _stdio_openlist_lock = _IO_lock_initializer;
# else
pthread_mutex_t _stdio_openlist_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
@@ -172,7 +172,7 @@ int _stdio_openlist_delflag = 0;
/* 2 if threading not initialized and 0 otherwise; */
int _stdio_user_locking = 2;
-#ifndef __UCLIBC_HAS_FUTEXES__
+#ifndef __USE_STDIO_FUTEXES__
void __stdio_init_mutex(pthread_mutex_t *m)
{
static const pthread_mutex_t __stdio_mutex_initializer
@@ -196,7 +196,7 @@ void _stdio_term(void)
* locked, then I suppose there is a chance that a pointer in the
* chain might be corrupt due to a partial store.
*/
-#ifdef __UCLIBC_HAS_FUTEXES__
+#ifdef __USE_STDIO_FUTEXES__
_IO_lock_init (_stdio_openlist_lock);
#else
__stdio_init_mutex(&_stdio_openlist_lock);
@@ -221,7 +221,7 @@ void _stdio_term(void)
}
ptr->__user_locking = 1; /* Set locking mode to "by caller". */
-#ifdef __UCLIBC_HAS_FUTEXES__
+#ifdef __USE_STDIO_FUTEXES__
_IO_lock_init (ptr->_lock);
#else
__stdio_init_mutex(&ptr->__lock); /* Shouldn't be necessary, but... */
diff --git a/libc/stdio/_stdio.h b/libc/stdio/_stdio.h
index 2b956daa3..c167b177e 100644
--- a/libc/stdio/_stdio.h
+++ b/libc/stdio/_stdio.h
@@ -25,7 +25,7 @@
#ifdef __UCLIBC_HAS_THREADS__
#include <pthread.h>
-#ifdef __UCLIBC_HAS_FUTEXES__
+#ifdef __USE_STDIO_FUTEXES___
#define __STDIO_THREADLOCK_OPENLIST \
_IO_lock_lock(_stdio_openlist_lock)
diff --git a/libc/stdio/scanf.c b/libc/stdio/scanf.c
index 13254a50b..feaec3b44 100644
--- a/libc/stdio/scanf.c
+++ b/libc/stdio/scanf.c
@@ -235,7 +235,7 @@ int vsscanf(__const char *sp, __const char *fmt, va_list ap)
#ifdef __UCLIBC_HAS_THREADS__
f.__user_locking = 1; /* Set user locking. */
-#ifdef __UCLIBC_HAS_FUTEXES__
+#ifdef __USE_STDIO_FUTEXES__
_IO_lock_init (f._lock);
#else
__stdio_init_mutex(&f.__lock);
@@ -286,7 +286,7 @@ int vsscanf(__const char *sp, __const char *fmt, va_list ap)
#ifdef __UCLIBC_HAS_THREADS__
f.f.__user_locking = 1; /* Set user locking. */
-#ifdef __UCLIBC_HAS_FUTEXES__
+#ifdef __USE_STDIO_FUTEXES__
_IO_lock_init (f.f._lock);
#else
__stdio_init_mutex(&f.f.__lock);
@@ -421,7 +421,7 @@ int vswscanf(const wchar_t * __restrict str, const wchar_t * __restrict format,
#ifdef __UCLIBC_HAS_THREADS__
f.__user_locking = 1; /* Set user locking. */
-#ifdef __UCLIBC_HAS_FUTEXES__
+#ifdef __USE_STDIO_FUTEXES__
_IO_lock_init (f._lock);
#else
__stdio_init_mutex(&f.__lock);
diff --git a/libc/stdio/vdprintf.c b/libc/stdio/vdprintf.c
index 6449d37ca..6d8c91e90 100644
--- a/libc/stdio/vdprintf.c
+++ b/libc/stdio/vdprintf.c
@@ -43,7 +43,7 @@ int vdprintf(int filedes, const char * __restrict format, va_list arg)
#ifdef __UCLIBC_HAS_THREADS__
f.__user_locking = 1; /* Set user locking. */
-#ifdef __UCLIBC_HAS_FUTEXES__
+#ifdef __USE_STDIO_FUTEXES__
_IO_lock_init (f._lock);
#else
__stdio_init_mutex(&f.__lock);
diff --git a/libc/stdio/vsnprintf.c b/libc/stdio/vsnprintf.c
index 2f4f8e0a4..b8bdbaaa1 100644
--- a/libc/stdio/vsnprintf.c
+++ b/libc/stdio/vsnprintf.c
@@ -41,7 +41,7 @@ int vsnprintf(char *__restrict buf, size_t size,
#ifdef __UCLIBC_HAS_THREADS__
f.__user_locking = 1; /* Set user locking. */
-#ifdef __UCLIBC_HAS_FUTEXES__
+#ifdef __USE_STDIO_FUTEXES__
_IO_lock_init (f._lock);
#else
__stdio_init_mutex(&f.__lock);
@@ -113,7 +113,7 @@ int vsnprintf(char *__restrict buf, size_t size,
#ifdef __UCLIBC_HAS_THREADS__
f.f.__user_locking = 1; /* Set user locking. */
-#ifdef __UCLIBC_HAS_FUTEXES__
+#ifdef __USE_STDIO_FUTEXES__
_IO_lock_init (f.f._lock);
#else
__stdio_init_mutex(&f.f.__lock);
@@ -201,7 +201,7 @@ int vsnprintf(char *__restrict buf, size_t size,
#ifdef __UCLIBC_HAS_THREADS__
f.__user_locking = 1; /* Set user locking. */
-#ifdef __UCLIBC_HAS_FUTEXES__
+#ifdef __USE_STDIO_FUTEXES__
_IO_lock_init (f._lock);
#else
__stdio_init_mutex(&f.__lock);
diff --git a/libc/stdio/vswprintf.c b/libc/stdio/vswprintf.c
index ea99836e2..aab847dfd 100644
--- a/libc/stdio/vswprintf.c
+++ b/libc/stdio/vswprintf.c
@@ -38,7 +38,7 @@ int vswprintf(wchar_t *__restrict buf, size_t size,
#ifdef __UCLIBC_HAS_THREADS__
f.__user_locking = 1; /* Set user locking. */
-#ifdef __UCLIBC_HAS_FUTEXES__
+#ifdef __USE_STDIO_FUTEXES__
_IO_lock_init (f._lock);
#else
__stdio_init_mutex(&f.__lock);
diff --git a/libc/sysdeps/linux/common/bits/errno.h b/libc/sysdeps/linux/common/bits/errno.h
index cb9c2ee43..bf73a8fe1 100644
--- a/libc/sysdeps/linux/common/bits/errno.h
+++ b/libc/sysdeps/linux/common/bits/errno.h
@@ -39,7 +39,9 @@ extern int *__errno_location (void) __THROW __attribute__ ((__const__));
# if defined _LIBC
/* We wouldn't need a special macro anymore but it is history. */
-# define __set_errno(val) ((errno) = (val))
+# ifndef __set_errno
+# define __set_errno(val) ((errno) = (val))
+# endif
# endif /* _LIBC */
# if defined __UCLIBC_HAS_THREADS__
diff --git a/libc/sysdeps/linux/common/bits/uClibc_stdio.h b/libc/sysdeps/linux/common/bits/uClibc_stdio.h
index e378489a4..18ec2beca 100644
--- a/libc/sysdeps/linux/common/bits/uClibc_stdio.h
+++ b/libc/sysdeps/linux/common/bits/uClibc_stdio.h
@@ -119,7 +119,7 @@
#ifdef __UCLIBC_HAS_THREADS__
/* Need this for pthread_mutex_t. */
#include <bits/pthreadtypes.h>
-#if defined __UCLIBC_HAS_FUTEXES__ && defined _LIBC
+#ifdef __USE_STDIO_FUTEXES__
#include <bits/stdio-lock.h>
#endif
@@ -137,7 +137,7 @@
#define __STDIO_AUTO_THREADLOCK_VAR int __infunc_user_locking
-#if defined __UCLIBC_HAS_FUTEXES__ && defined _LIBC
+#ifdef __USE_STDIO_FUTEXES__
#define __STDIO_SET_USER_LOCKING(__stream) ((__stream)->__user_locking = 1)
@@ -313,7 +313,7 @@ struct __STDIO_FILE_STRUCT {
#endif
#ifdef __UCLIBC_HAS_THREADS__
int __user_locking;
-#if defined __UCLIBC_HAS_FUTEXES__ && defined _LIBC
+#ifdef __USE_STDIO_FUTEXES__
_IO_lock_t _lock;
#else
pthread_mutex_t __lock;
@@ -392,7 +392,7 @@ extern void _stdio_term(void);
extern struct __STDIO_FILE_STRUCT *_stdio_openlist;
#ifdef __UCLIBC_HAS_THREADS__
-#if defined __UCLIBC_HAS_FUTEXES__ && defined _LIBC
+#ifdef __USE_STDIO_FUTEXES__
extern _IO_lock_t _stdio_openlist_lock;
#else
extern pthread_mutex_t _stdio_openlist_lock;