about summary refs log tree commit diff
path: root/nptl
diff options
context:
space:
mode:
Diffstat (limited to 'nptl')
-rw-r--r--nptl/ChangeLog19
-rw-r--r--nptl/Makefile5
-rw-r--r--nptl/flockfile.c3
-rw-r--r--nptl/funlockfile.c3
-rw-r--r--nptl/sysdeps/pthread/bits/libc-lock.h137
-rw-r--r--nptl/sysdeps/unix/sysv/linux/Makefile4
-rw-r--r--nptl/sysdeps/unix/sysv/linux/fork.c4
7 files changed, 147 insertions, 28 deletions
diff --git a/nptl/ChangeLog b/nptl/ChangeLog
index 9d40cca747..b8a193ea09 100644
--- a/nptl/ChangeLog
+++ b/nptl/ChangeLog
@@ -1,3 +1,22 @@
+2002-12-06  Ulrich Drepper  <drepper@redhat.com>
+
+	* Makefile (tests): Comment out tst-locale2 for now.
+	(CFLAGS-flockfile.c, CFLAGS-funlockfile.c): Define to -D_IO_MTSAFE_IO.
+
+	* sysdeps/unix/sysv/linux/Makefile: Define CFLAGS-fork.c to
+	-D_IO_MTSAFE_IO.
+	* sysdeps/unix/sysv/linux/fork.c: Include <bits/stdio-lock.h>.
+	Use _IO_lock_init instead of explicit assignment.
+
+	* sysdeps/pthread/bits/libc-lock.h: Define __rtld_lock_* macros.
+	Define __libc_lock_* and __libc_lock_recursive macros with
+	lowlevellock macros, not pthread mutexes.
+
+	* flockfile.c: Include <bits/stdio-lock.h>.  Use _IO_lock_lock instead
+	of pthread_mutex_lock.
+	* funlockfile.c: Include <bits/stdio-lock.h>.  Use _IO_lock_unlock
+	instead of pthread_mutex_unlock.
+
 2002-12-06  Roland McGrath  <roland@redhat.com>
 
 	* allocatestack.c (__stack_user): Use uninitialized defn.
diff --git a/nptl/Makefile b/nptl/Makefile
index a856b2df9d..7683ab87db 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -134,7 +134,7 @@ tests = tst-mutex1 tst-mutex2 tst-mutex3 tst-mutex4 tst-mutex5 tst-mutex6 \
 	tst-stack1 \
 	tst-unload \
 	tst-sysconf \
-	tst-locale1 tst-locale2
+	tst-locale1 #tst-locale2  <--- commented out until compiler is fixed
 
 LDFLAGS-pthread.so = -Wl,--enable-new-dtags,-z,nodelete,-z,initfirst
 
@@ -155,6 +155,9 @@ omit-deps += crti
 CFLAGS-pt-initfini.s = -g0 -fPIC -fno-inline-functions
 endif
 
+CFLAGS-flockfile.c = -D_IO_MTSAFE_IO
+CFLAGS-funlockfile.c = -D_IO_MTSAFE_IO
+
 ifeq ($(build-static),yes)
 tests-static += tst-locale1 tst-locale2
 endif
diff --git a/nptl/flockfile.c b/nptl/flockfile.c
index a82059f2f1..db6776813c 100644
--- a/nptl/flockfile.c
+++ b/nptl/flockfile.c
@@ -20,12 +20,13 @@
 #include <pthread.h>
 #include <stdio.h>
 #include <libio.h>
+#include <bits/stdio-lock.h>
 
 
 void
 flockfile (stream)
      FILE *stream;
 {
-  pthread_mutex_lock (stream->_lock);
+  _IO_lock_lock (*stream->_lock);
 }
 strong_alias (flockfile, _IO_flockfile)
diff --git a/nptl/funlockfile.c b/nptl/funlockfile.c
index cbb3ec690c..f0314b2fc6 100644
--- a/nptl/funlockfile.c
+++ b/nptl/funlockfile.c
@@ -20,12 +20,13 @@
 #include <pthread.h>
 #include <stdio.h>
 #include <libio.h>
+#include <bits/stdio-lock.h>
 
 
 void
 funlockfile (stream)
      FILE *stream;
 {
-  pthread_mutex_unlock (stream->_lock);
+  _IO_lock_unlock (*stream->_lock);
 }
 strong_alias (funlockfile, _IO_funlockfile)
