diff options
Diffstat (limited to 'nptl/pthread_mutex_init.c')
-rw-r--r-- | nptl/pthread_mutex_init.c | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/nptl/pthread_mutex_init.c b/nptl/pthread_mutex_init.c index c25e4035e5..6ffa30d5c0 100644 --- a/nptl/pthread_mutex_init.c +++ b/nptl/pthread_mutex_init.c @@ -41,11 +41,25 @@ __pthread_mutex_init (mutex, mutexattr) imutexattr = (const struct pthread_mutexattr *) mutexattr ?: &default_attr; /* Sanity checks. */ - // 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; + // XXX For now we don't support priority protected mutexes. + switch (__builtin_expect (imutexattr->mutexkind + & PTHREAD_MUTEXATTR_PROTOCOL_MASK, + PTHREAD_PRIO_NONE + << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT)) + { + case PTHREAD_PRIO_NONE << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT: + break; + + case PTHREAD_PRIO_INHERIT << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT: +#ifndef __ASSUME_SET_ROBUST_LIST + if (__set_robust_list_avail < 0) + return ENOTSUP; +#endif + break; + + default: + return ENOTSUP; + } /* Clear the whole variable. */ memset (mutex, '\0', __SIZEOF_PTHREAD_MUTEX_T); @@ -64,14 +78,14 @@ __pthread_mutex_init (mutex, mutexattr) mutex->__data.__kind |= PTHREAD_MUTEX_ROBUST_NORMAL_NP; } - switch ((imutexattr->mutexkind & PTHREAD_MUTEXATTR_PROTOCOL_MASK) - >> PTHREAD_MUTEXATTR_PROTOCOL_SHIFT) + switch (imutexattr->mutexkind & PTHREAD_MUTEXATTR_PROTOCOL_MASK) { - case PTHREAD_PRIO_INHERIT: - mutex->__data.__kind |= PTHREAD_MUTEX_PRIO_INHERIT_PRIVATE_NP; + case PTHREAD_PRIO_INHERIT << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT: + mutex->__data.__kind |= PTHREAD_MUTEX_PRIO_INHERIT_NP; break; - case PTHREAD_PRIO_PROTECT: - mutex->__data.__kind |= PTHREAD_MUTEX_PRIO_PROTECT_PRIVATE_NP; + + case PTHREAD_PRIO_PROTECT << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT: + mutex->__data.__kind |= PTHREAD_MUTEX_PRIO_PROTECT_NP; if (PTHREAD_MUTEX_PRIO_CEILING_MASK == PTHREAD_MUTEXATTR_PRIO_CEILING_MASK) mutex->__data.__kind |= (imutexattr->mutexkind @@ -82,6 +96,7 @@ __pthread_mutex_init (mutex, mutexattr) >> PTHREAD_MUTEXATTR_PRIO_CEILING_SHIFT) << PTHREAD_MUTEX_PRIO_CEILING_SHIFT; break; + default: break; } |