[PATCH] sync MIPS NPTL with latest NPTL changes

Lior Balkohen balkohen@gmail.com
Wed Feb 22 21:39:00 GMT 2006


My simply copy&paste lll_robust_mutex_dead might be bogus, since I
have no clue how to implement it on MIPS.


2006-02-22  Lior Balkohen  <balkohen@gmail.com>

	* ports/sysdeps/unix/sysv/linux/mips/nptl/lowlevellock.h (FUTEX_WAKE_OP,
	FUTEX_OP_CLEAR_WAKE_IF_GT_ONE): Define.
	(lll_futex_wake_unlock): Define.
	* ports/sysdeps/unix/sysv/linux/mips/nptl/bits/pthreadtypes.h
	(__pthread_list_t, __pthread_slist_t): New typedefs.
	(pthread_mutex_t): Replace __next and __prev fields with __list.
	Include <sys/syscall.h>
	(lll_robust_mutex_dead, lll_robust_mutex_trylock, lll_robust_mutex_lock,
	lll_robust_mutex_cond_lock, lll_robust_mutex_timedlock,
	lll_robust_mutex_unlock): New macros.
	(__lll_robust_lock_wait, __lll_robust_timedlock_wait): New prototypes.
	* ports/sysdeps/unix/mips/mips32/sysdep.h: Use correct path
	to sysdep.h
	* ports/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h: Likewise
	* ports/sysdeps/unix/sysv/linux/mips/nptl/vfork.S: Use correct path
	to vfork.S
	* ports/sysdeps/unix/sysv/linux/mips/pipe.S: Use correct path
	to pipe.S
	* ports/sysdeps/unix/sysv/linux/mips/nptl/clone.S: Use correct path
	to clone.S
	* ports/sysdeps/unix/sysv/linux/mips/nptl/pt-vfork.S Use correct path
	to vfork.S


diff -Naur ports/sysdeps/unix/mips/mips32/sysdep.h
libc/ports/sysdeps/unix/mips/mips32/sysdep.h
--- ports/sysdeps/unix/mips/mips32/sysdep.h	2003-03-29 09:15:28.000000000 +0100
+++ libc/ports/sysdeps/unix/mips/mips32/sysdep.h	2006-02-22
19:50:58.000000000 +0100
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992, 1995, 1997, 1999, 2000, 2002, 2003
+/* Copyright (C) 1992, 1995, 1997, 1999, 2000, 2002, 2003, 2006
    Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Brendan Kehoe (brendan@zen.org).
@@ -18,7 +18,7 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */

-#include <sysdeps/unix/mips/sysdep.h>
+#include <ports/sysdeps/unix/mips/sysdep.h>

 /* Note that while it's better structurally, going back to call __syscall_error
    can make things confusing if you're debugging---it looks like it's jumping
diff -Naur ports/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h
libc/ports/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h
--- ports/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h	2005-03-28
11:17:26.000000000 +0200
+++ libc/ports/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h	2006-02-22
19:50:58.000000000 +0100
@@ -1,4 +1,5 @@
-/* Copyright (C) 2000, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+/* Copyright (C) 2000, 2002, 2003, 2004, 2005, 2006
+   Free Software Foundation, Inc.
    This file is part of the GNU C Library.

    The GNU C Library is free software; you can redistribute it and/or
@@ -20,7 +21,7 @@
 #define _LINUX_MIPS_MIPS32_SYSDEP_H 1

 /* There is some commonality.  */
-#include <sysdeps/unix/mips/mips32/sysdep.h>
+#include <ports/sysdeps/unix/mips/mips32/sysdep.h>

 /* For Linux we can use the system call table in the header file
 	/usr/include/asm/unistd.h
diff -Naur ports/sysdeps/unix/sysv/linux/mips/nptl/bits/pthreadtypes.h
libc/ports/sysdeps/unix/sysv/linux/mips/nptl/bits/pthreadtypes.h
--- ports/sysdeps/unix/sysv/linux/mips/nptl/bits/pthreadtypes.h	2006-01-18
09:41:47.000000000 +0100
+++ libc/ports/sysdeps/unix/sysv/linux/mips/nptl/bits/pthreadtypes.h	2006-02-22
19:50:58.000000000 +0100
@@ -55,6 +55,20 @@
 } pthread_attr_t;


+#if _MIPS_SIM == _ABI64
+typedef struct __pthread_internal_list
+{
+  struct __pthread_internal_list *__prev;
+  struct __pthread_internal_list *__next;
+} __pthread_list_t;
+#else
+typedef struct __pthread_internal_slist
+{
+  struct __pthread_internal_slist *__next;
+} __pthread_slist_t;
+#endif
+
+
 /* Data structures for mutex handling.  The structure of the attribute
    type is deliberately not exposed.  */
 typedef union
@@ -72,15 +86,14 @@
     int __kind;
 #if _MIPS_SIM == _ABI64
     int __spins;