diff --git a/nptl/sysdeps/pthread/bits/libc-lock.h b/nptl/sysdeps/pthread/bits/libc-lock.h
index 9536d0c909..30e3410cbc 100644
--- a/nptl/sysdeps/pthread/bits/libc-lock.h
+++ b/nptl/sysdeps/pthread/bits/libc-lock.h
@@ -33,16 +33,19 @@
    ld.so might be used on old kernels with a different libc.so.  */
 #ifdef _LIBC
 # include <lowlevellock.h>
+# include <tls.h>
 #endif
 
 /* Mutex type.  */
 #if defined _LIBC || defined _IO_MTSAFE_IO
-# if defined NOT_IN_libc || !defined _LIBC
+# if (defined NOT_IN_libc && !defined IS_IN_libpthread) || !defined _LIBC
 typedef pthread_mutex_t __libc_lock_t;
+typedef struct { pthread_mutex_t mutex; } __libc_lock_recursive_t;
 # else
 typedef int __libc_lock_t;
+typedef struct { int lock; int cnt; void *owner; } __libc_lock_recursive_t;
 # endif
-typedef struct { pthread_mutex_t mutex; } __libc_lock_recursive_t;
+typedef struct { pthread_mutex_t mutex; } __rtld_lock_recursive_t;
 # ifdef __USE_UNIX98
 typedef pthread_rwlock_t __libc_rwlock_t;
 # else
@@ -70,6 +73,8 @@ typedef pthread_key_t __libc_key_t;
   CLASS __libc_rwlock_t NAME;
 #define __libc_lock_define_recursive(CLASS,NAME) \
   CLASS __libc_lock_recursive_t NAME;
+#define __rtld_lock_define_recursive(CLASS,NAME) \
+  CLASS __rtld_lock_recursive_t NAME;
 
 /* Define an initialized lock variable NAME with storage class CLASS.
 
@@ -80,7 +85,7 @@ typedef pthread_key_t __libc_key_t;
    initialized locks must be set to one due to the lack of normal
    atomic operations.) */
 
-#if defined _LIBC && !defined NOT_IN_libc
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
 # if LLL_LOCK_INITIALIZER == 0
 #  define __libc_lock_define_initialized(CLASS,NAME) \
   CLASS __libc_lock_t NAME;
@@ -103,11 +108,27 @@ typedef pthread_key_t __libc_key_t;
 
 /* Define an initialized recursive lock variable NAME with storage
    class CLASS.  */
-#define __libc_lock_define_initialized_recursive(CLASS,NAME) \
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
+# if LLL_LOCK_INITIALIZER == 0
+#  define __libc_lock_define_initialized_recursive(CLASS,NAME) \
+  CLASS __libc_lock_recursive_t NAME;
+# else
+#  define __libc_lock_define_initialized_recursive(CLASS,NAME) \
+  CLASS __libc_lock_recursive_t NAME = _LIBC_LOCK_RECURSIVE_INITIALIZER;
+# endif
+# define _LIBC_LOCK_RECURSIVE_INITIALIZER \
+  { LLL_LOCK_INITIALIZER, 0, NULL }
+#else
+# define __libc_lock_define_initialized_recursive(CLASS,NAME) \
   CLASS __libc_lock_recursive_t NAME = _LIBC_LOCK_RECURSIVE_INITIALIZER;
-#define _LIBC_LOCK_RECURSIVE_INITIALIZER \
+# define _LIBC_LOCK_RECURSIVE_INITIALIZER \
   {PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP}
+#endif
 
+#define __rtld_lock_define_initialized_recursive(CLASS,NAME) \
+  CLASS __rtld_lock_recursive_t NAME = _RTLD_LOCK_RECURSIVE_INITIALIZER;
+#define _RTLD_LOCK_RECURSIVE_INITIALIZER \
+  {PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP}
 
 /* If we check for a weakly referenced symbol and then perform a
    normal jump to it te code generated for some platforms in case of
@@ -126,7 +147,7 @@ typedef pthread_key_t __libc_key_t;
 
 /* Initialize the named lock variable, leaving it in a consistent, unlocked
    state.  */
-#if defined _LIBC && !defined NOT_IN_libc
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
 # define __libc_lock_init(NAME) (NAME) = LLL_LOCK_INITIALIZER;
 #else
 # define __libc_lock_init(NAME) \
