summaryrefslogtreecommitdiff
path: root/sysdeps/mach
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2017-12-29 15:01:46 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2017-12-29 15:01:46 +0100
commit218db6679aea0dcf05fb60566cef6e18f706d9ba (patch)
tree3099f55335743748ff18bd435e4de25b22c8f54a /sysdeps/mach
parent0a69b89843ec466fa20c994a29d13de6a45c3acb (diff)
parent7d4a84731cd80a1ef711c83535c6340f0e2b143f (diff)
Merge branch 'master' into 2.262.26
Diffstat (limited to 'sysdeps/mach')
-rw-r--r--sysdeps/mach/bits/spin-lock-inline.h14
-rw-r--r--sysdeps/mach/bits/spin-lock.h7
-rw-r--r--sysdeps/mach/hurd/bits/mutex.h64
-rw-r--r--sysdeps/mach/hurd/pt-mutex-consistent.c45
-rw-r--r--sysdeps/mach/hurd/pt-mutex-destroy.c36
-rw-r--r--sysdeps/mach/hurd/pt-mutex-getprioceiling.c32
-rw-r--r--sysdeps/mach/hurd/pt-mutex-init.c55
-rw-r--r--sysdeps/mach/hurd/pt-mutex-lock.c79
-rw-r--r--sysdeps/mach/hurd/pt-mutex-setprioceiling.c32
-rw-r--r--sysdeps/mach/hurd/pt-mutex-timedlock.c80
-rw-r--r--sysdeps/mach/hurd/pt-mutex-transfer-np.c74
-rw-r--r--sysdeps/mach/hurd/pt-mutex-trylock.c77
-rw-r--r--sysdeps/mach/hurd/pt-mutex-unlock.c90
-rw-r--r--sysdeps/mach/hurd/pt-mutex.h92
-rw-r--r--sysdeps/mach/hurd/pt-mutexattr-destroy.c31
-rw-r--r--sysdeps/mach/hurd/pt-mutexattr-getprioceiling.c32
-rw-r--r--sysdeps/mach/hurd/pt-mutexattr-getprotocol.c30
-rw-r--r--sysdeps/mach/hurd/pt-mutexattr-getpshared.c30
-rw-r--r--sysdeps/mach/hurd/pt-mutexattr-getrobust.c33
-rw-r--r--sysdeps/mach/hurd/pt-mutexattr-gettype.c31
-rw-r--r--sysdeps/mach/hurd/pt-mutexattr-init.c39
-rw-r--r--sysdeps/mach/hurd/pt-mutexattr-setprioceiling.c32
-rw-r--r--sysdeps/mach/hurd/pt-mutexattr-setprotocol.c32
-rw-r--r--sysdeps/mach/hurd/pt-mutexattr-setpshared.c34
-rw-r--r--sysdeps/mach/hurd/pt-mutexattr-setrobust.c36
-rw-r--r--sysdeps/mach/hurd/pt-mutexattr-settype.c34
-rw-r--r--sysdeps/mach/hurd/pt-mutexattr.c1
-rw-r--r--sysdeps/mach/i386/bits/spin-lock-inline.h98
-rw-r--r--sysdeps/mach/i386/bits/spin-lock.h39
-rw-r--r--sysdeps/mach/pt-spin.c8
-rw-r--r--sysdeps/mach/pt-thread-alloc.c4
31 files changed, 1163 insertions, 158 deletions
diff --git a/sysdeps/mach/bits/spin-lock-inline.h b/sysdeps/mach/bits/spin-lock-inline.h
index f9f7c29..98e4b3b 100644
--- a/sysdeps/mach/bits/spin-lock-inline.h
+++ b/sysdeps/mach/bits/spin-lock-inline.h
@@ -22,7 +22,7 @@
#include <features.h>
#include <bits/spin-lock.h>
-#include <machine-lock.h> /* This does all the work. */
+#include <lock-intern.h> /* This does all the work. */
__BEGIN_DECLS
@@ -60,17 +60,15 @@ __PT_SPIN_INLINE int __pthread_spin_trylock (__pthread_spinlock_t *__lock);
__PT_SPIN_INLINE int
__pthread_spin_trylock (__pthread_spinlock_t *__lock)
{
- return __spin_try_lock (__lock) ? 0 : __EBUSY;
+ return __spin_try_lock ((__spin_lock_t *) __lock) ? 0 : __EBUSY;
}
-__extern_inline int __pthread_spin_lock (__pthread_spinlock_t *__lock);
-extern int _pthread_spin_lock (__pthread_spinlock_t *__lock);
+__PT_SPIN_INLINE int __pthread_spin_lock (__pthread_spinlock_t *__lock);
-__extern_inline int
+__PT_SPIN_INLINE int
__pthread_spin_lock (__pthread_spinlock_t *__lock)
{
- if (__pthread_spin_trylock (__lock))
- return _pthread_spin_lock (__lock);
+ __spin_lock ((__spin_lock_t *) __lock);
return 0;
}
@@ -79,7 +77,7 @@ __PT_SPIN_INLINE int __pthread_spin_unlock (__pthread_spinlock_t *__lock);
__PT_SPIN_INLINE int
__pthread_spin_unlock (__pthread_spinlock_t *__lock)
{
- __spin_unlock (__lock);
+ __spin_unlock ((__spin_lock_t *) __lock);
return 0;
}
diff --git a/sysdeps/mach/bits/spin-lock.h b/sysdeps/mach/bits/spin-lock.h
index 537dac9..7574b37 100644
--- a/sysdeps/mach/bits/spin-lock.h
+++ b/sysdeps/mach/bits/spin-lock.h
@@ -21,17 +21,14 @@
#define _BITS_SPIN_LOCK_H 1
#include <features.h>
-#include <machine-lock.h> /* This does all the work. */
__BEGIN_DECLS
/* The type of a spin lock object. */
-typedef __spin_lock_t __pthread_spinlock_t;
+typedef volatile int __pthread_spinlock_t;
/* Initializer for a spin lock object. */
-#ifndef __PTHREAD_SPIN_LOCK_INITIALIZER
-#error __PTHREAD_SPIN_LOCK_INITIALIZER undefined: should be defined by <lock-intern.h>.
-#endif
+#define __PTHREAD_SPIN_LOCK_INITIALIZER 0
__END_DECLS
diff --git a/sysdeps/mach/hurd/bits/mutex.h b/sysdeps/mach/hurd/bits/mutex.h
new file mode 100644
index 0000000..a52a2ad
--- /dev/null
+++ b/sysdeps/mach/hurd/bits/mutex.h
@@ -0,0 +1,64 @@
+/* Mutex type. Generic version.
+
+ Copyright (C) 2000-2016
+ 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
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _BITS_MUTEX_H
+
+#ifndef __need_pthread_mutex
+# define _BITS_MUTEX_H 1
+#endif
+
+#ifndef __pthread_mutex_defined
+# if defined __need_pthread_mutex || defined _BITS_MUTEX_H
+# undef __need_pthread_mutex
+# define __pthread_mutex_defined
+
+# include <bits/mutex-attr.h>
+
+/* User visible part of a mutex. */
+struct __pthread_mutex
+{
+ unsigned int __lock;
+ unsigned int __owner_id;
+ unsigned int __cnt;
+ int __shpid;
+ int __type;
+ int __flags;
+ unsigned int __reserved1;
+ unsigned int __reserved2;
+};
+
+/* Static mutex initializers. */
+#define __PTHREAD_MUTEX_INITIALIZER \
+ { 0, 0, 0, 0, __PTHREAD_MUTEX_TIMED, 0, 0, 0 }
+
+/* The +1 is to mantain binary compatibility with the old
+ * libpthread implementation. */
+#define __PTHREAD_ERRORCHECK_MUTEX_INITIALIZER \
+ { 0, 0, 0, 0, __PTHREAD_MUTEX_ERRORCHECK + 1, 0, 0, 0 }
+
+#define __PTHREAD_RECURSIVE_MUTEX_INITIALIZER \
+ { 0, 0, 0, 0, __PTHREAD_MUTEX_RECURSIVE + 1, 0, 0, 0 }
+
+# endif
+#endif /* Not __pthread_mutex_defined. */
+
+#endif /* bits/mutex.h */
diff --git a/sysdeps/mach/hurd/pt-mutex-consistent.c b/sysdeps/mach/hurd/pt-mutex-consistent.c
new file mode 100644
index 0000000..28e9e4a
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutex-consistent.c
@@ -0,0 +1,45 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+ Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the license, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutex_consistent (pthread_mutex_t *mtxp)
+{
+ int ret = EINVAL;
+ unsigned int val = mtxp->__lock;
+
+ if ((mtxp->__flags & PTHREAD_MUTEX_ROBUST) != 0 &&
+ (val & LLL_DEAD_OWNER) != 0 &&
+ atomic_compare_and_exchange_bool_acq (&mtxp->__lock,
+ __getpid () | LLL_WAITERS, val) == 0)
+ {
+ /* The mutex is now ours, and it's consistent. */
+ mtxp->__owner_id = _pthread_self()->thread;
+ mtxp->__cnt = 1;
+ ret = 0;
+ }
+
+ return (ret);
+}
+
+weak_alias (pthread_mutex_consistent, pthread_mutex_consistent_np)
diff --git a/sysdeps/mach/hurd/pt-mutex-destroy.c b/sysdeps/mach/hurd/pt-mutex-destroy.c
new file mode 100644
index 0000000..2c6acd1
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutex-destroy.c
@@ -0,0 +1,36 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+ Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the license, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int _pthread_mutex_destroy (pthread_mutex_t *mtxp)
+{
+ atomic_read_barrier ();
+ if (*(volatile unsigned int *)&mtxp->__lock != 0)
+ return (EBUSY);
+
+ mtxp->__type = -1;
+ return (0);
+}
+
+strong_alias (_pthread_mutex_destroy, pthread_mutex_destroy)
diff --git a/sysdeps/mach/hurd/pt-mutex-getprioceiling.c b/sysdeps/mach/hurd/pt-mutex-getprioceiling.c
new file mode 100644
index 0000000..8a8a080
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutex-getprioceiling.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+ Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the license, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutex_getprioceiling (const pthread_mutex_t *mtxp, int *clp)
+{
+ (void)mtxp; (void)clp;
+ return (ENOSYS);
+}
+
+stub_warning (pthread_mutex_getprioceiling)
diff --git a/sysdeps/mach/hurd/pt-mutex-init.c b/sysdeps/mach/hurd/pt-mutex-init.c
new file mode 100644
index 0000000..af9ed7e
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutex-init.c
@@ -0,0 +1,55 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+ Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the license, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+static const pthread_mutexattr_t dfl_attr =
+{
+ .__prioceiling = 0,
+ .__protocol = PTHREAD_PRIO_NONE,
+ .__pshared = PTHREAD_PROCESS_PRIVATE,
+ .__mutex_type = __PTHREAD_MUTEX_TIMED
+};
+
+int _pthread_mutex_init (pthread_mutex_t *mtxp,
+ const pthread_mutexattr_t *attrp)
+{
+ if (attrp == NULL)
+ attrp = &dfl_attr;
+
+ mtxp->__flags = (attrp->__pshared == PTHREAD_PROCESS_SHARED ?
+ GSYNC_SHARED : 0) | ((attrp->__prioceiling & PTHREAD_MUTEX_ROBUST) ?
+ PTHREAD_MUTEX_ROBUST : 0);
+
+ mtxp->__type = attrp->__mutex_type +
+ (attrp->__mutex_type != __PTHREAD_MUTEX_TIMED);
+
+ mtxp->__owner_id = 0;
+ mtxp->__shpid = 0;
+ mtxp->__cnt = 0;
+ mtxp->__lock = 0;
+
+ return (0);
+}
+
+strong_alias (_pthread_mutex_init, pthread_mutex_init)
diff --git a/sysdeps/mach/hurd/pt-mutex-lock.c b/sysdeps/mach/hurd/pt-mutex-lock.c
new file mode 100644
index 0000000..5d3c958
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutex-lock.c
@@ -0,0 +1,79 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+ Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the license, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int __pthread_mutex_lock (pthread_mutex_t *mtxp)
+{
+ struct __pthread *self;
+ int flags = mtxp->__flags & GSYNC_SHARED;
+ int ret = 0;
+
+ switch (MTX_TYPE (mtxp))
+ {
+ case PT_MTX_NORMAL:
+ lll_lock (&mtxp->__lock, flags);
+ break;
+
+ case PT_MTX_RECURSIVE:
+ self = _pthread_self ();
+ if (mtx_owned_p (mtxp, self, flags))
+ {
+ if (__glibc_unlikely (mtxp->__cnt + 1 == 0))
+ return (EAGAIN);
+
+ ++mtxp->__cnt;
+ return (ret);
+ }
+
+ lll_lock (&mtxp->__lock, flags);
+ mtx_set_owner (mtxp, self, flags);
+ mtxp->__cnt = 1;
+ break;
+
+ case PT_MTX_ERRORCHECK:
+ self = _pthread_self ();
+ if (mtx_owned_p (mtxp, self, flags))
+ return (EDEADLK);
+
+ lll_lock (&mtxp->__lock, flags);
+ mtx_set_owner (mtxp, self, flags);
+ break;
+
+ case PT_MTX_NORMAL | PTHREAD_MUTEX_ROBUST:
+ case PT_MTX_RECURSIVE | PTHREAD_MUTEX_ROBUST:
+ case PT_MTX_ERRORCHECK | PTHREAD_MUTEX_ROBUST:
+ self = _pthread_self ();
+ ROBUST_LOCK (self, mtxp, __lll_robust_lock, flags);
+ break;
+
+ default:
+ ret = EINVAL;
+ break;
+ }
+
+ return (ret);
+}
+
+strong_alias (__pthread_mutex_lock, _pthread_mutex_lock)
+strong_alias (__pthread_mutex_lock, pthread_mutex_lock)
diff --git a/sysdeps/mach/hurd/pt-mutex-setprioceiling.c b/sysdeps/mach/hurd/pt-mutex-setprioceiling.c
new file mode 100644
index 0000000..b88917d
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutex-setprioceiling.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+ Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the license, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutex_setprioceiling (pthread_mutex_t *mtxp, int cl, int *prp)
+{
+ (void)mtxp; (void)cl; (void)prp;
+ return (ENOSYS);
+}
+
+stub_warning (pthread_mutex_setprioceiling)
diff --git a/sysdeps/mach/hurd/pt-mutex-timedlock.c b/sysdeps/mach/hurd/pt-mutex-timedlock.c
new file mode 100644
index 0000000..3fdd5da
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutex-timedlock.c
@@ -0,0 +1,80 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+ Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the license, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutex_timedlock (pthread_mutex_t *mtxp,
+ const struct timespec *tsp)
+{
+ struct __pthread *self;
+ int ret, flags = mtxp->__flags & GSYNC_SHARED;
+
+ switch (MTX_TYPE (mtxp))
+ {
+ case PT_MTX_NORMAL:
+ ret = lll_abstimed_lock (&mtxp->__lock, tsp, flags);
+ break;
+
+ case PT_MTX_RECURSIVE:
+ self = _pthread_self ();
+ if (mtx_owned_p (mtxp, self, flags))
+ {
+ if (__glibc_unlikely (mtxp->__cnt + 1 == 0))
+ return (EAGAIN);
+
+ ++mtxp->__cnt;
+ ret = 0;
+ }
+ else if ((ret = lll_abstimed_lock (&mtxp->__lock,
+ tsp, flags)) == 0)
+ {
+ mtx_set_owner (mtxp, self, flags);
+ mtxp->__cnt = 1;
+ }
+
+ break;
+
+ case PT_MTX_ERRORCHECK:
+ self = _pthread_self ();
+ if (mtx_owned_p (mtxp, self, flags))
+ ret = EDEADLK;
+ else if ((ret = lll_abstimed_lock (&mtxp->__lock,
+ tsp, flags)) == 0)
+ mtx_set_owner (mtxp, self, flags);
+
+ break;
+
+ case PT_MTX_NORMAL | PTHREAD_MUTEX_ROBUST:
+ case PT_MTX_RECURSIVE | PTHREAD_MUTEX_ROBUST:
+ case PT_MTX_ERRORCHECK | PTHREAD_MUTEX_ROBUST:
+ self = _pthread_self ();
+ ROBUST_LOCK (self, mtxp, lll_robust_abstimed_lock, tsp, flags);
+ break;
+
+ default:
+ ret = EINVAL;
+ break;
+ }
+
+ return (ret);
+}
diff --git a/sysdeps/mach/hurd/pt-mutex-transfer-np.c b/sysdeps/mach/hurd/pt-mutex-transfer-np.c
new file mode 100644
index 0000000..410474f
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutex-transfer-np.c
@@ -0,0 +1,74 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+ Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the license, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int __pthread_mutex_transfer_np (pthread_mutex_t *mtxp, pthread_t th)
+{
+ struct __pthread *self = _pthread_self ();
+ struct __pthread *pt = __pthread_getid (th);
+
+ if (!pt)
+ return (ESRCH);
+ else if (pt == self)
+ return (0);
+
+ int ret = 0;
+ int flags = mtxp->__flags & GSYNC_SHARED;
+
+ switch (MTX_TYPE (mtxp))
+ {
+ case PT_MTX_NORMAL:
+ break;
+
+ case PT_MTX_RECURSIVE:
+ case PT_MTX_ERRORCHECK:
+ if (!mtx_owned_p (mtxp, self, flags))
+ ret = EPERM;
+ else
+ mtx_set_owner (mtxp, pt, flags);
+
+ break;
+
+ case PT_MTX_NORMAL | PTHREAD_MUTEX_ROBUST:
+ case PT_MTX_RECURSIVE | PTHREAD_MUTEX_ROBUST:
+ case PT_MTX_ERRORCHECK | PTHREAD_MUTEX_ROBUST:
+ /* Note that this can be used to transfer an inconsistent
+ * mutex as well. The new owner will still have the same
+ * flags as the original. */
+ if (mtxp->__owner_id != self->thread ||
+ (int)(mtxp->__lock & LLL_OWNER_MASK) != __getpid ())
+ ret = EPERM;
+ else
+ mtxp->__owner_id = pt->thread;
+
+ break;
+
+ default:
+ ret = EINVAL;
+ }
+
+ return (ret);
+}
+
+weak_alias (__pthread_mutex_transfer_np, pthread_mutex_transfer_np)
diff --git a/sysdeps/mach/hurd/pt-mutex-trylock.c b/sysdeps/mach/hurd/pt-mutex-trylock.c
new file mode 100644
index 0000000..6680094
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutex-trylock.c
@@ -0,0 +1,77 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+ Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the license, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int __pthread_mutex_trylock (pthread_mutex_t *mtxp)
+{
+ struct __pthread *self;
+ int ret;
+
+ switch (MTX_TYPE (mtxp))
+ {
+ case PT_MTX_NORMAL:
+ ret = lll_trylock (&mtxp->__lock);
+ break;
+
+ case PT_MTX_RECURSIVE:
+ self = _pthread_self ();
+ if (mtx_owned_p (mtxp, self, mtxp->__flags))
+ {
+ if (__glibc_unlikely (mtxp->__cnt + 1 == 0))
+ return (EAGAIN);
+
+ ++mtxp->__cnt;
+ ret = 0;
+ }
+ else if ((ret = lll_trylock (&mtxp->__lock)) == 0)
+ {
+ mtx_set_owner (mtxp, self, mtxp->__flags);
+ mtxp->__cnt = 1;
+ }
+
+ break;
+
+ case PT_MTX_ERRORCHECK:
+ self = _pthread_self ();
+ if ((ret = lll_trylock (&mtxp->__lock)) == 0)
+ mtx_set_owner (mtxp, self, mtxp->__flags);
+ break;
+
+ case PT_MTX_NORMAL | PTHREAD_MUTEX_ROBUST:
+ case PT_MTX_RECURSIVE | PTHREAD_MUTEX_ROBUST:
+ case PT_MTX_ERRORCHECK | PTHREAD_MUTEX_ROBUST:
+ self = _pthread_self ();
+ ROBUST_LOCK (self, mtxp, __lll_robust_trylock);
+ break;
+
+ default:
+ ret = EINVAL;
+ break;
+ }
+
+ return (ret);
+}
+
+strong_alias (__pthread_mutex_trylock, _pthread_mutex_trylock)
+strong_alias (__pthread_mutex_trylock, pthread_mutex_trylock)
diff --git a/sysdeps/mach/hurd/pt-mutex-unlock.c b/sysdeps/mach/hurd/pt-mutex-unlock.c
new file mode 100644
index 0000000..071f622
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutex-unlock.c
@@ -0,0 +1,90 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+ Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the license, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int __pthread_mutex_unlock (pthread_mutex_t *mtxp)
+{
+ struct __pthread *self;
+ int ret = 0, flags = mtxp->__flags & GSYNC_SHARED;
+
+ switch (MTX_TYPE (mtxp))
+ {
+ case PT_MTX_NORMAL:
+ lll_unlock (&mtxp->__lock, flags);
+ break;
+
+ case PT_MTX_RECURSIVE:
+ self = _pthread_self ();
+ if (!mtx_owned_p (mtxp, self, flags))
+ ret = EPERM;
+ else if (--mtxp->__cnt == 0)
+ {
+ mtxp->__owner_id = mtxp->__shpid = 0;
+ lll_unlock (&mtxp->__lock, flags);
+ }
+
+ break;
+
+ case PT_MTX_ERRORCHECK:
+ self = _pthread_self ();
+ if (!mtx_owned_p (mtxp, self, flags))
+ ret = EPERM;
+ else
+ {
+ mtxp->__owner_id = mtxp->__shpid = 0;
+ lll_unlock (&mtxp->__lock, flags);
+ }
+
+ break;
+
+ case PT_MTX_NORMAL | PTHREAD_MUTEX_ROBUST:
+ case PT_MTX_RECURSIVE | PTHREAD_MUTEX_ROBUST:
+ case PT_MTX_ERRORCHECK | PTHREAD_MUTEX_ROBUST:
+ self = _pthread_self ();
+ if (mtxp->__owner_id == NOTRECOVERABLE_ID)
+ ; /* Nothing to do. */
+ else if (mtxp->__owner_id != self->thread ||
+ (int)(mtxp->__lock & LLL_OWNER_MASK) != __getpid ())
+ ret = EPERM;
+ else if (--mtxp->__cnt == 0)
+ {
+ /* Release the lock. If it's in an inconsistent
+ * state, mark it as irrecoverable. */
+ mtxp->__owner_id = (mtxp->__lock & LLL_DEAD_OWNER) ?
+ NOTRECOVERABLE_ID : 0;
+ __lll_robust_unlock (&mtxp->__lock, flags);
+ }
+
+ break;
+
+ default:
+ ret = EINVAL;
+ break;
+ }
+
+ return (ret);
+}
+
+strong_alias (__pthread_mutex_unlock, _pthread_mutex_unlock)
+strong_alias (__pthread_mutex_unlock, pthread_mutex_unlock)
diff --git a/sysdeps/mach/hurd/pt-mutex.h b/sysdeps/mach/hurd/pt-mutex.h
new file mode 100644
index 0000000..c67453e
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutex.h
@@ -0,0 +1,92 @@
+/* Internal definitions for pthreads library.
+ Copyright (C) 2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _PT_MUTEX_H
+#define _PT_MUTEX_H 1
+
+/* Special ID used to signal an unrecoverable robust mutex. */
+#define NOTRECOVERABLE_ID (1U << 31)
+
+/* Common path for robust mutexes. Assumes the variable 'ret'
+ * is bound in the function this is called from. */
+#define ROBUST_LOCK(self, mtxp, cb, ...) \
+ if (mtxp->__owner_id == NOTRECOVERABLE_ID) \
+ return (ENOTRECOVERABLE); \
+ else if (mtxp->__owner_id == self->thread && \
+ __getpid () == (int)(mtxp->__lock & LLL_OWNER_MASK)) \
+ { \
+ if (mtxp->__type == PT_MTX_RECURSIVE) \
+ { \
+ if (__glibc_unlikely (mtxp->__cnt + 1 == 0)) \
+ return (EAGAIN); \
+ \
+ ++mtxp->__cnt; \
+ return (0); \
+ } \
+ else if (mtxp->__type == PT_MTX_ERRORCHECK) \
+ return (EDEADLK); \
+ } \
+ \
+ ret = cb (&mtxp->__lock, ##__VA_ARGS__); \
+ if (ret == 0 || ret == EOWNERDEAD) \
+ { \
+ if (mtxp->__owner_id == ENOTRECOVERABLE) \
+ ret = ENOTRECOVERABLE; \
+ else \
+ { \
+ mtxp->__owner_id = self->thread; \
+ mtxp->__cnt = 1; \
+ if (ret == EOWNERDEAD) \
+ { \
+ mtxp->__lock = mtxp->__lock | LLL_DEAD_OWNER; \
+ atomic_write_barrier (); \
+ } \
+ } \
+ } \
+ (void)0
+
+/* Check that a thread owns the mutex. For non-robust, task-shared
+ * objects, we have to check the thread *and* process-id. */
+#define mtx_owned_p(mtx, pt, flags) \
+ ((mtx)->__owner_id == (pt)->thread && \
+ (((flags) & GSYNC_SHARED) == 0 || \
+ (mtx)->__shpid == __getpid ()))
+
+/* Record a thread as the owner of the mutex. */
+#define mtx_set_owner(mtx, pt, flags) \
+ (void) \
+ ({ \
+ (mtx)->__owner_id = (pt)->thread; \
+ if ((flags) & GSYNC_SHARED) \
+ (mtx)->__shpid = __getpid (); \
+ })
+
+/* Redefined mutex types. The +1 is for binary compatibility. */
+#define PT_MTX_NORMAL __PTHREAD_MUTEX_TIMED
+#define PT_MTX_RECURSIVE (__PTHREAD_MUTEX_RECURSIVE + 1)
+#define PT_MTX_ERRORCHECK (__PTHREAD_MUTEX_ERRORCHECK + 1)
+
+/* Mutex type, including robustness. */
+#define MTX_TYPE(mtxp) \
+ ((mtxp)->__type | ((mtxp)->__flags & PTHREAD_MUTEX_ROBUST))
+
+extern int __getpid (void) __attribute__ ((const));
+
+#endif /* pt-mutex.h */
diff --git a/sysdeps/mach/hurd/pt-mutexattr-destroy.c b/sysdeps/mach/hurd/pt-mutexattr-destroy.c
new file mode 100644
index 0000000..ad711ac
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutexattr-destroy.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+ Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the license, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int __pthread_mutexattr_destroy (pthread_mutexattr_t *attrp)
+{
+ (void)attrp;
+ return (0);
+}
+weak_alias (__pthread_mutexattr_destroy, pthread_mutexattr_destroy)
diff --git a/sysdeps/mach/hurd/pt-mutexattr-getprioceiling.c b/sysdeps/mach/hurd/pt-mutexattr-getprioceiling.c
new file mode 100644
index 0000000..bcfc8c8
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutexattr-getprioceiling.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+ Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the license, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutexattr_getprioceiling (const pthread_mutexattr_t *ap, int *clp)
+{
+ (void)ap; (void)clp;
+ return (ENOSYS);
+}
+
+stub_warning (pthread_mutexattr_getprioceiling)
diff --git a/sysdeps/mach/hurd/pt-mutexattr-getprotocol.c b/sysdeps/mach/hurd/pt-mutexattr-getprotocol.c
new file mode 100644
index 0000000..cb94424
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutexattr-getprotocol.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+ Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the license, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutexattr_getprotocol (const pthread_mutexattr_t *attrp, int *ptp)
+{
+ *ptp = attrp->__protocol;
+ return (0);
+}
diff --git a/sysdeps/mach/hurd/pt-mutexattr-getpshared.c b/sysdeps/mach/hurd/pt-mutexattr-getpshared.c
new file mode 100644
index 0000000..7639528
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutexattr-getpshared.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+ Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the license, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutexattr_getpshared (const pthread_mutexattr_t *attrp, int *outp)
+{
+ *outp = attrp->__pshared;
+ return (0);
+}
diff --git a/sysdeps/mach/hurd/pt-mutexattr-getrobust.c b/sysdeps/mach/hurd/pt-mutexattr-getrobust.c
new file mode 100644
index 0000000..86a0909
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutexattr-getrobust.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+ Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the license, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutexattr_getrobust (const pthread_mutexattr_t *attrp, int *outp)
+{
+ *outp = (attrp->__prioceiling & PTHREAD_MUTEX_ROBUST) ?
+ PTHREAD_MUTEX_ROBUST : PTHREAD_MUTEX_STALLED;
+ return (0);
+}
+
+weak_alias (pthread_mutexattr_getrobust, pthread_mutexattr_getrobust_np)
diff --git a/sysdeps/mach/hurd/pt-mutexattr-gettype.c b/sysdeps/mach/hurd/pt-mutexattr-gettype.c
new file mode 100644
index 0000000..746f628
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutexattr-gettype.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+ Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the license, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutexattr_gettype (const pthread_mutexattr_t *attrp, int *outp)
+{
+ *outp = attrp->__mutex_type;
+ return (0);
+}
+
diff --git a/sysdeps/mach/hurd/pt-mutexattr-init.c b/sysdeps/mach/hurd/pt-mutexattr-init.c
new file mode 100644
index 0000000..4cac661
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutexattr-init.c
@@ -0,0 +1,39 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+ Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the license, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+static const pthread_mutexattr_t dfl_attr =
+{
+ .__prioceiling = 0,
+ .__protocol = PTHREAD_PRIO_NONE,
+ .__pshared = PTHREAD_PROCESS_PRIVATE,
+ .__mutex_type = __PTHREAD_MUTEX_TIMED
+};
+
+int __pthread_mutexattr_init (pthread_mutexattr_t *attrp)
+{
+ *attrp = dfl_attr;
+ return (0);
+}
+weak_alias (__pthread_mutexattr_init, pthread_mutexattr_init)
diff --git a/sysdeps/mach/hurd/pt-mutexattr-setprioceiling.c b/sysdeps/mach/hurd/pt-mutexattr-setprioceiling.c
new file mode 100644
index 0000000..d399050
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutexattr-setprioceiling.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+ Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the license, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutexattr_setprioceiling (pthread_mutexattr_t *attrp, int cl)
+{
+ (void)attrp; (void)cl;
+ return (ENOSYS);
+}
+
+stub_warning (pthread_mutexattr_setprioceiling)
diff --git a/sysdeps/mach/hurd/pt-mutexattr-setprotocol.c b/sysdeps/mach/hurd/pt-mutexattr-setprotocol.c
new file mode 100644
index 0000000..9f7f152
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutexattr-setprotocol.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+ Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the license, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutexattr_setprotocol (pthread_mutexattr_t *attrp, int proto)
+{
+ (void)attrp;
+ return (proto == PTHREAD_PRIO_NONE ? 0 :
+ proto != PTHREAD_PRIO_INHERIT &&
+ proto != PTHREAD_PRIO_PROTECT ? EINVAL : ENOTSUP);
+}
diff --git a/sysdeps/mach/hurd/pt-mutexattr-setpshared.c b/sysdeps/mach/hurd/pt-mutexattr-setpshared.c
new file mode 100644
index 0000000..c10dfa0
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutexattr-setpshared.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+ Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the license, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutexattr_setpshared (pthread_mutexattr_t *attrp, int pshared)
+{
+ if (pshared != PTHREAD_PROCESS_PRIVATE &&
+ pshared != PTHREAD_PROCESS_SHARED)
+ return (EINVAL);
+
+ attrp->__pshared = pshared;
+ return (0);
+}
diff --git a/sysdeps/mach/hurd/pt-mutexattr-setrobust.c b/sysdeps/mach/hurd/pt-mutexattr-setrobust.c
new file mode 100644
index 0000000..a90e747
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutexattr-setrobust.c
@@ -0,0 +1,36 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+ Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the license, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutexattr_setrobust (pthread_mutexattr_t *attrp, int robust)
+{
+ if (robust != PTHREAD_MUTEX_ROBUST &&
+ robust != PTHREAD_MUTEX_STALLED)
+ return (EINVAL);
+
+ attrp->__prioceiling |= robust;
+ return (0);
+}
+
+weak_alias (pthread_mutexattr_setrobust, pthread_mutexattr_setrobust_np)
diff --git a/sysdeps/mach/hurd/pt-mutexattr-settype.c b/sysdeps/mach/hurd/pt-mutexattr-settype.c
new file mode 100644
index 0000000..67ed4f5
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutexattr-settype.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+ Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the license, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int __pthread_mutexattr_settype (pthread_mutexattr_t *attrp, int type)
+{
+ if (type < 0 || type > __PTHREAD_MUTEX_RECURSIVE)
+ return (EINVAL);
+
+ attrp->__mutex_type = type;
+ return (0);
+}
+weak_alias (__pthread_mutexattr_settype, pthread_mutexattr_settype)
diff --git a/sysdeps/mach/hurd/pt-mutexattr.c b/sysdeps/mach/hurd/pt-mutexattr.c
new file mode 100644
index 0000000..40a8c17
--- /dev/null
+++ b/sysdeps/mach/hurd/pt-mutexattr.c
@@ -0,0 +1 @@
+/* empty */
diff --git a/sysdeps/mach/i386/bits/spin-lock-inline.h b/sysdeps/mach/i386/bits/spin-lock-inline.h
deleted file mode 100644
index e5ed3de..0000000
--- a/sysdeps/mach/i386/bits/spin-lock-inline.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/* Machine-specific definitions for spin locks. i386 version.
- Copyright (C) 2000, 2005, 2008, 2009 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
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
-
-/*
- * Never include this file directly; use <pthread.h> or <cthreads.h> instead.
- */
-
-#ifndef _BITS_SPIN_LOCK_INLINE_H
-#define _BITS_SPIN_LOCK_INLINE_H 1
-
-#include <features.h>
-#include <bits/spin-lock.h>
-
-__BEGIN_DECLS
-
-#if defined __USE_EXTERN_INLINES || defined _FORCE_INLINES
-
-# ifndef __EBUSY
-# include <errno.h>
-# define __EBUSY EBUSY
-# endif
-
-# ifndef __PT_SPIN_INLINE
-# define __PT_SPIN_INLINE __extern_inline
-# endif
-
-__PT_SPIN_INLINE int __pthread_spin_destroy (__pthread_spinlock_t *__lock);
-
-__PT_SPIN_INLINE int
-__pthread_spin_destroy (__pthread_spinlock_t *__lock)
-{
- return 0;
-}
-
-__PT_SPIN_INLINE int __pthread_spin_init (__pthread_spinlock_t *__lock,
- int __pshared);
-
-__PT_SPIN_INLINE int
-__pthread_spin_init (__pthread_spinlock_t *__lock, int __pshared)
-{
- *__lock = __PTHREAD_SPIN_LOCK_INITIALIZER;
- return 0;
-}
-
-__PT_SPIN_INLINE int __pthread_spin_trylock (__pthread_spinlock_t *__lock);
-
-__PT_SPIN_INLINE int
-__pthread_spin_trylock (__pthread_spinlock_t *__lock)
-{
- int __locked;
- __asm__ __volatile ("xchgl %0, %1"
- : "=&r" (__locked), "=m" (*__lock) : "0" (1) : "memory");
- return __locked ? __EBUSY : 0;
-}
-
-__extern_inline int __pthread_spin_lock (__pthread_spinlock_t *__lock);
-extern int _pthread_spin_lock (__pthread_spinlock_t *__lock);
-
-__extern_inline int
-__pthread_spin_lock (__pthread_spinlock_t *__lock)
-{
- if (__pthread_spin_trylock (__lock))
- return _pthread_spin_lock (__lock);
- return 0;
-}
-
-__PT_SPIN_INLINE int __pthread_spin_unlock (__pthread_spinlock_t *__lock);
-
-__PT_SPIN_INLINE int
-__pthread_spin_unlock (__pthread_spinlock_t *__lock)
-{
- int __unlocked;
- __asm__ __volatile ("xchgl %0, %1"
- : "=&r" (__unlocked), "=m" (*__lock) : "0" (0) : "memory");
- return 0;
-}
-
-#endif /* Use extern inlines or force inlines. */
-
-__END_DECLS
-
-#endif /* bits/spin-lock.h */
diff --git a/sysdeps/mach/i386/bits/spin-lock.h b/sysdeps/mach/i386/bits/spin-lock.h
deleted file mode 100644
index 5ae81e1..0000000
--- a/sysdeps/mach/i386/bits/spin-lock.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/* Machine-specific definitions for spin locks. i386 version.
- Copyright (C) 2000, 2005, 2008, 2009 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
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
-
-/*
- * Never include this file directly; use <pthread.h> or <cthreads.h> instead.
- */
-
-#ifndef _BITS_SPIN_LOCK_H
-#define _BITS_SPIN_LOCK_H 1
-
-#include <features.h>
-
-__BEGIN_DECLS
-
-/* The type of a spin lock object. */
-typedef __volatile int __pthread_spinlock_t;
-
-/* Initializer for a spin lock object. */
-# define __PTHREAD_SPIN_LOCK_INITIALIZER ((__pthread_spinlock_t) 0)
-
-__END_DECLS
-
-#endif /* bits/spin-lock.h */
diff --git a/sysdeps/mach/pt-spin.c b/sysdeps/mach/pt-spin.c
index d9a2a32..0cf1c49 100644
--- a/sysdeps/mach/pt-spin.c
+++ b/sysdeps/mach/pt-spin.c
@@ -17,20 +17,16 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <pthread.h>
#include <machine-lock.h>
/* In glibc. */
-extern void __spin_lock_solid (__pthread_spinlock_t *lock);
+extern void __spin_lock_solid (__spin_lock_t *lock);
/* Lock the spin lock object LOCK. If the lock is held by another
thread spin until it becomes available. */
int
-_pthread_spin_lock (__pthread_spinlock_t *lock)
+_pthread_spin_lock (__spin_lock_t *lock)
{
__spin_lock_solid (lock);
return 0;
}
-
-weak_alias (_pthread_spin_lock, pthread_spin_lock);
-weak_alias (_pthread_spin_lock, __pthread_spin_lock);
diff --git a/sysdeps/mach/pt-thread-alloc.c b/sysdeps/mach/pt-thread-alloc.c
index 77aa933..76e5660 100644
--- a/sysdeps/mach/pt-thread-alloc.c
+++ b/sysdeps/mach/pt-thread-alloc.c
@@ -56,8 +56,8 @@ create_wakeupmsg (struct __pthread *thread)
}
/* No need to queue more than one wakeup message on this port. */
- mach_port_set_qlimit (__mach_task_self (),
- thread->wakeupmsg.msgh_remote_port, 1);
+ __mach_port_set_qlimit (__mach_task_self (),
+ thread->wakeupmsg.msgh_remote_port, 1);
return 0;
}