From a5f2bd861c4c84ac66164951a7f32e1d6f57849c Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Tue, 28 Feb 2006 09:57:07 +0000 Subject: [PATCH] * elf/rtld-Rules (subdir-args): New variable. (rtld-subdir-make): Use it. --- ChangeLog | 5 +++ elf/rtld-Rules | 10 ++++-- nptl/Makefile | 7 ++++- nptl/Versions | 3 ++ nptl/pthreadP.h | 17 +++++++--- nptl/pthread_mutex_getprioceiling.c | 33 ++++++++++++++++++++ nptl/pthread_mutex_init.c | 28 ++++++++++++++++- nptl/pthread_mutex_setprioceiling.c | 55 +++++++++++++++++++++++++++++++++ nptl/pthread_mutexattr_getprioceiling.c | 37 ++++++++++++++++++++++ nptl/pthread_mutexattr_getprotocol.c | 37 ++++++++++++++++++++++ nptl/pthread_mutexattr_setprioceiling.c | 39 +++++++++++++++++++++++ nptl/pthread_mutexattr_setprotocol.c | 41 ++++++++++++++++++++++++ nptl/sysdeps/pthread/pthread.h | 47 ++++++++++++++++++++++++++++ 13 files changed, 351 insertions(+), 8 deletions(-) create mode 100644 nptl/pthread_mutex_getprioceiling.c create mode 100644 nptl/pthread_mutex_setprioceiling.c create mode 100644 nptl/pthread_mutexattr_getprioceiling.c create mode 100644 nptl/pthread_mutexattr_getprotocol.c create mode 100644 nptl/pthread_mutexattr_setprioceiling.c create mode 100644 nptl/pthread_mutexattr_setprotocol.c diff --git a/ChangeLog b/ChangeLog index b5ea890..f73f548 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-02-28 Roland McGrath + + * elf/rtld-Rules (subdir-args): New variable. + (rtld-subdir-make): Use it. + 2006-02-22 Martin Schwidefsky * sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h diff --git a/elf/rtld-Rules b/elf/rtld-Rules index 61143b1..01fbbdf 100644 --- a/elf/rtld-Rules +++ b/elf/rtld-Rules @@ -1,6 +1,6 @@ # Subroutine makefile for compiling libc modules linked into dynamic linker. -# Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc. +# Copyright (C) 2002, 2003, 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 @@ -72,10 +72,16 @@ include $(patsubst %,../o-iterator.mk,$(object-suffixes-left)) # This is how we descend into each subdirectory. See below. define rtld-subdir-make -$(MAKE) -C ../$* objdir=$(objdir) -f Makefile -f ../elf/rtld-Rules rtld-all \ +$(MAKE) $(subdir-args) objdir=$(objdir) \ + -f Makefile -f ../elf/rtld-Rules rtld-all \ rtld-modules='$(addprefix rtld-,$(rtld-$*))' endef +# See subdir-target-args in ../Makefile for the model. +subdir-args = subdir=$*$(if $($*-srcdir),\ + -C $($*-srcdir) ..=`pwd`/,\ + -C $(..)$* ..=../) + FORCE: else diff --git a/nptl/Makefile b/nptl/Makefile index fff33ea..e0da950 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -118,7 +118,12 @@ libpthread-routines = init vars events version \ pthread_attr_getaffinity pthread_attr_setaffinity \ pthread_mutexattr_getrobust pthread_mutexattr_setrobust \ pthread_mutex_consistent \ - cleanup_routine unwind-forcedunwind + cleanup_routine unwind-forcedunwind \ + pthread_mutexattr_getprotocol \ + pthread_mutexattr_setprotocol \ + pthread_mutexattr_getprioceiling \ + pthread_mutexattr_setprioceiling \ + pthread_mutex_getprioceiling pthread_mutex_setprioceiling # pthread_setuid pthread_seteuid pthread_setreuid \ # pthread_setresuid \ # pthread_setgid pthread_setegid pthread_setregid \ diff --git a/nptl/Versions b/nptl/Versions index 2b4dd01..54b9b9c 100644 --- a/nptl/Versions +++ b/nptl/Versions @@ -235,6 +235,9 @@ libpthread { GLIBC_2.4 { pthread_mutexattr_getrobust_np; pthread_mutexattr_setrobust_np; pthread_mutex_consistent_np; + pthread_mutexattr_getprotocol; pthread_mutexattr_setprotocol; + pthread_mutexattr_getprioceiling; pthread_mutexattr_setprioceiling; + pthread_mutex_getprioceiling; pthread_mutex_setprioceiling; }; GLIBC_PRIVATE { diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h index 77d8f5a..a4d6d1a 100644 --- a/nptl/pthreadP.h +++ b/nptl/pthreadP.h @@ -66,15 +66,24 @@ enum PTHREAD_MUTEX_ROBUST_PRIVATE_ERRORCHECK_NP = PTHREAD_MUTEX_ROBUST_PRIVATE_NP | PTHREAD_MUTEX_ERRORCHECK_NP, PTHREAD_MUTEX_ROBUST_PRIVATE_ADAPTIVE_NP - = PTHREAD_MUTEX_ROBUST_PRIVATE_NP | PTHREAD_MUTEX_ADAPTIVE_NP + = PTHREAD_MUTEX_ROBUST_PRIVATE_NP | PTHREAD_MUTEX_ADAPTIVE_NP, + PTHREAD_MUTEX_PRIO_INHERIT_PRIVATE_NP = 32, + PTHREAD_MUTEX_PRIO_PROTECT_PRIVATE_NP = 64 }; +#define PTHREAD_MUTEX_PRIO_CEILING_SHIFT 16 +#define PTHREAD_MUTEX_PRIO_CEILING_MASK 0x00ff0000 /* Flags in mutex attr. */ -#define PTHREAD_MUTEXATTR_FLAG_ROBUST 0x40000000 -#define PTHREAD_MUTEXATTR_FLAG_PSHARED 0x80000000 +#define PTHREAD_MUTEXATTR_PROTOCOL_SHIFT 28 +#define PTHREAD_MUTEXATTR_PROTOCOL_MASK 0x30000000 +#define PTHREAD_MUTEXATTR_PRIO_CEILING_SHIFT 16 +#define PTHREAD_MUTEXATTR_PRIO_CEILING_MASK 0x00ff0000 +#define PTHREAD_MUTEXATTR_FLAG_ROBUST 0x40000000 +#define PTHREAD_MUTEXATTR_FLAG_PSHARED 0x80000000 #define PTHREAD_MUTEXATTR_FLAG_BITS \ - (PTHREAD_MUTEXATTR_FLAG_ROBUST | PTHREAD_MUTEXATTR_FLAG_PSHARED) + (PTHREAD_MUTEXATTR_FLAG_ROBUST | PTHREAD_MUTEXATTR_FLAG_PSHARED \ + | PTHREAD_MUTEXATTR_PROTOCOL_MASK | PTHREAD_MUTEXATTR_PRIO_CEILING_MASK) /* Bits used in robust mutex implementation. */ diff --git a/nptl/pthread_mutex_getprioceiling.c b/nptl/pthread_mutex_getprioceiling.c new file mode 100644 index 0000000..4d1bc28 --- /dev/null +++ b/nptl/pthread_mutex_getprioceiling.c @@ -0,0 +1,33 @@ +/* Get current priority ceiling of pthread_mutex_t. + Copyright (C) 2006 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jakub Jelinek , 2006. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include + + +int +pthread_mutex_getprioceiling (mutex, prioceiling) + const pthread_mutex_t *mutex; + int *prioceiling; +{ + *prioceiling = (mutex->__data.__kind & PTHREAD_MUTEX_PRIO_CEILING_MASK) + >> PTHREAD_MUTEX_PRIO_CEILING_SHIFT; + + return 0; +} diff --git a/nptl/pthread_mutex_init.c b/nptl/pthread_mutex_init.c index 17d1c99..f984d90 100644 --- a/nptl/pthread_mutex_init.c +++ b/nptl/pthread_mutex_init.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. +/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 2002. @@ -46,6 +46,11 @@ __pthread_mutex_init (mutex, mutexattr) if ((imutexattr->mutexkind & PTHREAD_MUTEXATTR_FLAG_ROBUST) != 0 && (imutexattr->mutexkind & PTHREAD_MUTEXATTR_FLAG_PSHARED) != 0) return ENOTSUP; + // XXX For now we don't support priority inherited or priority protected + // XXX mutexes. + if ((imutexattr->mutexkind & PTHREAD_MUTEXATTR_PROTOCOL_MASK) + != (PTHREAD_PRIO_NONE << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT)) + return ENOTSUP; /* Clear the whole variable. */ memset (mutex, '\0', __SIZEOF_PTHREAD_MUTEX_T); @@ -54,6 +59,27 @@ __pthread_mutex_init (mutex, mutexattr) mutex->__data.__kind = imutexattr->mutexkind & ~PTHREAD_MUTEXATTR_FLAG_BITS; if ((imutexattr->mutexkind & PTHREAD_MUTEXATTR_FLAG_ROBUST) != 0) mutex->__data.__kind |= PTHREAD_MUTEX_ROBUST_PRIVATE_NP; + switch ((imutexattr->mutexkind & PTHREAD_MUTEXATTR_PROTOCOL_MASK) + >> PTHREAD_MUTEXATTR_PROTOCOL_SHIFT) + { + case PTHREAD_PRIO_INHERIT: + mutex->__data.__kind |= PTHREAD_MUTEX_PRIO_INHERIT_PRIVATE_NP; + break; + case PTHREAD_PRIO_PROTECT: + mutex->__data.__kind |= PTHREAD_MUTEX_PRIO_PROTECT_PRIVATE_NP; + if (PTHREAD_MUTEX_PRIO_CEILING_MASK + == PTHREAD_MUTEXATTR_PRIO_CEILING_MASK) + mutex->__data.__kind |= (imutexattr->mutexkind + & PTHREAD_MUTEXATTR_PRIO_CEILING_MASK); + else + mutex->__data.__kind |= ((imutexattr->mutexkind + & PTHREAD_MUTEXATTR_PRIO_CEILING_MASK) + >> PTHREAD_MUTEXATTR_PRIO_CEILING_SHIFT) + << PTHREAD_MUTEX_PRIO_CEILING_SHIFT; + break; + default: + break; + } /* Default values: mutex not used yet. */ // mutex->__count = 0; already done by memset diff --git a/nptl/pthread_mutex_setprioceiling.c b/nptl/pthread_mutex_setprioceiling.c new file mode 100644 index 0000000..999b635 --- /dev/null +++ b/nptl/pthread_mutex_setprioceiling.c @@ -0,0 +1,55 @@ +/* Set current priority ceiling of pthread_mutex_t. + Copyright (C) 2006 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jakub Jelinek , 2006. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include + + +int +pthread_mutex_setprioceiling (mutex, prioceiling, old_ceiling) + pthread_mutex_t *mutex; + int prioceiling; + int *old_ceiling; +{ + /* The low bits of __kind aren't ever changed after pthread_mutex_init, + so we don't need a lock yet. */ + if ((mutex->__data.__kind & PTHREAD_MUTEX_PRIO_PROTECT_PRIVATE_NP) == 0) + return EINVAL; + + if (prioceiling < 0 || __builtin_expect (prioceiling > 255, 0)) + return EINVAL; + + /* XXX This needs to lock with TID, but shouldn't obey priority protect + protocol. */ + /* lll_xxx_mutex_lock (mutex->__data.__lock); */ + + if (old_ceiling != NULL) + *old_ceiling = (mutex->__data.__kind & PTHREAD_MUTEX_PRIO_CEILING_MASK) + >> PTHREAD_MUTEX_PRIO_CEILING_SHIFT; + + int newkind = (mutex->__data.__kind & ~PTHREAD_MUTEX_PRIO_CEILING_MASK); + mutex->__data.__kind = newkind + | (prioceiling << PTHREAD_MUTEX_PRIO_CEILING_SHIFT); + + /* XXX This needs to unlock the above special kind of lock. */ + /* lll_xxx_mutex_unlock (mutex->__data.__lock); */ + + return 0; +} diff --git a/nptl/pthread_mutexattr_getprioceiling.c b/nptl/pthread_mutexattr_getprioceiling.c new file mode 100644 index 0000000..da1beab --- /dev/null +++ b/nptl/pthread_mutexattr_getprioceiling.c @@ -0,0 +1,37 @@ +/* Get priority ceiling setting from pthread_mutexattr_t. + Copyright (C) 2006 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jakub Jelinek , 2006. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include + + +int +pthread_mutexattr_getprioceiling (attr, prioceiling) + const pthread_mutexattr_t *attr; + int *prioceiling; +{ + const struct pthread_mutexattr *iattr; + + iattr = (const struct pthread_mutexattr *) attr; + + *prioceiling = ((iattr->mutexkind & PTHREAD_MUTEXATTR_PRIO_CEILING_MASK) + >> PTHREAD_MUTEXATTR_PRIO_CEILING_SHIFT); + + return 0; +} diff --git a/nptl/pthread_mutexattr_getprotocol.c b/nptl/pthread_mutexattr_getprotocol.c new file mode 100644 index 0000000..0c28699 --- /dev/null +++ b/nptl/pthread_mutexattr_getprotocol.c @@ -0,0 +1,37 @@ +/* Get priority protocol setting from pthread_mutexattr_t. + Copyright (C) 2006 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jakub Jelinek , 2006. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include + + +int +pthread_mutexattr_getprotocol (attr, protocol) + const pthread_mutexattr_t *attr; + int *protocol; +{ + const struct pthread_mutexattr *iattr; + + iattr = (const struct pthread_mutexattr *) attr; + + *protocol = ((iattr->mutexkind & PTHREAD_MUTEXATTR_PROTOCOL_MASK) + >> PTHREAD_MUTEXATTR_PROTOCOL_SHIFT); + + return 0; +} diff --git a/nptl/pthread_mutexattr_setprioceiling.c b/nptl/pthread_mutexattr_setprioceiling.c new file mode 100644 index 0000000..6c15b46 --- /dev/null +++ b/nptl/pthread_mutexattr_setprioceiling.c @@ -0,0 +1,39 @@ +/* Change priority ceiling setting in pthread_mutexattr_t. + Copyright (C) 2006 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jakub Jelinek , 2006. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include + + +int +pthread_mutexattr_setprioceiling (attr, prioceiling) + pthread_mutexattr_t *attr; + int prioceiling; +{ + if (prioceiling < 0 || __builtin_expect (prioceiling > 255, 0)) + return EINVAL; + + struct pthread_mutexattr *iattr = (struct pthread_mutexattr *) attr; + + iattr->mutexkind = ((iattr->mutexkind & ~PTHREAD_MUTEXATTR_PRIO_CEILING_MASK) + | (prioceiling << PTHREAD_MUTEXATTR_PRIO_CEILING_SHIFT)); + + return 0; +} diff --git a/nptl/pthread_mutexattr_setprotocol.c b/nptl/pthread_mutexattr_setprotocol.c new file mode 100644 index 0000000..1912312 --- /dev/null +++ b/nptl/pthread_mutexattr_setprotocol.c @@ -0,0 +1,41 @@ +/* Change priority protocol setting in pthread_mutexattr_t. + Copyright (C) 2006 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jakub Jelinek , 2006. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include + + +int +pthread_mutexattr_setprotocol (attr, protocol) + pthread_mutexattr_t *attr; + int protocol; +{ + if (protocol != PTHREAD_PRIO_NONE + && protocol != PTHREAD_PRIO_INHERIT + && __builtin_expect (protocol != PTHREAD_PRIO_PROTECT, 0)) + return EINVAL; + + struct pthread_mutexattr *iattr = (struct pthread_mutexattr *) attr; + + iattr->mutexkind = ((iattr->mutexkind & ~PTHREAD_MUTEXATTR_PROTOCOL_MASK) + | (protocol << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT)); + + return 0; +} diff --git a/nptl/sysdeps/pthread/pthread.h b/nptl/sysdeps/pthread/pthread.h index f4935e0..e03c374 100644 --- a/nptl/sysdeps/pthread/pthread.h +++ b/nptl/sysdeps/pthread/pthread.h @@ -71,6 +71,17 @@ enum #endif +#ifdef __USE_UNIX98 +/* Mutex protocols. */ +enum +{ + PTHREAD_PRIO_NONE, + PTHREAD_PRIO_INHERIT, + PTHREAD_PRIO_PROTECT +}; +#endif + + /* Mutex initializers. */ #if __WORDSIZE == 64 # define PTHREAD_MUTEX_INITIALIZER \ @@ -711,6 +722,22 @@ extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex, extern int pthread_mutex_unlock (pthread_mutex_t *__mutex) __THROW; +#ifdef __USE_UNIX98 +/* Get the priority ceiling of MUTEX. */ +extern int pthread_mutex_getprioceiling (__const pthread_mutex_t * + __restrict __mutex, + int *__restrict __prioceiling) + __THROW; + +/* Set the priority ceiling of MUTEX to PRIOCEILING, return old + priority ceiling value in *OLD_CEILING. */ +extern int pthread_mutex_setprioceiling (pthread_mutex_t *__restrict __mutex, + int __prioceiling, + int *__restrict __old_ceiling) + __THROW; +#endif + + #ifdef __USE_GNU /* Declare the state protected by MUTEX as consistent. */ extern int pthread_mutex_consistent_np (pthread_mutex_t *__mutex) __THROW; @@ -745,6 +772,26 @@ extern int pthread_mutexattr_gettype (__const pthread_mutexattr_t *__restrict PTHREAD_MUTEX_DEFAULT). */ extern int pthread_mutexattr_settype (pthread_mutexattr_t *__attr, int __kind) __THROW; + +/* Return in *PROTOCOL the mutex protocol attribute in *ATTR. */ +extern int pthread_mutexattr_getprotocol (__const pthread_mutexattr_t * + __restrict __attr, + int *__restrict __protocol) __THROW; + +/* Set the mutex protocol attribute in *ATTR to PROTOCOL (either + PTHREAD_PRIO_NONE, PTHREAD_PRIO_INHERIT, or PTHREAD_PRIO_PROTECT). */ +extern int pthread_mutexattr_setprotocol (pthread_mutexattr_t *__attr, + int __protocol) __THROW; + +/* Return in *PRIOCEILING the mutex prioceiling attribute in *ATTR. */ +extern int pthread_mutexattr_getprioceiling (__const pthread_mutexattr_t * + __restrict __attr, + int *__restrict __prioceiling) + __THROW; + +/* Set the mutex prioceiling attribute in *ATTR to PRIOCEILING. */ +extern int pthread_mutexattr_setprioceiling (pthread_mutexattr_t *__attr, + int __prioceiling) __THROW; #endif #ifdef __USE_GNU -- 2.7.4