@@ -136,23 +157,40 @@ typedef pthread_key_t __libc_key_t;
   __libc_maybe_call (__pthread_rwlock_init, (&(NAME), NULL), 0)
 
 /* Same as last but this time we initialize a recursive mutex.  */
-#define __libc_lock_init_recursive(NAME) \
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
+# define __libc_lock_init_recursive(NAME) \
+    (NAME) = (__libc_lock_recursive_t) _LIBC_LOCK_RECURSIVE_INITIALIZER
+#else
+# define __libc_lock_init_recursive(NAME) \
+  do {									      \
+    if (__pthread_mutex_init != NULL)					      \
+      {									      \
+	pthread_mutexattr_t __attr;					      \
+	__pthread_mutexattr_init (&__attr);				      \
+	__pthread_mutexattr_settype (&__attr, PTHREAD_MUTEX_RECURSIVE_NP);    \
+	__pthread_mutex_init (&(NAME).mutex, &__attr);			      \
+	__pthread_mutexattr_destroy (&__attr);				      \
+      }									      \
+  } while (0)
+#endif
+
+#define __rtld_lock_init_recursive(NAME) \
   do {									      \
     if (__pthread_mutex_init != NULL)					      \
       {									      \
 	pthread_mutexattr_t __attr;					      \
 	__pthread_mutexattr_init (&__attr);				      \
-	__pthread_mutexattr_settype (&__attr, PTHREAD_MUTEX_RECURSIVE_NP); \
+	__pthread_mutexattr_settype (&__attr, PTHREAD_MUTEX_RECURSIVE_NP);    \
 	__pthread_mutex_init (&(NAME).mutex, &__attr);			      \
 	__pthread_mutexattr_destroy (&__attr);				      \
       }									      \
-  } while (0);
+  } while (0)
 
 /* Finalize the named lock variable, which must be locked.  It cannot be
    used again until __libc_lock_init is called again on it.  This must be
    called on a lock variable before the containing storage is reused.  */
-#if defined _LIBC && !defined NOT_IN_libc
-# define __libc_lock_fini(NAME) (0)
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
+# define __libc_lock_fini(NAME) ((void) 0)
 #else
 # define __libc_lock_fini(NAME) \
   __libc_maybe_call (__pthread_mutex_destroy, (&(NAME)), 0)
@@ -161,11 +199,15 @@ typedef pthread_key_t __libc_key_t;
   __libc_maybe_call (__pthread_rwlock_destroy, (&(NAME)), 0)
 
 /* Finalize recursive named lock.  */
-#define __libc_lock_fini_recursive(NAME) \
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
+# define __libc_lock_fini_recursive(NAME) ((void) 0)
+#else
+# define __libc_lock_fini_recursive(NAME) \
   __libc_maybe_call (__pthread_mutex_destroy, (&(NAME)), 0)
+#endif
 
 /* Lock the named lock variable.  */
-#if defined _LIBC && !defined NOT_IN_libc
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
 # define __libc_lock_lock(NAME) \
   lll_lock (NAME);
 #else
@@ -178,11 +220,27 @@ typedef pthread_key_t __libc_key_t;
   __libc_maybe_call (__pthread_rwlock_wrlock, (&(NAME)), 0)
 
 /* Lock the recursive named lock variable.  */
-#define __libc_lock_lock_recursive(NAME) \
-  __libc_maybe_call (__pthread_mutex_lock, (&(NAME)), 0)
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
+# define __libc_lock_lock_recursive(NAME) \
+  do {									      \
+    void *self = THREAD_SELF;						      \
+    if ((NAME).owner != self)						      \
+      {									      \
+	lll_lock ((NAME).lock);						      \
+	(NAME).owner = self;						      \
+      }									      \
+    ++(NAME).cnt;							      \
+  } while (0)
+#else
+# define __libc_lock_lock_recursive(NAME) \
+  __libc_maybe_call (__pthread_mutex_lock, (&(NAME).mutex), 0)
+#endif
+
+#define __rtld_lock_lock_recursive(NAME) \
+  __libc_maybe_call (__pthread_mutex_lock, (&(NAME).mutex), 0)
 
 /* Try to lock the named lock variable.  */
-#if defined _LIBC && !defined NOT_IN_libc
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
 # define __libc_lock_trylock(NAME) \
   lll_trylock (NAME)
 #else