-    struct __pthread_mutex_s *__next;
-    struct __pthread_mutex_s *__prev;
+    __pthread_list_t __list;
 # define __PTHREAD_MUTEX_HAVE_PREV	1
 #else
     unsigned int __nusers;
     __extension__ union
     {
       int __spins;
-      struct __pthread_mutex_s *__next;
+      __pthread_slist_t __list;
     };
 #endif
   } __data;
diff -Naur ports/sysdeps/unix/sysv/linux/mips/nptl/clone.S
libc/ports/sysdeps/unix/sysv/linux/mips/nptl/clone.S
--- ports/sysdeps/unix/sysv/linux/mips/nptl/clone.S	2005-03-28
11:21:52.000000000 +0200
+++ libc/ports/sysdeps/unix/sysv/linux/mips/nptl/clone.S	2006-02-22
19:50:58.000000000 +0100
@@ -1,2 +1,2 @@
 #define RESET_PID
-#include <sysdeps/unix/sysv/linux/mips/clone.S>
+#include <ports/sysdeps/unix/sysv/linux/mips/clone.S>
diff -Naur ports/sysdeps/unix/sysv/linux/mips/nptl/lowlevellock.h
libc/ports/sysdeps/unix/sysv/linux/mips/nptl/lowlevellock.h
--- ports/sysdeps/unix/sysv/linux/mips/nptl/lowlevellock.h	2005-03-28
11:21:52.000000000 +0200
+++ libc/ports/sysdeps/unix/sysv/linux/mips/nptl/lowlevellock.h	2006-02-22
20:24:24.000000000 +0100
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
+/* Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
    This file is part of the GNU C Library.

    The GNU C Library is free software; you can redistribute it and/or
@@ -21,6 +21,7 @@

 #include <time.h>
 #include <sys/param.h>
+#include <sys/syscall.h>
 #include <bits/pthreadtypes.h>
 #include <atomic.h>
 #include <sysdep.h>
@@ -30,6 +31,8 @@
 #define FUTEX_WAKE		1
 #define FUTEX_REQUEUE		3
 #define FUTEX_CMP_REQUEUE	4
+#define FUTEX_WAKE_OP		5
+#define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE	((4 << 24) | 1)

 /* Initializer for compatibility lock.	*/
 #define LLL_MUTEX_LOCK_INITIALIZER (0)
@@ -61,6 +64,15 @@
     INTERNAL_SYSCALL_ERROR_P (__ret, __err) ? -__ret : __ret;		      \
   })

+#define lll_robust_mutex_dead(futexv) \
+  do									      \
+    {									      \
+      int *__futexp = &(futexv);					      \
+      atomic_or (__futexp, FUTEX_OWNER_DIED);				      \
+      lll_futex_wake (__futexp, 1);					      \
+    }									      \
+  while (0)
+
 /* Returns non-zero if error happened, zero if success.  */
 #define lll_futex_requeue(futexp, nr_wake, nr_move, mutex, val) \
   ({									      \
@@ -72,6 +84,18 @@
     INTERNAL_SYSCALL_ERROR_P (__ret, __err);				      \
   })

+/* Returns non-zero if error happened, zero if success.  */
+#define lll_futex_wake_unlock(futexp, nr_wake, nr_wake2, futexp2) \
+  ({									      \
+    INTERNAL_SYSCALL_DECL (__err);					      \
+    long int __ret;							      \
+									      \
+    __ret = INTERNAL_SYSCALL (futex, __err, 6,				      \
+			      (futexp), FUTEX_WAKE_OP, (nr_wake),	      \
+			      (nr_wake2), (futexp2),			      \
+			      FUTEX_OP_CLEAR_WAKE_IF_GT_ONE);		      \
+    INTERNAL_SYSCALL_ERROR_P (__ret, __err);				      \
+  })

 static inline int __attribute__((always_inline))
 __lll_mutex_trylock(int *futex)
@@ -89,7 +113,16 @@
 #define lll_mutex_cond_trylock(lock)	__lll_mutex_cond_trylock (&(lock))


+static inline int __attribute__((always_inline))
+__lll_robust_mutex_trylock(int *futex, int id)
+{
+  return atomic_compare_and_exchange_val_acq (futex, id, 0) != 0;
+}
+#define lll_robust_mutex_trylock(lock, id) \
+  __lll_robust_mutex_trylock (&(lock), id)
+
 extern void __lll_lock_wait (int *futex) attribute_hidden;
+extern int __lll_robust_lock_wait (int *futex) attribute_hidden;

 static inline void __attribute__((always_inline))
 __lll_mutex_lock(int *futex)
@@ -100,6 +133,18 @@
 #define lll_mutex_lock(futex) __lll_mutex_lock (&(futex))


