mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-29 11:41:21 +03:00
* pthread_mutex_lock.c (__pthread_mutex_lock): Handle only the
fast path here, for robust/PI/PP mutexes call __pthread_mutex_lock_full. Don't use switch, instead use a series of ifs according to their probability. (__pthread_mutex_lock_full): New function. * pthread_mutex_unlock.c: Include assert.h. (__pthread_mutex_unlock_usercnt): Handle only the fast path here, for robust/PI/PP mutexes call __pthread_mutex_unlock_full. Don't use switch, instead use a series of ifs according to their probability. (__pthread_mutex_unlock_full): New function. * sysdeps/unix/sysv/linux/pthread_mutex_cond_lock.c (__pthread_mutex_lock_full): Define.
This commit is contained in:
@ -17,11 +17,16 @@
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include "pthreadP.h"
|
||||
#include <lowlevellock.h>
|
||||
|
||||
static int
|
||||
internal_function
|
||||
__pthread_mutex_unlock_full (pthread_mutex_t *mutex, int decr)
|
||||
__attribute_noinline__;
|
||||
|
||||
int
|
||||
internal_function attribute_hidden
|
||||
@ -29,30 +34,13 @@ __pthread_mutex_unlock_usercnt (mutex, decr)
|
||||
pthread_mutex_t *mutex;
|
||||
int decr;
|
||||
{
|
||||
int newowner = 0;
|
||||
int type = PTHREAD_MUTEX_TYPE (mutex);
|
||||
if (__builtin_expect (type & ~PTHREAD_MUTEX_KIND_MASK_NP, 0))
|
||||
return __pthread_mutex_unlock_full (mutex, decr);
|
||||
|
||||
switch (__builtin_expect (PTHREAD_MUTEX_TYPE (mutex),
|
||||
PTHREAD_MUTEX_TIMED_NP))
|
||||
if (__builtin_expect (type, PTHREAD_MUTEX_TIMED_NP)
|
||||
== PTHREAD_MUTEX_TIMED_NP)
|
||||
{
|
||||
case PTHREAD_MUTEX_RECURSIVE_NP:
|
||||
/* Recursive mutex. */
|
||||
if (mutex->__data.__owner != THREAD_GETMEM (THREAD_SELF, tid))
|
||||
return EPERM;
|
||||
|
||||
if (--mutex->__data.__count != 0)
|
||||
/* We still hold the mutex. */
|
||||
return 0;
|
||||
goto normal;
|
||||
|
||||
case PTHREAD_MUTEX_ERRORCHECK_NP:
|
||||
/* Error checking mutex. */
|
||||
if (mutex->__data.__owner != THREAD_GETMEM (THREAD_SELF, tid)
|
||||
|| ! lll_islocked (mutex->__data.__lock))
|
||||
return EPERM;
|
||||
/* FALLTHROUGH */
|
||||
|
||||
case PTHREAD_MUTEX_TIMED_NP:
|
||||
case PTHREAD_MUTEX_ADAPTIVE_NP:
|
||||
/* Always reset the owner field. */
|
||||
normal:
|
||||
mutex->__data.__owner = 0;
|
||||
@ -62,8 +50,41 @@ __pthread_mutex_unlock_usercnt (mutex, decr)
|
||||
|
||||
/* Unlock. */
|
||||
lll_unlock (mutex->__data.__lock, PTHREAD_MUTEX_PSHARED (mutex));
|
||||
break;
|
||||
return 0;
|
||||
}
|
||||
else if (__builtin_expect (type == PTHREAD_MUTEX_RECURSIVE_NP, 1))
|
||||
{
|
||||
/* Recursive mutex. */
|
||||
if (mutex->__data.__owner != THREAD_GETMEM (THREAD_SELF, tid))
|
||||
return EPERM;
|
||||
|
||||
if (--mutex->__data.__count != 0)
|
||||
/* We still hold the mutex. */
|
||||
return 0;
|
||||
goto normal;
|
||||
}
|
||||
else if (__builtin_expect (type == PTHREAD_MUTEX_ADAPTIVE_NP, 1))
|
||||
goto normal;
|
||||
else
|
||||
{
|
||||
/* Error checking mutex. */
|
||||
assert (type == PTHREAD_MUTEX_ERRORCHECK_NP);
|
||||
if (mutex->__data.__owner != THREAD_GETMEM (THREAD_SELF, tid)
|
||||
|| ! lll_islocked (mutex->__data.__lock))
|
||||
return EPERM;
|
||||
goto normal;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
internal_function
|
||||
__pthread_mutex_unlock_full (pthread_mutex_t *mutex, int decr)
|
||||
{
|
||||
int newowner = 0;
|
||||
|
||||
switch (PTHREAD_MUTEX_TYPE (mutex))
|
||||
{
|
||||
case PTHREAD_MUTEX_ROBUST_RECURSIVE_NP:
|
||||
/* Recursive mutex. */
|
||||
if ((mutex->__data.__lock & FUTEX_TID_MASK)
|
||||
|
Reference in New Issue
Block a user