@@ -195,11 +253,34 @@ typedef pthread_key_t __libc_key_t;
   __libc_maybe_call (__pthread_rwlock_trywrlock, (&(NAME)), 0)
 
 /* Try to lock the recursive named lock variable.  */
-#define __libc_lock_trylock_recursive(NAME) \
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
+# define __libc_lock_trylock_recursive(NAME)				      \
+  do {									      \
+    int result = 0;							      \
+    void *self = THREAD_SELF;						      \
+    if ((NAME).owner != self)						      \
+      {									      \
+	if (lll_trylock ((NAME).lock) == 0)				      \
+	  {								      \
+	    (NAME).owner = self;					      \
+	    (NAME).cnt = 1;						      \
+	  }								      \
+	else								      \
+	  result = EBUSY;						      \
+      }									      \
+    else								      \
+      ++(NAME).cnt;							      \
+  } while (0)
+#else
+# define __libc_lock_trylock_recursive(NAME) \
   __libc_maybe_call (__pthread_mutex_trylock, (&(NAME)), 0)
+#endif
+
+#define __rtld_lock_trylock_recursive(NAME) \
+  __libc_maybe_call (__pthread_mutex_trylock, (&(NAME).mutex), 0)
 
 /* Unlock the named lock variable.  */
-#if defined _LIBC && !defined NOT_IN_libc
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
 # define __libc_lock_unlock(NAME) \
   lll_unlock (NAME);
 #else
@@ -210,9 +291,23 @@ typedef pthread_key_t __libc_key_t;
   __libc_maybe_call (__pthread_rwlock_unlock, (&(NAME)), 0)
 
 /* Unlock the recursive named lock variable.  */
-#define __libc_lock_unlock_recursive(NAME) \
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
+/* We do no error checking here.  */
+# define __libc_lock_unlock_recursive(NAME) \
+  do {									      \
+    if (--(NAME).cnt == 0)						      \
+      {									      \
+	(NAME).owner = NULL;						      \
+	lll_unlock ((NAME).lock);					      \
+      }									      \
+  } while (0)
+#else
+# define __libc_lock_unlock_recursive(NAME) \
   __libc_maybe_call (__pthread_mutex_unlock, (&(NAME)), 0)
+#endif
 
+#define __rtld_lock_unlock_recursive(NAME) \
+  __libc_maybe_call (__pthread_mutex_unlock, (&(NAME).mutex), 0)
 
 /* Define once control variable.  */
 #if PTHREAD_ONCE_INIT == 0
@@ -394,8 +489,4 @@ weak_extern (BP_SYM (_pthread_cleanup_pop_restore))
 # endif
 #endif
 
-/* We need portable names for some functions.  E.g., when they are
-   used as argument to __libc_cleanup_region_start.  */
-#define __libc_mutex_unlock __pthread_mutex_unlock
-
 #endif	/* bits/libc-lock.h */
diff --git a/nptl/sysdeps/unix/sysv/linux/Makefile b/nptl/sysdeps/unix/sysv/linux/Makefile
index 832ce2326b..9a84534d5b 100644
--- a/nptl/sysdeps/unix/sysv/linux/Makefile
+++ b/nptl/sysdeps/unix/sysv/linux/Makefile
@@ -22,3 +22,7 @@ sysdep_routines += register-atfork unregister-atfork fork-gen
 
 libpthread-sysdep_routines += pt-fork
 endif
+
+ifeq ($(subdir),posix)
+CFLAGS-fork.c = -D_IO_MTSAFE_IO
+endif
diff --git a/nptl/sysdeps/unix/sysv/linux/fork.c b/nptl/sysdeps/unix/sysv/linux/fork.c
index c1aa23c5c5..b643f89dfc 100644
--- a/nptl/sysdeps/unix/sysv/linux/fork.c
+++ b/nptl/sysdeps/unix/sysv/linux/fork.c
@@ -24,6 +24,7 @@
 #include <libio/libioP.h>
 #include <tls.h>
 #include "fork.h"
+#include <bits/stdio-lock.h>
 
 
 unsigned long int *__fork_generation_pointer;
@@ -41,8 +42,7 @@ fresetlockfiles (void)
   _IO_ITER i;
 
   for (i = _IO_iter_begin(); i != _IO_iter_end(); i = _IO_iter_next(i))
-    *((pthread_mutex_t *) _IO_iter_file(i)->_lock)
-      = (pthread_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+    _IO_lock_init (*((_IO_lock_t *) _IO_iter_file(i)->_lock));
 }