diff options
| author | christos <christos@NetBSD.org> | 2016-07-03 14:24:58 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2016-07-03 14:24:58 +0000 |
| commit | 774674fd4710ea607eef47c793bd0cf3d4eb5184 (patch) | |
| tree | 05cc5703bc1498308ea98c1fe07c25fdaee74f76 /lib/libpthread | |
| parent | 3abdd8b82ad97d2929a64342f1bbc596ee3b1efa (diff) | |
GSoC 2016 Charles Cui: Implement thread priority protection based on work
by Andy Doran. Also document the get/set pshared thread calls as not
implemented, and add a skeleton implementation that is disabled.
XXX: document _sched_protect(2).
Diffstat (limited to 'lib/libpthread')
| -rw-r--r-- | lib/libpthread/Makefile | 18 | ||||
| -rw-r--r-- | lib/libpthread/pthread.h | 46 | ||||
| -rw-r--r-- | lib/libpthread/pthread_barrier.3 | 60 | ||||
| -rw-r--r-- | lib/libpthread/pthread_barrier.c | 27 | ||||
| -rw-r--r-- | lib/libpthread/pthread_barrierattr.3 | 42 | ||||
| -rw-r--r-- | lib/libpthread/pthread_cond.c | 38 | ||||
| -rw-r--r-- | lib/libpthread/pthread_condattr.3 | 62 | ||||
| -rw-r--r-- | lib/libpthread/pthread_mutex.3 | 88 | ||||
| -rw-r--r-- | lib/libpthread/pthread_mutex.c | 197 | ||||
| -rw-r--r-- | lib/libpthread/pthread_mutexattr.3 | 171 | ||||
| -rw-r--r-- | lib/libpthread/pthread_rwlock.c | 27 | ||||
| -rw-r--r-- | lib/libpthread/pthread_rwlockattr.3 | 51 | ||||
| -rw-r--r-- | lib/libpthread/pthread_types.h | 4 |
13 files changed, 729 insertions, 102 deletions
diff --git a/lib/libpthread/Makefile b/lib/libpthread/Makefile index b5e6b97263b..37727058f11 100644 --- a/lib/libpthread/Makefile +++ b/lib/libpthread/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.86 2016/04/23 23:12:19 christos Exp $ +# $NetBSD: Makefile,v 1.87 2016/07/03 14:24:58 christos Exp $ # WARNS?= 5 @@ -177,6 +177,8 @@ MLINKS+= pthread_barrier.3 pthread_barrier_wait.3 MLINKS+= pthread_barrierattr.3 pthread_barrierattr_init.3 MLINKS+= pthread_barrierattr.3 pthread_barrierattr_destroy.3 +MLINKS+= pthread_barrierattr.3 pthread_barrierattr_getpshared.3 +MLINKS+= pthread_barrierattr.3 pthread_barrierattr_setpshared.3 MLINKS+= pthread_cond.3 pthread_cond_init.3 MLINKS+= pthread_cond.3 pthread_cond_destroy.3 @@ -188,6 +190,9 @@ MLINKS+= pthread_cond.3 pthread_cond_timedwait.3 MLINKS+= pthread_condattr.3 pthread_condattr_init.3 MLINKS+= pthread_condattr.3 pthread_condattr_destroy.3 MLINKS+= pthread_condattr.3 pthread_condattr_setclock.3 +MLINKS+= pthread_condattr.3 pthread_condattr_getclock.3 +MLINKS+= pthread_condattr.3 pthread_condattr_getpshared.3 +MLINKS+= pthread_condattr.3 pthread_condattr_setpshared.3 MLINKS+= pthread_getname_np.3 pthread_setname_np.3 MLINKS+= pthread_getspecific.3 pthread_setspecific.3 @@ -198,11 +203,20 @@ MLINKS+= pthread_mutex.3 pthread_mutex_destroy.3 MLINKS+= pthread_mutex.3 pthread_mutex_lock.3 MLINKS+= pthread_mutex.3 pthread_mutex_trylock.3 MLINKS+= pthread_mutex.3 pthread_mutex_unlock.3 +MLINKS+= pthread_mutex.3 pthread_mutex_timedlock.3 +MLINKS+= pthread_mutex.3 pthread_mutex_getprioceiling.3 +MLINKS+= pthread_mutex.3 pthread_mutex_setprioceiling.3 MLINKS+= pthread_mutexattr.3 pthread_mutexattr_init.3 MLINKS+= pthread_mutexattr.3 pthread_mutexattr_destroy.3 +MLINKS+= pthread_mutexattr.3 pthread_mutexattr_getpshared.3 +MLINKS+= pthread_mutexattr.3 pthread_mutexattr_setpshared.3 MLINKS+= pthread_mutexattr.3 pthread_mutexattr_settype.3 MLINKS+= pthread_mutexattr.3 pthread_mutexattr_gettype.3 +MLINKS+= pthread_mutexattr.3 pthread_mutexattr_getprotocol.3 +MLINKS+= pthread_mutexattr.3 pthread_mutexattr_setprotocol.3 +MLINKS+= pthread_mutexattr.3 pthread_mutexattr_getprioceiling.3 +MLINKS+= pthread_mutexattr.3 pthread_mutexattr_setprioceiling.3 MLINKS+= pthread_rwlock.3 pthread_rwlock_init.3 MLINKS+= pthread_rwlock.3 pthread_rwlock_destroy.3 @@ -217,6 +231,8 @@ MLINKS+= pthread_rwlock.3 pthread_rwlock_trywrlock.3 MLINKS+= pthread_rwlockattr.3 pthread_rwlockattr_init.3 MLINKS+= pthread_rwlockattr.3 pthread_rwlockattr_destroy.3 +MLINKS+= pthread_rwlockattr.3 pthread_rwlockattr_getpshared.3 +MLINKS+= pthread_rwlockattr.3 pthread_rwlockattr_setpshared.3 MLINKS+= pthread_spin.3 pthread_spin_init.3 MLINKS+= pthread_spin.3 pthread_spin_destroy.3 diff --git a/lib/libpthread/pthread.h b/lib/libpthread/pthread.h index 8f7da27af8b..83246ea1224 100644 --- a/lib/libpthread/pthread.h +++ b/lib/libpthread/pthread.h @@ -1,4 +1,4 @@ -/* $NetBSD: pthread.h,v 1.36 2016/04/23 23:12:19 christos Exp $ */ +/* $NetBSD: pthread.h,v 1.37 2016/07/03 14:24:58 christos Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -94,12 +94,30 @@ int pthread_mutex_destroy(pthread_mutex_t *); int pthread_mutex_lock(pthread_mutex_t *); int pthread_mutex_trylock(pthread_mutex_t *); int pthread_mutex_unlock(pthread_mutex_t *); +int pthread_mutex_timedlock(pthread_mutex_t *, + const struct timespec * __restrict); +int pthread_mutex_getprioceiling(const pthread_mutex_t * __restrict, + int * __restrict); +int pthread_mutex_setprioceiling(pthread_mutex_t * __restrict, int, + int * __restrict); int pthread_mutexattr_init(pthread_mutexattr_t *); int pthread_mutexattr_destroy(pthread_mutexattr_t *); +#ifdef _PTHREAD_PSHARED +int pthread_mutexattr_getpshared(const pthread_mutexattr_t * __restrict, + int * __restrict); +int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int); +#endif int pthread_mutexattr_gettype(const pthread_mutexattr_t * __restrict, int * __restrict); int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int); - +int pthread_mutexattr_getprotocol(const pthread_mutexattr_t * __restrict, + int * __restrict); +int pthread_mutexattr_setprotocol(pthread_mutexattr_t*, + int); +int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t * __restrict, + int * __restrict); +int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, + int); int pthread_cond_init(pthread_cond_t * __restrict, const pthread_condattr_t * __restrict); int pthread_cond_destroy(pthread_cond_t *); @@ -114,9 +132,15 @@ int pthread_cond_broadcast(pthread_cond_t *); int pthread_condattr_init(pthread_condattr_t *); #if defined(_NETBSD_SOURCE) int pthread_condattr_setclock(pthread_condattr_t *, clockid_t); +int pthread_condattr_getclock(const pthread_condattr_t * __restrict, + clockid_t * __restrict); #endif int pthread_condattr_destroy(pthread_condattr_t *); - +#ifdef _PTHREAD_PSHARED +int pthread_condattr_getpshared(const pthread_condattr_t * __restrict, + int * __restrict); +int pthread_condattr_setpshared(pthread_condattr_t *, int); +#endif int pthread_once(pthread_once_t *, void (*)(void)); int pthread_key_create(pthread_key_t *, void (*)(void *)); @@ -178,14 +202,22 @@ int pthread_rwlock_timedwrlock(pthread_rwlock_t * __restrict, int pthread_rwlock_unlock(pthread_rwlock_t *); int pthread_rwlockattr_init(pthread_rwlockattr_t *); int pthread_rwlockattr_destroy(pthread_rwlockattr_t *); - +#ifdef _PTHREAD_PSHARED +int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t * __restrict, + int * __restrict); +int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int); +#endif int pthread_barrier_init(pthread_barrier_t * __restrict, const pthread_barrierattr_t * __restrict, unsigned int); int pthread_barrier_wait(pthread_barrier_t *); int pthread_barrier_destroy(pthread_barrier_t *); int pthread_barrierattr_init(pthread_barrierattr_t *); int pthread_barrierattr_destroy(pthread_barrierattr_t *); - +#ifdef _PTHREAD_PSHARED +int pthread_barrierattr_getpshared(const pthread_barrierattr_t * __restrict, + int * __restrict); +int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int); +#endif int pthread_getschedparam(pthread_t, int * __restrict, struct sched_param * __restrict); int pthread_setschedparam(pthread_t, int, const struct sched_param *); @@ -251,6 +283,10 @@ __END_DECLS #define PTHREAD_MUTEX_RECURSIVE 2 #define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL +#define PTHREAD_PRIO_NONE 0 +#define PTHREAD_PRIO_INHERIT 1 +#define PTHREAD_PRIO_PROTECT 2 + #define PTHREAD_COND_INITIALIZER _PTHREAD_COND_INITIALIZER #define PTHREAD_MUTEX_INITIALIZER _PTHREAD_MUTEX_INITIALIZER #define PTHREAD_ONCE_INIT _PTHREAD_ONCE_INIT diff --git a/lib/libpthread/pthread_barrier.3 b/lib/libpthread/pthread_barrier.3 index 8cbec101239..097bb24247e 100644 --- a/lib/libpthread/pthread_barrier.3 +++ b/lib/libpthread/pthread_barrier.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: pthread_barrier.3,v 1.4 2010/07/09 18:07:20 jruoho Exp $ +.\" $NetBSD: pthread_barrier.3,v 1.5 2016/07/03 14:24:58 christos Exp $ .\" .\" Copyright (c) 2002, 2010 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -25,7 +25,8 @@ .\" POSSIBILITY OF SUCH DAMAGE. .\" .\" ---------------------------------------------------------------------------- -.Dd July 8, 2010 + +.Dd June 12, 2016 .Dt PTHREAD_BARRIER 3 .Os .Sh NAME @@ -42,7 +43,14 @@ .Fn pthread_barrier_destroy "pthread_barrier_t *barrier" .Ft int .Fn pthread_barrier_wait "pthread_barrier_t *barrier" +.Ft int +.Fn pthread_barrierattr_getpshared "const pthread_barrierattr_t * __restrict attr" \ +"int * __restrict pshared" +.Ft int +.Fn pthread_barrierattr_setpshared "pthread_barrierattr_t * attr" \ +"int pshared" .\" ---------------------------------------------------------------------------- + .Sh DESCRIPTION The .Fn pthread_barrier_init @@ -87,7 +95,18 @@ call have called all threads will wake up, return from their respective .Fn pthread_barrier_wait calls and continue execution. +.Pp +.\" ----- +The +.Fn pthread_barrierattr_getpshared +function shall obtain the value of the process-shared attribute from the +attributes object referenced by attr. +The +.Fn pthread_barrierattr_setpshared +function shall set the process-shared attribute in an initialized attributes +object referenced by attr. .\" ---------------------------------------------------------------------------- + .Sh RETURN VALUES If successful, .Fn pthread_barrier_init @@ -113,7 +132,23 @@ It is the responsibility of this thread to insure the visibility and atomicity of any updates to shared data with respect to the other threads participating in the barrier. In the case of failure, an error value will be returned. +.Pp +.\" ----- +If successful, +.Fn pthread_barrierattr_getpshared +shall return zero and store the value of the process-shared attribute of attr +into the object referenced by the +.Fa pshared +parameter. +Otherwise, an error number shall be returned to indicate the error. +.Pp +.\" ----- +If successful, +.Fn pthread_barrierattr_setpshared +shall return zero; +Otherwise, an error number shall be returned to indicate the error. .\" ---------------------------------------------------------------------------- + .Sh ERRORS The .Fn pthread_barrier_init @@ -152,6 +187,20 @@ The value specified by .Fa barrier is invalid. .El +.Pp +.\" ----- +The +.Fn pthread_barrierattr_setpshared +function and +the +.Fn pthread_barrierattr_getpshared +function may fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value specified by +.Fa attr +is invalid. + .\" --------------------------------------------------------------------------- .Sh SEE ALSO .Xr pthread_barrierattr 3 , @@ -160,3 +209,10 @@ is invalid. .Sh STANDARDS These functions conform to .St -p1003.1-2001 . +.Sh BUGS +The +.Fn pthread_barrierattr_getpshared +and +.Fn pthread_barrierattr_setpshared +functions are hidden by default since only thread shared attributes +are supported. diff --git a/lib/libpthread/pthread_barrier.c b/lib/libpthread/pthread_barrier.c index 4fa5f166ef3..5e53218a225 100644 --- a/lib/libpthread/pthread_barrier.c +++ b/lib/libpthread/pthread_barrier.c @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_barrier.c,v 1.19 2009/01/29 21:19:35 ad Exp $ */ +/* $NetBSD: pthread_barrier.c,v 1.20 2016/07/03 14:24:58 christos Exp $ */ /*- * Copyright (c) 2001, 2003, 2006, 2007, 2009 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: pthread_barrier.c,v 1.19 2009/01/29 21:19:35 ad Exp $"); +__RCSID("$NetBSD: pthread_barrier.c,v 1.20 2016/07/03 14:24:58 christos Exp $"); #include <errno.h> @@ -117,6 +117,29 @@ pthread_barrier_wait(pthread_barrier_t *barrier) return 0; } +#ifdef _PTHREAD_PSHARED +int +pthread_barrierattr_getpshared(const pthread_barrierattr_t * __restrict attr, + int * __restrict pshared) +{ + + *pshared = PTHREAD_PROCESS_PRIVATE; + return 0; +} + +int +pthread_barrierattr_setpshared(pthread_barrierattr_t *attr, int pshared) +{ + + switch(pshared) { + case PTHREAD_PROCESS_PRIVATE: + return 0; + case PTHREAD_PROCESS_SHARED: + return ENOSYS; + } + return EINVAL; +} +#endif int pthread_barrierattr_init(pthread_barrierattr_t *attr) diff --git a/lib/libpthread/pthread_barrierattr.3 b/lib/libpthread/pthread_barrierattr.3 index 38b04f192b4..c6c05fc0253 100644 --- a/lib/libpthread/pthread_barrierattr.3 +++ b/lib/libpthread/pthread_barrierattr.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: pthread_barrierattr.3,v 1.9 2010/07/09 10:45:36 wiz Exp $ +.\" $NetBSD: pthread_barrierattr.3,v 1.10 2016/07/03 14:24:58 christos Exp $ .\" .\" Copyright (c) 2002 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -22,12 +22,14 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd July 9, 2010 +.Dd June 12, 2016 .Dt PTHREAD_BARRIERATTR 3 .Os .Sh NAME .Nm pthread_barrierattr_init , .Nm pthread_barrierattr_destroy , +.Nm pthread_barrierattr_getpshared , +.Nm pthread_barrierattr_setpshared .Nd barrier attribute operations .Sh LIBRARY .Lb libpthread @@ -37,6 +39,10 @@ .Fn pthread_barrierattr_init "pthread_barrierattr_t *attr" .Ft int .Fn pthread_barrierattr_destroy "pthread_barrierattr_t *attr" +.Ft int +.Fn pthread_barrierattr_getpshared "const pthread_barrierattr_t * __restrict attr" "int * __restrict pshared" +.Ft int +.Fn pthread_barrierattr_setpshared "pthread_barrierattr_t * attr" "int pshared" .Sh DESCRIPTION Barrier attributes are used to specify parameters to be used with .Xr pthread_barrier_init 3 . @@ -54,6 +60,19 @@ The .Fn pthread_barrierattr_destroy function destroys .Fa attr . +.Pp +The +.Fn pthread_barrierattr_getpshared +function shall obtain the value of the process-shared attribute +from the attributes object referenced by +.Fa attr . +.Pp +The +.Fn pthread_barrierattr_setpshared +function shall set the process-shared attribute in an initialized +attributes object referenced by +.Fa attr . + .Sh RETURN VALUES If successful, these functions return 0. Otherwise, an error number is returned to indicate the error. @@ -70,8 +89,27 @@ The value specified by .Fa attr is invalid. .El +.Pp +The +.Fn pthread_barrierattr_getpshared +and +.Fn pthread_barrierattr_setpshared +may fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value specified by +.Fa attr +is invalid. +.El .Sh SEE ALSO .Xr pthread_barrier_init 3 .Sh STANDARDS Both functions conform to .St -p1003.1-2001 . +.Sh BUGS +The +.Fn pthread_barrierattr_getpshared +and +.Fn pthread_barrierattr_setpshared +functions are hidden by default since only thread shared attributes +are supported. diff --git a/lib/libpthread/pthread_cond.c b/lib/libpthread/pthread_cond.c index 4be884a1395..101ca18c427 100644 --- a/lib/libpthread/pthread_cond.c +++ b/lib/libpthread/pthread_cond.c @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_cond.c,v 1.63 2014/01/31 20:44:01 christos Exp $ */ +/* $NetBSD: pthread_cond.c,v 1.64 2016/07/03 14:24:58 christos Exp $ */ /*- * Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -46,7 +46,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: pthread_cond.c,v 1.63 2014/01/31 20:44:01 christos Exp $"); +__RCSID("$NetBSD: pthread_cond.c,v 1.64 2016/07/03 14:24:58 christos Exp $"); #include <stdlib.h> #include <errno.h> @@ -370,6 +370,16 @@ pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clck) } int +pthread_condattr_getclock(const pthread_condattr_t *__restrict attr, + clockid_t *__restrict clock_id) +{ + if (attr == NULL || attr->ptca_private == NULL) + return EINVAL; + *clock_id = *(clockid_t *)attr->ptca_private; + return 0; +} + +int pthread_condattr_destroy(pthread_condattr_t *attr) { @@ -382,6 +392,30 @@ pthread_condattr_destroy(pthread_condattr_t *attr) return 0; } +#ifdef _PTHREAD_PSHARED +int +pthread_condattr_getpshared(const pthread_condattr_t * __restrict attr, + int * __restrict pshared) +{ + + *pshared = PTHREAD_PROCESS_PRIVATE; + return 0; +} + +int +pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared) +{ + + switch(pshared) { + case PTHREAD_PROCESS_PRIVATE: + return 0; + case PTHREAD_PROCESS_SHARED: + return ENOSYS; + } + return EINVAL; +} +#endif + /* Utility routine to hang out for a while if threads haven't started yet. */ static int pthread_cond_wait_nothread(pthread_t self, pthread_mutex_t *mutex, diff --git a/lib/libpthread/pthread_condattr.3 b/lib/libpthread/pthread_condattr.3 index 6816c429619..5d72bc362a1 100644 --- a/lib/libpthread/pthread_condattr.3 +++ b/lib/libpthread/pthread_condattr.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: pthread_condattr.3,v 1.9 2012/11/03 09:20:36 wiz Exp $ +.\" $NetBSD: pthread_condattr.3,v 1.10 2016/07/03 14:24:58 christos Exp $ .\" .\" Copyright (c) 2002 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -50,11 +50,15 @@ .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" $FreeBSD: src/lib/libpthread/man/pthread_condattr.3,v 1.10 2002/09/16 19:29:28 mini Exp $ -.Dd November 2, 2012 +.Dd June 12, 2016 .Dt PTHREAD_CONDATTR 3 .Os .Sh NAME -.Nm pthread_condattr_init +.Nm pthread_condattr_init, +.Nm pthread_condattr_getpshared, +.Nm pthread_condattr_setpshared, +.Nm pthread_condattr_getclock, +.Nm pthread_condattr_setclock .Nd condition attribute operations .Sh LIBRARY .Lb libpthread @@ -63,9 +67,16 @@ .Ft int .Fn pthread_condattr_init "pthread_condattr_t *attr" .Ft int +.Fn pthread_condattr_getclock "const pthread_condattr_t *__restrict attr" \ +"clockid_t * __restrict clock_id" +.Ft int .Fn pthread_condattr_setclock "pthread_condattr_t *attr" "clockid_t clock" .Ft int .Fn pthread_condattr_destroy "pthread_condattr_t *attr" +.Ft int +.Fn pthread_condattr_getpshared "const pthread_condattr_t * __restrict attr" "int * __restrict pshared" +.Ft int +.Fn pshared_condattr_setpshared "pthread_condattr_t *attr" "int pshared" .Sh DESCRIPTION Condition attribute objects are used to specify parameters to the .Xr pthread_cond_init 3 @@ -77,6 +88,12 @@ and the .Fn pthread_condattr_destroy function destroys a condition attribute object. The +.Fn pthread_condattr_getclock +function shall obtain the value of the +.Fa clock +attributes object referenced by +.Fa attr. +The .Fn pthread_condattr_setclock function sets the system clock to be used for time comparisons to the one specified in @@ -86,6 +103,16 @@ Valid clock values are and .Dv CLOCK_REALTIME (the default). +The +.Fn pthread_condattr_getpshared +function shall obtain the value of the process-shared attribute from the +attributes object referenced by +.Fa attr. +The +.Fn pthread_condattr_setpshared +function shall set the process-shared attribute in an initialized attributes +object referenced by +.Fa attr. .Sh RETURN VALUES If successful, these functions return 0. Otherwise, an error number is returned to indicate the error. @@ -102,6 +129,28 @@ The value specified by .Fa attr is invalid. .El +.Pp +The +.Fn pthread_condattr_getclock +and +.Fn pthread_condattr_setclock +may fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value specified by +.Fa attr is invalid. +.El +.Pp +The +.Fn pthread_condattr_getpshared +and +.Fn pthread_condattr_setpshared +may fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value specified by +.Fa attr +is invalid. .Sh SEE ALSO .Xr pthread_cond_init 3 .Sh STANDARDS @@ -115,3 +164,10 @@ These functions do not conform to the .St -p1003.1-2008 revision of the standard, which mandates two additional attributes, the clock attribute and the process-shared attribute. +.Sh BUGS +The +.Fn pthread_condattr_getpshared +and +.Fn pthread_condattr_setpshared +functions are hidden by default since only thread shared attributes +are supported. diff --git a/lib/libpthread/pthread_mutex.3 b/lib/libpthread/pthread_mutex.3 index b6ddcab9363..ddae42c40b7 100644 --- a/lib/libpthread/pthread_mutex.3 +++ b/lib/libpthread/pthread_mutex.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: pthread_mutex.3,v 1.6 2012/11/12 23:11:05 uwe Exp $ +.\" $NetBSD: pthread_mutex.3,v 1.7 2016/07/03 14:24:58 christos Exp $ .\" .\" Copyright (c) 2002, 2010 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -52,7 +52,7 @@ .\" SUCH DAMAGE. .\" .\" ---------------------------------------------------------------------------- -.Dd July 8, 2010 +.Dd June 12, 2016 .Dt PTHREAD_MUTEX 3 .Os .Sh NAME @@ -75,6 +75,14 @@ .Fn pthread_mutex_trylock "pthread_mutex_t *mutex" .Ft int .Fn pthread_mutex_unlock "pthread_mutex_t *mutex" +.Ft int +.Fn pthread_mutex_timedlock "pthread_mutex_t * mutex" "const struct timespec *__restrict timeout" +.Ft int +.Fn pthread_mutex_getprioceiling "const pthread_mutex_t * __restrict mutex" "int * __restrict prioceiling" +.Ft int +.Fn pthread_mutex_setprioceiling "pthread_mutex_t * __restrict mutex" \ +"int prioceiling" "int * __restrict old_ceiling" + .\" ---------------------------------------------------------------------------- .Sh DESCRIPTION The @@ -135,7 +143,45 @@ When operating with the default mutex type, undefined behavior follows if a thread tries to unlock a mutex that has not been locked by it, or if a thread tries to release a mutex that is already unlocked. +.Pp +.\" ----- +The +.Fn pthread_mutex_timedlock +function shall lock the mutex object referenced by +.Fa mutex. +If the mutex is already locked, the calling thread shall block until +the mutex becomes available in the +.Fn pthread_mutex_lock +function. +If the mutex cannot be locked without waiting for another thread to +unlock the mutex, this wait shall be terminated when the specified timeout +expires. +The timeout shall expire when the absolute time specified by +.Fa timeout +passes, as measured by the clock on which timeouts are based. +.Pp +.\" ----- +The +.Fn pthread_mutex_getprioceiling +function shall return the current priority ceiling of the mutex. +.Pp +.\" ----- +The +.Fn pthread_mutex_setprioceiling +function shall either lock the mutex if it is unlocked, or block until +it can sucessfully lock the mutex, then it shall change the mutex's priority +ceiling and release the mutex. +When the change is successful, the previous value of the priority ceiling +shall be returned +in +.Fa old_ceiling. +The process of locking the mutex need not adhere to the priority +protect protocol. +If +.Fn pthread_mutex_setprioceiling +function fails, the mutex priority ceiling shall not be changed. .\" ---------------------------------------------------------------------------- + .Sh RETURN VALUES Upon success all described functions return zero. Otherwise, an error number will be returned to indicate the error. @@ -203,7 +249,45 @@ is invalid. The current thread does not hold a lock on .Fa mutex . .El +.Pp +.\" ----- +.Fn pthread_mutex_timedlock +may fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The mutex was created with the protocol attribute having the value +.Dv PTHREAD_PRIO_PROTECT +and the calling thread's priority is higher than +the mutex current priority ceiling. +.It Bq Er EINVAL +The process or thread would have blocked, and the +.Fa timeout +parameter specified a nanoseconds field value less than zero or greater +than or equal to 1000 million. +.It Bq Er ETIMEDOUT +The mutex could not be locked before the specified timeout expired. +.El +.Pp +.\" ----- +The +.Fn pthread_mutex_getprioceiling +and +.Fn pthread_mutex_setprioceiling +functions may fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The priority requested by +.Fa prioceiling +is out of range. +.It Bq Er EINVAL +The value specified by +.Fa mutex +does not refer to a currently existing mutex. +.It Bq Er EPERM +The caller does not have the privilege to perform the operation. + .\" ---------------------------------------------------------------------------- + .Sh SEE ALSO .Xr pthread 3 , .Xr pthread_barrier 3 , diff --git a/lib/libpthread/pthread_mutex.c b/lib/libpthread/pthread_mutex.c index 2d8eed5f144..d8879eea523 100644 --- a/lib/libpthread/pthread_mutex.c +++ b/lib/libpthread/pthread_mutex.c @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_mutex.c,v 1.59 2014/02/03 15:51:01 rmind Exp $ */ +/* $NetBSD: pthread_mutex.c,v 1.60 2016/07/03 14:24:58 christos Exp $ */ /*- * Copyright (c) 2001, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -47,10 +47,11 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: pthread_mutex.c,v 1.59 2014/02/03 15:51:01 rmind Exp $"); +__RCSID("$NetBSD: pthread_mutex.c,v 1.60 2016/07/03 14:24:58 christos Exp $"); #include <sys/types.h> #include <sys/lwpctl.h> +#include <sys/sched.h> #include <sys/lock.h> #include <errno.h> @@ -67,12 +68,27 @@ __RCSID("$NetBSD: pthread_mutex.c,v 1.59 2014/02/03 15:51:01 rmind Exp $"); #define MUTEX_WAITERS_BIT ((uintptr_t)0x01) #define MUTEX_RECURSIVE_BIT ((uintptr_t)0x02) #define MUTEX_DEFERRED_BIT ((uintptr_t)0x04) -#define MUTEX_THREAD ((uintptr_t)-16L) +#define MUTEX_PROTECT_BIT ((uintptr_t)0x08) +#define MUTEX_THREAD ((uintptr_t)~0x0f) #define MUTEX_HAS_WAITERS(x) ((uintptr_t)(x) & MUTEX_WAITERS_BIT) #define MUTEX_RECURSIVE(x) ((uintptr_t)(x) & MUTEX_RECURSIVE_BIT) +#define MUTEX_PROTECT(x) ((uintptr_t)(x) & MUTEX_PROTECT_BIT) #define MUTEX_OWNER(x) ((uintptr_t)(x) & MUTEX_THREAD) +#define MUTEX_GET_TYPE(x) \ + ((int)(((uintptr_t)(x) & 0x000000ff) >> 0)) +#define MUTEX_SET_TYPE(x, t) \ + (x) = (void *)(((uintptr_t)(x) & ~0x000000ff) | ((t) << 0)) +#define MUTEX_GET_PROTOCOL(x) \ + ((int)(((uintptr_t)(x) & 0x0000ff00) >> 8)) +#define MUTEX_SET_PROTOCOL(x, p) \ + (x) = (void *)(((uintptr_t)(x) & ~0x0000ff00) | ((p) << 8)) +#define MUTEX_GET_CEILING(x) \ + ((int)(((uintptr_t)(x) & 0x00ff0000) >> 16)) +#define MUTEX_SET_CEILING(x, c) \ + (x) = (void *)(((uintptr_t)(x) & ~0x00ff0000) | ((c) << 16)) + #if __GNUC_PREREQ__(3, 0) #define NOINLINE __attribute ((noinline)) #else @@ -80,7 +96,8 @@ __RCSID("$NetBSD: pthread_mutex.c,v 1.59 2014/02/03 15:51:01 rmind Exp $"); #endif static void pthread__mutex_wakeup(pthread_t, pthread_mutex_t *); -static int pthread__mutex_lock_slow(pthread_mutex_t *); +static int pthread__mutex_lock_slow(pthread_mutex_t *, + const struct timespec *); static int pthread__mutex_unlock_slow(pthread_mutex_t *); static void pthread__mutex_pause(void); @@ -103,16 +120,22 @@ __strong_alias(__libc_mutexattr_settype,pthread_mutexattr_settype) int pthread_mutex_init(pthread_mutex_t *ptm, const pthread_mutexattr_t *attr) { - intptr_t type; + uintptr_t type, proto, val, ceil; if (__predict_false(__uselibcstub)) return __libc_mutex_init_stub(ptm, attr); - if (attr == NULL) + if (attr == NULL) { type = PTHREAD_MUTEX_NORMAL; - else - type = (intptr_t)attr->ptma_private; + proto = PTHREAD_PRIO_NONE; + ceil = 0; + } else { + val = (uintptr_t)attr->ptma_private; + type = MUTEX_GET_TYPE(val); + proto = MUTEX_GET_PROTOCOL(val); + ceil = MUTEX_GET_CEILING(val); + } switch (type) { case PTHREAD_MUTEX_ERRORCHECK: __cpu_simple_lock_set(&ptm->ptm_errorcheck); @@ -127,10 +150,18 @@ pthread_mutex_init(pthread_mutex_t *ptm, const pthread_mutexattr_t *attr) ptm->ptm_owner = NULL; break; } + switch (proto) { + case PTHREAD_PRIO_PROTECT: + val = (uintptr_t)ptm->ptm_owner; + val |= MUTEX_PROTECT_BIT; + ptm->ptm_owner = (void *)val; + break; + } ptm->ptm_magic = _PT_MUTEX_MAGIC; ptm->ptm_waiters = NULL; ptm->ptm_recursed = 0; + ptm->ptm_ceiling = (unsigned char)ceil; return 0; } @@ -168,7 +199,24 @@ pthread_mutex_lock(pthread_mutex_t *ptm) #endif return 0; } - return pthread__mutex_lock_slow(ptm); + return pthread__mutex_lock_slow(ptm, NULL); +} + +int +pthread_mutex_timedlock(pthread_mutex_t* ptm, const struct timespec *ts) +{ + pthread_t self; + void *val; + + self = pthread__self(); + val = atomic_cas_ptr(&ptm->ptm_owner, NULL, self); + if (__predict_true(val == NULL)) { +#ifndef PTHREAD__ATOMIC_IS_MEMBAR + membar_enter(); +#endif + return 0; + } + return pthread__mutex_lock_slow(ptm, ts); } /* We want function call overhead. */ @@ -258,11 +306,12 @@ again: } NOINLINE static int -pthread__mutex_lock_slow(pthread_mutex_t *ptm) +pthread__mutex_lock_slow(pthread_mutex_t *ptm, const struct timespec *ts) { void *waiters, *new, *owner, *next; pthread_t self; int serrno; + int error; pthread__error(EINVAL, "Invalid mutex", ptm->ptm_magic == _PT_MUTEX_MAGIC); @@ -282,6 +331,10 @@ pthread__mutex_lock_slow(pthread_mutex_t *ptm) return EDEADLK; } + /* priority protect */ + if (MUTEX_PROTECT(owner) && _sched_protect(ptm->ptm_ceiling) == -1) { + return errno; + } serrno = errno; for (;; owner = ptm->ptm_owner) { /* Spin while the owner is running. */ @@ -339,12 +392,23 @@ pthread__mutex_lock_slow(pthread_mutex_t *ptm) */ while (self->pt_mutexwait) { self->pt_blocking++; - (void)_lwp_park(CLOCK_REALTIME, TIMER_ABSTIME, NULL, + error = _lwp_park(CLOCK_REALTIME, TIMER_ABSTIME, ts, self->pt_unpark, __UNVOLATILE(&ptm->ptm_waiters), __UNVOLATILE(&ptm->ptm_waiters)); self->pt_unpark = 0; self->pt_blocking--; membar_sync(); + if (__predict_true(error != -1)) { + continue; + } + if (errno == ETIMEDOUT && self->pt_mutexwait) { + /*Remove self from waiters list*/ + pthread__mutex_wakeup(self, ptm); + /*priority protect*/ + if (MUTEX_PROTECT(owner)) + (void)_sched_protect(-1); + return ETIMEDOUT; + } } } } @@ -460,6 +524,10 @@ pthread__mutex_unlock_slow(pthread_mutex_t *ptm) */ if (new != owner) { owner = atomic_swap_ptr(&ptm->ptm_owner, new); + if (__predict_false(MUTEX_PROTECT(owner))) { + /* restore elevated priority */ + (void)_sched_protect(-1); + } if (MUTEX_HAS_WAITERS(owner) != 0) { pthread__mutex_wakeup(self, ptm); return 0; @@ -591,16 +659,18 @@ pthread_mutexattr_destroy(pthread_mutexattr_t *attr) int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *typep) { + pthread__error(EINVAL, "Invalid mutex attribute", attr->ptma_magic == _PT_MUTEXATTR_MAGIC); - *typep = (int)(intptr_t)attr->ptma_private; + *typep = MUTEX_GET_TYPE(attr->ptma_private); return 0; } int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) { + if (__predict_false(__uselibcstub)) return __libc_mutexattr_settype_stub(attr, type); @@ -611,13 +681,92 @@ pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) case PTHREAD_MUTEX_NORMAL: case PTHREAD_MUTEX_ERRORCHECK: case PTHREAD_MUTEX_RECURSIVE: - attr->ptma_private = (void *)(intptr_t)type; + MUTEX_SET_TYPE(attr->ptma_private, type); return 0; default: return EINVAL; } } +int +pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr, int*proto) +{ + + pthread__error(EINVAL, "Invalid mutex attribute", + attr->ptma_magic == _PT_MUTEXATTR_MAGIC); + + *proto = MUTEX_GET_PROTOCOL(attr->ptma_private); + return 0; +} + +int +pthread_mutexattr_setprotocol(pthread_mutexattr_t* attr, int proto) +{ + + pthread__error(EINVAL, "Invalid mutex attribute", + attr->ptma_magic == _PT_MUTEXATTR_MAGIC); + + switch (proto) { + case PTHREAD_PRIO_NONE: + case PTHREAD_PRIO_PROTECT: + MUTEX_SET_PROTOCOL(attr->ptma_private, proto); + return 0; + case PTHREAD_PRIO_INHERIT: + return ENOTSUP; + default: + return EINVAL; + } +} + +int +pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *attr, int *ceil) +{ + + pthread__error(EINVAL, "Invalid mutex attribute", + attr->ptma_magic == _PT_MUTEXATTR_MAGIC); + + *ceil = MUTEX_GET_CEILING(attr->ptma_private); + return 0; +} + +int +pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr, int ceil) +{ + + pthread__error(EINVAL, "Invalid mutex attribute", + attr->ptma_magic == _PT_MUTEXATTR_MAGIC); + + if (ceil & ~0xff) + return EINVAL; + + MUTEX_SET_CEILING(attr->ptma_private, ceil); + return 0; +} + +#ifdef _PTHREAD_PSHARED +int +pthread_mutexattr_getpshared(const pthread_mutexattr_t * __restrict attr, + int * __restrict pshared) +{ + + *pshared = PTHREAD_PROCESS_PRIVATE; + return 0; +} + +int +pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared) +{ + + switch(pshared) { + case PTHREAD_PROCESS_PRIVATE: + return 0; + case PTHREAD_PROCESS_SHARED: + return ENOSYS; + } + return EINVAL; +} +#endif + /* * pthread__mutex_deferwake: try to defer unparking threads in self->pt_waiters * @@ -645,6 +794,28 @@ pthread__mutex_deferwake(pthread_t self, pthread_mutex_t *ptm) } int +pthread_mutex_getprioceiling(const pthread_mutex_t *ptm, int*ceil) +{ + *ceil = (unsigned int)ptm->ptm_ceiling; + return 0; +} + +int +pthread_mutex_setprioceiling(pthread_mutex_t *ptm, int ceil, int *old_ceil) +{ + int error; + + error = pthread_mutex_lock(ptm); + if (error == 0) { + *old_ceil = (unsigned int)ptm->ptm_ceiling; + /*check range*/ + ptm->ptm_ceiling = (unsigned char)ceil; + pthread_mutex_unlock(ptm); + } + return error; +} + +int _pthread_mutex_held_np(pthread_mutex_t *ptm) { diff --git a/lib/libpthread/pthread_mutexattr.3 b/lib/libpthread/pthread_mutexattr.3 index 5a20787b736..49fbf1b165c 100644 --- a/lib/libpthread/pthread_mutexattr.3 +++ b/lib/libpthread/pthread_mutexattr.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: pthread_mutexattr.3,v 1.11 2010/07/08 22:46:34 jruoho Exp $ +.\" $NetBSD: pthread_mutexattr.3,v 1.12 2016/07/03 14:24:58 christos Exp $ .\" .\" Copyright (c) 2002, 2010 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -50,18 +50,20 @@ .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" $FreeBSD: src/lib/libpthread/man/pthread_mutexattr.3,v 1.8 2002/09/16 19:29:29 mini Exp $ -.Dd July 9, 2010 +.Dd June 12, 2016 .Dt PTHREAD_MUTEXATTR 3 .Os .Sh NAME .Nm pthread_mutexattr_init , .Nm pthread_mutexattr_destroy , -.\" .Nm pthread_mutexattr_setprioceiling , -.\" .Nm pthread_mutexattr_getprioceiling , -.\" .Nm pthread_mutexattr_setprotocol , -.\" .Nm pthread_mutexattr_getprotocol , +.Nm pthread_mutexattr_setprioceiling , +.Nm pthread_mutexattr_getprioceiling , +.Nm pthread_mutexattr_setprotocol , +.Nm pthread_mutexattr_getprotocol , .Nm pthread_mutexattr_settype , -.Nm pthread_mutexattr_gettype +.Nm pthread_mutexattr_gettype , +.Nm pthread_mutexattr_getpshared , +.Nm pthread_mutexattr_setpshared .Nd mutex attribute operations .Sh LIBRARY .Lb libpthread @@ -71,23 +73,29 @@ .Fn pthread_mutexattr_init "pthread_mutexattr_t *attr" .Ft int .Fn pthread_mutexattr_destroy "pthread_mutexattr_t *attr" -.\" .Ft int -.\" .Fn pthread_mutexattr_setprioceiling \ -.\" "pthread_mutexattr_t *attr" "int prioceiling" -.\" .Ft int -.\" .Fn pthread_mutexattr_getprioceiling \ -.\" "pthread_mutexattr_t *attr" "int *prioceiling" -.\" .Ft int -.\" .Fn pthread_mutexattr_setprotocol \ -.\" "pthread_mutexattr_t *attr" "int protocol" -.\" .Ft int -.\" .Fn pthread_mutexattr_getprotocol \ -.\" "pthread_mutexattr_t *attr" "int *protocol" +.Ft int +.Fn pthread_mutexattr_setprioceiling \ +"pthread_mutexattr_t *attr" "int prioceiling" +.Ft int +.Fn pthread_mutexattr_getprioceiling \ +"pthread_mutexattr_t *attr" "int *prioceiling" +.Ft int +.Fn pthread_mutexattr_setprotocol \ +"pthread_mutexattr_t *attr" "int protocol" +.Ft int +.Fn pthread_mutexattr_getprotocol \ +"pthread_mutexattr_t *attr" "int *protocol" .Ft int .Fn pthread_mutexattr_settype "pthread_mutexattr_t *attr" "int type" .Ft int .Fn pthread_mutexattr_gettype \ "pthread_mutexattr_t * restrict attr" "int * restrict type" +.Ft int +.Fn pthread_mutexattr_getpshared \ +"const pthread_mutexattr_t * __restrict attr" "int * __restrict pshared" +.Ft int +.Fn pthread_mutexattr_setpshared \ +"pthread_mutexattr_t * attr" "int pshared" .Sh DESCRIPTION Mutex attributes are used to specify parameters to .Fn pthread_mutex_init . @@ -172,6 +180,38 @@ The .Fn pthread_mutexattr_gettype functions copy the type value of the attribute to the location pointed to by the second parameter. +.Pp +The +.Fn pthread_mutexattr_getpshared +function obtains the value of the process-shared attribute from +the attributes object referenced by +.Fa attr. +.Pp +The +.Fn pthread_mutexattr_setpshared +function is used to set the process-shared attribute in an initialised +attributes object referenced by +.Fa attr. +.Pp +The +.Fn pthread_mutexattr_getprotocol +and +.Fn pthread_mutexattr_setprotocol +functions shall get and set the protocol attribute of a mutex attributes +object pointed to by +.Fa attr +which was previously created by the function +.Fn pthread_mutexattr_init . +.Pp +The +.Fn pthread_mutexattr_getprioceiling +and +.Fn pthread_mutexattr_setprioceiling +functions, shall get and set the priority ceiling attribute of a mutex attributes +object pointed to by +.Fa attr +which was previously created by the function +.Fn pthread_mutexattr_init . .Sh RETURN VALUES If successful, these functions return 0. Otherwise, an error number is returned to indicate the error. @@ -201,46 +241,63 @@ No error numbers are defined for the and .Fn pthread_mutexattr_gettype functions. -.\" -.\" .Pp -.\" .Fn pthread_mutexattr_setprioceiling -.\" may fail if: -.\" .Bl -tag -width Er -.\" .It Bq Er EINVAL -.\" Invalid value for -.\" .Fa attr , -.\" or invalid value for -.\" .Fa prioceiling . -.\" .El -.\" .Pp -.\" .Fn pthread_mutexattr_getprioceiling -.\" may fail if: -.\" .Bl -tag -width Er -.\" .It Bq Er EINVAL -.\" Invalid value for -.\" .Fa attr . -.\" .El -.\" .Pp -.\" .Fn pthread_mutexattr_setprotocol -.\" may fail if: -.\" .Bl -tag -width Er -.\" .It Bq Er EINVAL -.\" Invalid value for -.\" .Fa attr , -.\" or invalid value for -.\" .Fa protocol . -.\" .El -.\" .Pp -.\" .Fn pthread_mutexattr_getprotocol -.\" may fail if: -.\" .Bl -tag -width Er -.\" .It Bq Er EINVAL -.\" Invalid value for -.\" .Fa attr . -.\" .El -.\" .Pp +.Pp +.Fn pthread_mutexattr_setprioceiling +may fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +Invalid value for +.Fa attr , +or invalid value for +.Fa prioceiling . +.El +.Pp +.Fn pthread_mutexattr_getprioceiling +may fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +Invalid value for +.Fa attr . +.El +.Pp +.Fn pthread_mutexattr_setprotocol +may fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +Invalid value for +.Fa attr , +or invalid value for +.Fa protocol . +.El +.Pp +.Fn pthread_mutexattr_getprotocol +may fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +Invalid value for +.Fa attr . +.El +.Pp +.El +.Pp +.Fn pthread_mutexattr_getpshared +and +.Fn pthread_mutexattr_setpshared +may fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +the value specified by +.Fa attr +is invalid. .Sh SEE ALSO .Xr pthread_mutex_init 3 .Sh STANDARDS These functions conform to .St -p1003.1-2001 . +.Sh BUGS +The +.Fn pthread_mutexattr_getpshared +and +.Fn pthread_mutexattr_setpshared +functions are hidden by default since only thread shared attributes +are supported. diff --git a/lib/libpthread/pthread_rwlock.c b/lib/libpthread/pthread_rwlock.c index e5712abaa8a..d1acf1b10ae 100644 --- a/lib/libpthread/pthread_rwlock.c +++ b/lib/libpthread/pthread_rwlock.c @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_rwlock.c,v 1.33 2013/03/21 16:49:12 christos Exp $ */ +/* $NetBSD: pthread_rwlock.c,v 1.34 2016/07/03 14:24:58 christos Exp $ */ /*- * Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: pthread_rwlock.c,v 1.33 2013/03/21 16:49:12 christos Exp $"); +__RCSID("$NetBSD: pthread_rwlock.c,v 1.34 2016/07/03 14:24:58 christos Exp $"); #include <sys/types.h> #include <sys/lwpctl.h> @@ -639,6 +639,29 @@ _pthread_rwlock_wrheld_np(pthread_rwlock_t *ptr) ((uintptr_t)pthread__self() | RW_WRITE_LOCKED); } +#ifdef _PTHREAD_PSHARED +int +pthread_rwlockattr_getpshared(const pthread_rwlockattr_t * __restrict attr, + int * __restrict pshared) +{ + *pshared = PTHREAD_PROCESS_PRIVATE; + return 0; +} + +int +pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared) +{ + + switch(pshared) { + case PTHREAD_PROCESS_PRIVATE: + return 0; + case PTHREAD_PROCESS_SHARED: + return ENOSYS; + } + return EINVAL; +} +#endif + int pthread_rwlockattr_init(pthread_rwlockattr_t *attr) { diff --git a/lib/libpthread/pthread_rwlockattr.3 b/lib/libpthread/pthread_rwlockattr.3 index 78ab06e8622..06fdc6b3918 100644 --- a/lib/libpthread/pthread_rwlockattr.3 +++ b/lib/libpthread/pthread_rwlockattr.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: pthread_rwlockattr.3,v 1.8 2010/07/09 08:51:28 jruoho Exp $ +.\" $NetBSD: pthread_rwlockattr.3,v 1.9 2016/07/03 14:24:58 christos Exp $ .\" .\" Copyright (c) 2002 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -48,13 +48,15 @@ .\" .\" $FreeBSD: src/lib/libpthread/man/pthread_rwlockattr_init.3,v 1.7 2002/09/16 19:29:29 mini Exp $ .\" -.Dd July 9, 2010 +.Dd June 12, 2016 .Dt PTHREAD_RWLOCKATTR 3 .Os .Sh NAME .Nm pthread_rwlockattr_init , -.Nm pthread_rwlockattr_destroy -.Nd initialize or destroy read/write lock attributes +.Nm pthread_rwlockattr_destroy , +.Nm pthread_rwlockattr_getpshared , +.Nm pthread_rwlockattr_setpshared +.Nd initialize, destroy or query read/write lock attributes .Sh LIBRARY .Lb libpthread .Sh SYNOPSIS @@ -63,6 +65,10 @@ .Fn pthread_rwlockattr_init "pthread_rwlockattr_t *attr" .Ft int .Fn pthread_rwlockattr_destroy "pthread_rwlockattr_t *attr" +.Ft int +.Fn pthread_rwlockattr_getpshared "const pthread_rwlockattr_t *__restrict attr" "int * __restrict pshared" +.Ft int +.Fn pthread_rwlockattr_setpshared "pthread_rwlockattr_t *attr" "int pshared" .Sh DESCRIPTION The .Fn pthread_rwlockattr_init @@ -73,12 +79,21 @@ The function is used to destroy a read/write lock attribute object previously created with .Fn pthread_rwlockattr_init . +.Pp +The +.Fn pthread_rwlockattr_getpshared +function shall obtain the value of process-shared attribute from +the initialized attributes object referenced by +.Fa attr. +.Pp +The +.Fn pthread_rwlockattr_setpshared +function shall set the process-shared attribute in an initialized +attributes object referenced by +.Fa attr. .Sh RETURN VALUES -If successful, the -.Fn pthread_rwlockattr_init -and -.Fn pthread_rwlockattr_destroy -functions return zero. +If successful, +all these functions return zero. Otherwise an error number will be returned to indicate the error. .Sh ERRORS .Fn pthread_rwlockattr_init @@ -98,8 +113,26 @@ The value specified by .Fa attr is invalid. .El +.Pp +.Fn pthread_rwlockattr_getpshared +and +.Fn pthread_rwlockattr_setpshared +may fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value specified by +.Fa attr +is invalid. +.El .Sh SEE ALSO .Xr pthread_rwlock_init 3 .Sh STANDARDS Both functions conform to .St -p1003.1-2001 . +.Sh BUGS +The +.Fn pthread_rwlockattr_getpshared +and +.Fn pthread_rwlockattr_setpshared +functions are hidden by default since only thread shared attributes +are supported. diff --git a/lib/libpthread/pthread_types.h b/lib/libpthread/pthread_types.h index a25be8effc9..c72d41b124c 100644 --- a/lib/libpthread/pthread_types.h +++ b/lib/libpthread/pthread_types.h @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_types.h,v 1.17 2015/08/27 12:30:50 pooka Exp $ */ +/* $NetBSD: pthread_types.h,v 1.18 2016/07/03 14:24:58 christos Exp $ */ /*- * Copyright (c) 2001, 2008 The NetBSD Foundation, Inc. @@ -115,7 +115,7 @@ struct __pthread_mutex_st { #ifdef __CPU_SIMPLE_LOCK_PAD uint8_t ptm_pad1[3]; #endif - __pthread_spin_t ptm_interlock; /* unused - backwards compat */ + __pthread_spin_t ptm_ceiling; #ifdef __CPU_SIMPLE_LOCK_PAD uint8_t ptm_pad2[3]; #endif |
