From 26d77dc296bc1f78bc0ac3e1d5662d44b634c19a Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Fri, 17 Feb 2006 18:44:32 +0000 Subject: [PATCH] (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. --- sysdeps/unix/sysv/linux/alpha/nptl/lowlevellock.h | 62 ++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/sysdeps/unix/sysv/linux/alpha/nptl/lowlevellock.h b/sysdeps/unix/sysv/linux/alpha/nptl/lowlevellock.h index ab325d2..1a2e8cb 100644 --- a/sysdeps/unix/sysv/linux/alpha/nptl/lowlevellock.h +++ b/sysdeps/unix/sysv/linux/alpha/nptl/lowlevellock.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2003, 2004 Free Software Foundation, Inc. +/* Copyright (C) 2003, 2004, 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 @@ -64,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) \ ({ \ @@ -106,7 +115,16 @@ __lll_mutex_cond_trylock(int *futex) #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) @@ -117,6 +135,18 @@ __lll_mutex_lock(int *futex) #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) { @@ -126,8 +156,14 @@ __lll_mutex_cond_lock (int *futex) #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) @@ -141,6 +177,19 @@ __lll_mutex_timedlock (int *futex, const struct timespec *abstime) __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) { @@ -152,6 +201,17 @@ __lll_mutex_unlock (int *futex) 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); -- 2.7.4