o Style
o Instead of checking both the passed in pointer and its value for NULL, only check the latter. Any caller that passes in a NULL pointer is obviously wrong.
This commit is contained in:
parent
5af0285e8f
commit
8330d43435
@ -47,9 +47,7 @@ _pthread_mutexattr_getprioceiling(pthread_mutexattr_t *mattr, int *prioceiling)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if ((mattr == NULL) || (*mattr == NULL))
|
||||
ret = EINVAL;
|
||||
else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT)
|
||||
if (*mattr == NULL)
|
||||
ret = EINVAL;
|
||||
else
|
||||
*prioceiling = (*mattr)->m_ceiling;
|
||||
@ -62,12 +60,13 @@ _pthread_mutexattr_setprioceiling(pthread_mutexattr_t *mattr, int prioceiling)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if ((mattr == NULL) || (*mattr == NULL))
|
||||
if (*mattr == NULL)
|
||||
ret = EINVAL;
|
||||
else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT)
|
||||
ret = EINVAL;
|
||||
else
|
||||
else if (prioceiling <= PTHREAD_MAX_PRIORITY &&
|
||||
prioceiling >= PTHREAD_MIN_PRIORITY)
|
||||
(*mattr)->m_ceiling = prioceiling;
|
||||
else
|
||||
ret = EINVAL;
|
||||
|
||||
return (ret);
|
||||
}
|
||||
@ -76,16 +75,11 @@ int
|
||||
_pthread_mutex_getprioceiling(pthread_mutex_t *mutex,
|
||||
int *prioceiling)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((mutex == NULL) || (*mutex == NULL))
|
||||
ret = EINVAL;
|
||||
else if ((*mutex)->m_protocol != PTHREAD_PRIO_PROTECT)
|
||||
ret = EINVAL;
|
||||
if (*mutex == NULL)
|
||||
return (EINVAL);
|
||||
else
|
||||
ret = (*mutex)->m_prio;
|
||||
|
||||
return (ret);
|
||||
*prioceiling = (*mutex)->m_prio;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
@ -94,20 +88,26 @@ _pthread_mutex_setprioceiling(pthread_mutex_t *mutex,
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if ((mutex == NULL) || (*mutex == NULL))
|
||||
ret = EINVAL;
|
||||
else if ((*mutex)->m_protocol != PTHREAD_PRIO_PROTECT)
|
||||
ret = EINVAL;
|
||||
else {
|
||||
/* Lock the mutex: */
|
||||
if ((ret = pthread_mutex_lock(mutex)) == 0) {
|
||||
/* Return the old ceiling and set the new ceiling: */
|
||||
*old_ceiling = (*mutex)->m_prio;
|
||||
(*mutex)->m_prio = prioceiling;
|
||||
if (*mutex == NULL)
|
||||
return (EINVAL);
|
||||
else if (prioceiling > PTHREAD_MAX_PRIORITY ||
|
||||
prioceiling < PTHREAD_MIN_PRIORITY)
|
||||
return (EINVAL);
|
||||
|
||||
/* Unlock the mutex: */
|
||||
ret = pthread_mutex_unlock(mutex);
|
||||
}
|
||||
/*
|
||||
* Because of the use of pthread_mutex_unlock(), the
|
||||
* priority ceiling of a mutex cannot be changed
|
||||
* while the mutex is held by another thread. It also,
|
||||
* means that the the thread trying to change the
|
||||
* priority ceiling must adhere to prio protection rules.
|
||||
*/
|
||||
if ((ret = pthread_mutex_lock(mutex)) == 0) {
|
||||
/* Return the old ceiling and set the new ceiling: */
|
||||
*old_ceiling = (*mutex)->m_prio;
|
||||
(*mutex)->m_prio = prioceiling;
|
||||
|
||||
/* Unlock the mutex: */
|
||||
ret = pthread_mutex_unlock(mutex);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
@ -43,28 +43,19 @@ __weak_reference(_pthread_mutexattr_setprotocol, pthread_mutexattr_setprotocol);
|
||||
int
|
||||
_pthread_mutexattr_getprotocol(pthread_mutexattr_t *mattr, int *protocol)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if ((mattr == NULL) || (*mattr == NULL))
|
||||
ret = EINVAL;
|
||||
else
|
||||
*protocol = (*mattr)->m_protocol;
|
||||
|
||||
return(ret);
|
||||
if (*mattr == NULL)
|
||||
return (EINVAL);
|
||||
*protocol = (*mattr)->m_protocol;
|
||||
return(0);
|
||||
}
|
||||
|
||||
int
|
||||
_pthread_mutexattr_setprotocol(pthread_mutexattr_t *mattr, int protocol)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if ((mattr == NULL) || (*mattr == NULL) ||
|
||||
(protocol < PTHREAD_PRIO_NONE) || (protocol > PTHREAD_PRIO_PROTECT))
|
||||
ret = EINVAL;
|
||||
else {
|
||||
(*mattr)->m_protocol = protocol;
|
||||
(*mattr)->m_ceiling = PTHREAD_MAX_PRIORITY;
|
||||
}
|
||||
return(ret);
|
||||
if (*mattr == NULL || protocol < PTHREAD_PRIO_NONE ||
|
||||
protocol > PTHREAD_PRIO_PROTECT)
|
||||
return (EINVAL);
|
||||
(*mattr)->m_protocol = protocol;
|
||||
(*mattr)->m_ceiling = PTHREAD_MAX_PRIORITY;
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user