+static inline int __attribute__ ((always_inline))
+__lll_robust_mutex_lock (int *futex, int id)
+{
+  int result = 0;
+  if (atomic_compare_and_exchange_bool_acq (futex, id, 0) != 0)
+    result = __lll_robust_lock_wait (futex);
+  return result;
+}
+#define lll_robust_mutex_lock(futex, id) \
+  __lll_robust_mutex_lock (&(futex), id)
+
+
 static inline void __attribute__ ((always_inline))
 __lll_mutex_cond_lock (int *futex)
 {
@@ -109,9 +154,15 @@
 #define lll_mutex_cond_lock(futex) __lll_mutex_cond_lock (&(futex))


+#define lll_robust_mutex_cond_lock(futex, id) \
+  __lll_robust_mutex_lock (&(futex), (id) | FUTEX_WAITERS)
+
+
 extern int __lll_timedlock_wait (int *futex, const struct timespec *)
 	attribute_hidden;
-
+extern int __lll_robust_timedlock_wait (int *futex, const struct timespec *)
+	attribute_hidden;
+
 static inline int __attribute__ ((always_inline))
 __lll_mutex_timedlock (int *futex, const struct timespec *abstime)
 {
@@ -124,6 +175,19 @@
   __lll_mutex_timedlock (&(futex), abstime)


+static inline int __attribute__ ((always_inline))
+__lll_robust_mutex_timedlock (int *futex, const struct timespec *abstime,
+			      int id)
+{
+  int result = 0;
+  if (atomic_compare_and_exchange_bool_acq (futex, id, 0) != 0)
+    result = __lll_robust_timedlock_wait (futex, abstime);
+  return result;
+}
+#define lll_robust_mutex_timedlock(futex, abstime, id) \
+  __lll_robust_mutex_timedlock (&(futex), abstime, id)
+
+
 static inline void __attribute__ ((always_inline))
 __lll_mutex_unlock (int *futex)
 {
@@ -135,6 +199,17 @@


 static inline void __attribute__ ((always_inline))
+__lll_robust_mutex_unlock (int *futex, int mask)
+{
+  int val = atomic_exchange_rel (futex, 0);
+  if (__builtin_expect (val & mask, 0))
+    lll_futex_wake (futex, 1);
+}
+#define lll_robust_mutex_unlock(futex) \
+  __lll_robust_mutex_unlock(&(futex), FUTEX_WAITERS)
+
+
+static inline void __attribute__ ((always_inline))
 __lll_mutex_unlock_force (int *futex)
 {
   (void) atomic_exchange_rel (futex, 0);
diff -Naur ports/sysdeps/unix/sysv/linux/mips/nptl/pt-vfork.S
libc/ports/sysdeps/unix/sysv/linux/mips/nptl/pt-vfork.S
--- ports/sysdeps/unix/sysv/linux/mips/nptl/pt-vfork.S	2005-03-28
11:21:52.000000000 +0200
+++ libc/ports/sysdeps/unix/sysv/linux/mips/nptl/pt-vfork.S	2006-02-22
20:26:16.000000000 +0100
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005 Free Software Foundation, Inc.
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
    This file is part of the GNU C Library.

    The GNU C Library is free software; you can redistribute it and/or
@@ -34,4 +34,4 @@
 	sw	a2, PID_OFFSET(v1);	/* Restore the PID.  */		\
 1:

-#include <../sysdeps/unix/sysv/linux/mips/vfork.S>
+#include <ports/sysdeps/unix/sysv/linux/mips/vfork.S>
diff -Naur ports/sysdeps/unix/sysv/linux/mips/nptl/vfork.S
libc/ports/sysdeps/unix/sysv/linux/mips/nptl/vfork.S
--- ports/sysdeps/unix/sysv/linux/mips/nptl/vfork.S	2005-03-28
11:21:52.000000000 +0200
+++ libc/ports/sysdeps/unix/sysv/linux/mips/nptl/vfork.S	2006-02-22
20:25:39.000000000 +0100
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005 Free Software Foundation, Inc.
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
    This file is part of the GNU C Library.

    The GNU C Library is free software; you can redistribute it and/or
@@ -39,4 +39,4 @@
 2:	sw	a2, PID_OFFSET(v1);	/* Restore the PID.  */		\
 1:

-#include <../sysdeps/unix/sysv/linux/mips/vfork.S>
+#include <ports/sysdeps/unix/sysv/linux/mips/vfork.S>
diff -Naur ports/sysdeps/unix/sysv/linux/mips/pipe.S
libc/ports/sysdeps/unix/sysv/linux/mips/pipe.S
--- ports/sysdeps/unix/sysv/linux/mips/pipe.S	2000-04-14
19:53:07.000000000 +0200
+++ libc/ports/sysdeps/unix/sysv/linux/mips/pipe.S	2006-02-22
19:50:58.000000000 +0100
@@ -1 +1 @@
-#include <sysdeps/unix/mips/pipe.S>
+#include <ports/sysdeps/unix/mips/pipe.S>



More information about the Libc-ports mailing list