Modify the return values to comply with POSIX. Previously these

functions would return -1 and set errno to indicate the specific error.
POSIX requires that the functions return the error code as the return
value of the function instead.
This commit is contained in:
Alexander Langer 1997-11-25 01:29:16 +00:00
parent 3234f7c1cc
commit 09bb0da60c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=31402
27 changed files with 114 additions and 231 deletions

View File

@ -44,8 +44,7 @@ pthread_cond_init(pthread_cond_t * cond, const pthread_condattr_t * cond_attr)
int rval = 0;
if (cond == NULL) {
errno = EINVAL;
rval = -1;
rval = EINVAL;
} else {
/*
* Check if a pointer to a condition variable attribute
@ -69,8 +68,7 @@ pthread_cond_init(pthread_cond_t * cond, const pthread_condattr_t * cond_attr)
/* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
rval = -1;
rval = EINVAL;
break;
}
@ -78,8 +76,7 @@ pthread_cond_init(pthread_cond_t * cond, const pthread_condattr_t * cond_attr)
if (rval == 0) {
if ((pcond = (pthread_cond_t)
malloc(sizeof(struct pthread_cond))) == NULL) {
errno = ENOMEM;
rval = -1;
rval = ENOMEM;
} else {
/*
* Initialise the condition variable
@ -102,8 +99,7 @@ pthread_cond_destroy(pthread_cond_t * cond)
int rval = 0;
if (cond == NULL || *cond == NULL) {
errno = EINVAL;
rval = -1;
rval = EINVAL;
} else {
/* Process according to condition variable type: */
switch ((*cond)->c_type) {
@ -115,8 +111,7 @@ pthread_cond_destroy(pthread_cond_t * cond)
/* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
rval = -1;
rval = EINVAL;
break;
}
@ -140,8 +135,7 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex)
int status;
if (cond == NULL || *cond == NULL) {
errno = EINVAL;
rval = -1;
rval = EINVAL;
} else {
/* Block signals: */
_thread_kern_sig_block(&status);
@ -176,8 +170,7 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex)
/* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
rval = -1;
rval = EINVAL;
break;
}
@ -197,8 +190,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
int status;
if (cond == NULL || *cond == NULL) {
errno = EINVAL;
rval = -1;
rval = EINVAL;
} else {
/* Block signals: */
_thread_kern_sig_block(&status);
@ -242,8 +234,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
/* Check if the wait timed out: */
else if (_thread_run->timeout) {
/* Return a timeout error: */
errno = ETIMEDOUT;
rval = -1;
rval = ETIMEDOUT;
}
}
break;
@ -251,8 +242,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
/* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
rval = -1;
rval = EINVAL;
break;
}
@ -272,8 +262,7 @@ pthread_cond_signal(pthread_cond_t * cond)
pthread_t pthread;
if (cond == NULL || *cond == NULL) {
errno = EINVAL;
rval = -1;
rval = EINVAL;
} else {
/* Block signals: */
_thread_kern_sig_block(&status);
@ -292,8 +281,7 @@ pthread_cond_signal(pthread_cond_t * cond)
/* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
rval = -1;
rval = EINVAL;
break;
}
@ -333,8 +321,7 @@ pthread_cond_broadcast(pthread_cond_t * cond)
/* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
rval = -1;
rval = EINVAL;
break;
}

View File

@ -40,8 +40,7 @@ int pthread_condattr_destroy(pthread_condattr_t *attr)
{
int ret;
if (attr == NULL || *attr == NULL) {
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
free(*attr);
*attr = NULL;

View File

@ -45,8 +45,7 @@ pthread_condattr_init(pthread_condattr_t *attr)
if ((pattr = (pthread_condattr_t)
malloc(sizeof(struct pthread_cond_attr))) == NULL) {
errno = ENOMEM;
ret = -1;
ret = ENOMEM;
} else {
memcpy(pattr, &pthread_condattr_default,
sizeof(struct pthread_cond_attr));

View File

@ -49,8 +49,7 @@ pthread_detach(pthread_t * p_pthread)
/* Check for invalid calling parameters: */
if (p_pthread == NULL || (pthread = *p_pthread) == NULL) {
/* Return an invalid argument error: */
errno = EINVAL;
rval = -1;
rval = EINVAL;
}
/* Check if the thread has not been detached: */
else if ((pthread->attr.flags & PTHREAD_DETACHED) == 0) {
@ -70,8 +69,7 @@ pthread_detach(pthread_t * p_pthread)
*p_pthread = NULL;
} else {
/* Return an error: */
errno = ESRCH;
rval = -1;
rval = ESRCH;
}
/* Unblock signals: */

View File

@ -67,14 +67,12 @@ pthread_join(pthread_t pthread, void **thread_return)
if (pthread1 == NULL) {
/* Return an error: */
errno = ESRCH;
rval = -1;
rval = ESRCH;
/* Check if this thread has been detached: */
} else if ((pthread->attr.flags & PTHREAD_DETACHED) != 0) {
/* Return an error: */
errno = ESRCH;
rval = -1;
rval = ESRCH;
}
/* Check if the thread is not dead: */
else if (pthread->state != PS_DEAD) {
@ -96,8 +94,7 @@ pthread_join(pthread_t pthread, void **thread_return)
}
} else {
/* Return an error: */
errno = ESRCH;
rval = -1;
rval = ESRCH;
}
} else {
/* Check if the return value is required: */

View File

@ -45,8 +45,7 @@ pthread_mutexattr_init(pthread_mutexattr_t *attr)
if ((pattr = (pthread_mutexattr_t)
malloc(sizeof(struct pthread_mutex_attr))) == NULL) {
errno = ENOMEM;
ret = -1;
ret = ENOMEM;
} else {
memcpy(pattr, &pthread_mutexattr_default,
sizeof(struct pthread_mutex_attr));

View File

@ -46,8 +46,7 @@ pthread_mutex_init(pthread_mutex_t * mutex,
int status;
if (mutex == NULL) {
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
/* Check if default mutex attributes: */
if (mutex_attr == NULL || *mutex_attr == NULL) {
@ -55,8 +54,7 @@ pthread_mutex_init(pthread_mutex_t * mutex,
type = MUTEX_TYPE_FAST;
} else if ((*mutex_attr)->m_type >= MUTEX_TYPE_MAX) {
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
/* Use the requested mutex type: */
type = (*mutex_attr)->m_type;
@ -65,8 +63,7 @@ pthread_mutex_init(pthread_mutex_t * mutex,
/* Check no errors so far: */
if (ret == 0) {
if ((pmutex = (pthread_mutex_t) malloc(sizeof(struct pthread_mutex))) == NULL) {
errno = ENOMEM;
ret = -1;
ret = ENOMEM;
} else {
/* Reset the mutex flags: */
pmutex->m_flags = 0;
@ -90,8 +87,7 @@ pthread_mutex_init(pthread_mutex_t * mutex,
/* Trap invalid mutex types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
break;
}
if (ret == 0) {
@ -122,8 +118,7 @@ pthread_mutex_destroy(pthread_mutex_t * mutex)
int status;
if (mutex == NULL || *mutex == NULL) {
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
/* Block signals: */
_thread_kern_sig_block(&status);
@ -144,8 +139,7 @@ pthread_mutex_destroy(pthread_mutex_t * mutex)
/* Trap undefined mutex types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
break;
}
@ -169,8 +163,7 @@ pthread_mutex_trylock(pthread_mutex_t * mutex)
int status;
if (mutex == NULL || *mutex == NULL) {
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
/* Block signals: */
_thread_kern_sig_block(&status);
@ -185,8 +178,7 @@ pthread_mutex_trylock(pthread_mutex_t * mutex)
(*mutex)->m_owner = _thread_run;
} else {
/* Return a busy error: */
errno = EBUSY;
ret = -1;
ret = EBUSY;
}
break;
@ -203,8 +195,7 @@ pthread_mutex_trylock(pthread_mutex_t * mutex)
(*mutex)->m_data.m_count++;
} else {
/* Return a busy error: */
errno = EBUSY;
ret = -1;
ret = EBUSY;
}
} else {
/* Lock the mutex for the running thread: */
@ -215,8 +206,7 @@ pthread_mutex_trylock(pthread_mutex_t * mutex)
/* Trap invalid mutex types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
break;
}
@ -235,8 +225,7 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
int status;
if (mutex == NULL || *mutex == NULL) {
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
/* Block signals: */
_thread_kern_sig_block(&status);
@ -306,8 +295,7 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
/* Trap invalid mutex types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
break;
}
@ -326,8 +314,7 @@ pthread_mutex_unlock(pthread_mutex_t * mutex)
int status;
if (mutex == NULL || *mutex == NULL) {
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
/* Block signals: */
_thread_kern_sig_block(&status);
@ -339,8 +326,7 @@ pthread_mutex_unlock(pthread_mutex_t * mutex)
/* Check if the running thread is not the owner of the mutex: */
if ((*mutex)->m_owner != _thread_run) {
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
}
/*
* Get the next thread from the queue of threads waiting on
@ -357,8 +343,7 @@ pthread_mutex_unlock(pthread_mutex_t * mutex)
/* Check if the running thread is not the owner of the mutex: */
if ((*mutex)->m_owner != _thread_run) {
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
}
/* Check if there are still counts: */
else if ((*mutex)->m_data.m_count) {
@ -378,8 +363,7 @@ pthread_mutex_unlock(pthread_mutex_t * mutex)
/* Trap invalid mutex types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
break;
}

View File

@ -40,8 +40,7 @@ int pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
{
int ret;
if (attr == NULL || *attr == NULL) {
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
free(*attr);
*attr = NULL;

View File

@ -209,7 +209,6 @@ pthread_getspecific(pthread_key_t key)
/* Check for errors: */
if (pthread == NULL) {
/* Return an invalid argument error: */
errno = EINVAL;
data = NULL;
}
/* Check if there is specific data: */

View File

@ -44,8 +44,7 @@ pthread_cond_init(pthread_cond_t * cond, const pthread_condattr_t * cond_attr)
int rval = 0;
if (cond == NULL) {
errno = EINVAL;
rval = -1;
rval = EINVAL;
} else {
/*
* Check if a pointer to a condition variable attribute
@ -69,8 +68,7 @@ pthread_cond_init(pthread_cond_t * cond, const pthread_condattr_t * cond_attr)
/* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
rval = -1;
rval = EINVAL;
break;
}
@ -78,8 +76,7 @@ pthread_cond_init(pthread_cond_t * cond, const pthread_condattr_t * cond_attr)
if (rval == 0) {
if ((pcond = (pthread_cond_t)
malloc(sizeof(struct pthread_cond))) == NULL) {
errno = ENOMEM;
rval = -1;
rval = ENOMEM;
} else {
/*
* Initialise the condition variable
@ -102,8 +99,7 @@ pthread_cond_destroy(pthread_cond_t * cond)
int rval = 0;
if (cond == NULL || *cond == NULL) {
errno = EINVAL;
rval = -1;
rval = EINVAL;
} else {
/* Process according to condition variable type: */
switch ((*cond)->c_type) {
@ -115,8 +111,7 @@ pthread_cond_destroy(pthread_cond_t * cond)
/* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
rval = -1;
rval = EINVAL;
break;
}
@ -140,8 +135,7 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex)
int status;
if (cond == NULL || *cond == NULL) {
errno = EINVAL;
rval = -1;
rval = EINVAL;
} else {
/* Block signals: */
_thread_kern_sig_block(&status);
@ -176,8 +170,7 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex)
/* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
rval = -1;
rval = EINVAL;
break;
}
@ -197,8 +190,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
int status;
if (cond == NULL || *cond == NULL) {
errno = EINVAL;
rval = -1;
rval = EINVAL;
} else {
/* Block signals: */
_thread_kern_sig_block(&status);
@ -242,8 +234,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
/* Check if the wait timed out: */
else if (_thread_run->timeout) {
/* Return a timeout error: */
errno = ETIMEDOUT;
rval = -1;
rval = ETIMEDOUT;
}
}
break;
@ -251,8 +242,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
/* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
rval = -1;
rval = EINVAL;
break;
}
@ -272,8 +262,7 @@ pthread_cond_signal(pthread_cond_t * cond)
pthread_t pthread;
if (cond == NULL || *cond == NULL) {
errno = EINVAL;
rval = -1;
rval = EINVAL;
} else {
/* Block signals: */
_thread_kern_sig_block(&status);
@ -292,8 +281,7 @@ pthread_cond_signal(pthread_cond_t * cond)
/* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
rval = -1;
rval = EINVAL;
break;
}
@ -333,8 +321,7 @@ pthread_cond_broadcast(pthread_cond_t * cond)
/* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
rval = -1;
rval = EINVAL;
break;
}

View File

@ -40,8 +40,7 @@ int pthread_condattr_destroy(pthread_condattr_t *attr)
{
int ret;
if (attr == NULL || *attr == NULL) {
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
free(*attr);
*attr = NULL;

View File

@ -45,8 +45,7 @@ pthread_condattr_init(pthread_condattr_t *attr)
if ((pattr = (pthread_condattr_t)
malloc(sizeof(struct pthread_cond_attr))) == NULL) {
errno = ENOMEM;
ret = -1;
ret = ENOMEM;
} else {
memcpy(pattr, &pthread_condattr_default,
sizeof(struct pthread_cond_attr));

View File

@ -49,8 +49,7 @@ pthread_detach(pthread_t * p_pthread)
/* Check for invalid calling parameters: */
if (p_pthread == NULL || (pthread = *p_pthread) == NULL) {
/* Return an invalid argument error: */
errno = EINVAL;
rval = -1;
rval = EINVAL;
}
/* Check if the thread has not been detached: */
else if ((pthread->attr.flags & PTHREAD_DETACHED) == 0) {
@ -70,8 +69,7 @@ pthread_detach(pthread_t * p_pthread)
*p_pthread = NULL;
} else {
/* Return an error: */
errno = ESRCH;
rval = -1;
rval = ESRCH;
}
/* Unblock signals: */

View File

@ -67,14 +67,12 @@ pthread_join(pthread_t pthread, void **thread_return)
if (pthread1 == NULL) {
/* Return an error: */
errno = ESRCH;
rval = -1;
rval = ESRCH;
/* Check if this thread has been detached: */
} else if ((pthread->attr.flags & PTHREAD_DETACHED) != 0) {
/* Return an error: */
errno = ESRCH;
rval = -1;
rval = ESRCH;
}
/* Check if the thread is not dead: */
else if (pthread->state != PS_DEAD) {
@ -96,8 +94,7 @@ pthread_join(pthread_t pthread, void **thread_return)
}
} else {
/* Return an error: */
errno = ESRCH;
rval = -1;
rval = ESRCH;
}
} else {
/* Check if the return value is required: */

View File

@ -45,8 +45,7 @@ pthread_mutexattr_init(pthread_mutexattr_t *attr)
if ((pattr = (pthread_mutexattr_t)
malloc(sizeof(struct pthread_mutex_attr))) == NULL) {
errno = ENOMEM;
ret = -1;
ret = ENOMEM;
} else {
memcpy(pattr, &pthread_mutexattr_default,
sizeof(struct pthread_mutex_attr));

View File

@ -46,8 +46,7 @@ pthread_mutex_init(pthread_mutex_t * mutex,
int status;
if (mutex == NULL) {
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
/* Check if default mutex attributes: */
if (mutex_attr == NULL || *mutex_attr == NULL) {
@ -55,8 +54,7 @@ pthread_mutex_init(pthread_mutex_t * mutex,
type = MUTEX_TYPE_FAST;
} else if ((*mutex_attr)->m_type >= MUTEX_TYPE_MAX) {
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
/* Use the requested mutex type: */
type = (*mutex_attr)->m_type;
@ -65,8 +63,7 @@ pthread_mutex_init(pthread_mutex_t * mutex,
/* Check no errors so far: */
if (ret == 0) {
if ((pmutex = (pthread_mutex_t) malloc(sizeof(struct pthread_mutex))) == NULL) {
errno = ENOMEM;
ret = -1;
ret = ENOMEM;
} else {
/* Reset the mutex flags: */
pmutex->m_flags = 0;
@ -90,8 +87,7 @@ pthread_mutex_init(pthread_mutex_t * mutex,
/* Trap invalid mutex types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
break;
}
if (ret == 0) {
@ -122,8 +118,7 @@ pthread_mutex_destroy(pthread_mutex_t * mutex)
int status;
if (mutex == NULL || *mutex == NULL) {
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
/* Block signals: */
_thread_kern_sig_block(&status);
@ -144,8 +139,7 @@ pthread_mutex_destroy(pthread_mutex_t * mutex)
/* Trap undefined mutex types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
break;
}
@ -169,8 +163,7 @@ pthread_mutex_trylock(pthread_mutex_t * mutex)
int status;
if (mutex == NULL || *mutex == NULL) {
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
/* Block signals: */
_thread_kern_sig_block(&status);
@ -185,8 +178,7 @@ pthread_mutex_trylock(pthread_mutex_t * mutex)
(*mutex)->m_owner = _thread_run;
} else {
/* Return a busy error: */
errno = EBUSY;
ret = -1;
ret = EBUSY;
}
break;
@ -203,8 +195,7 @@ pthread_mutex_trylock(pthread_mutex_t * mutex)
(*mutex)->m_data.m_count++;
} else {
/* Return a busy error: */
errno = EBUSY;
ret = -1;
ret = EBUSY;
}
} else {
/* Lock the mutex for the running thread: */
@ -215,8 +206,7 @@ pthread_mutex_trylock(pthread_mutex_t * mutex)
/* Trap invalid mutex types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
break;
}
@ -235,8 +225,7 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
int status;
if (mutex == NULL || *mutex == NULL) {
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
/* Block signals: */
_thread_kern_sig_block(&status);
@ -306,8 +295,7 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
/* Trap invalid mutex types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
break;
}
@ -326,8 +314,7 @@ pthread_mutex_unlock(pthread_mutex_t * mutex)
int status;
if (mutex == NULL || *mutex == NULL) {
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
/* Block signals: */
_thread_kern_sig_block(&status);
@ -339,8 +326,7 @@ pthread_mutex_unlock(pthread_mutex_t * mutex)
/* Check if the running thread is not the owner of the mutex: */
if ((*mutex)->m_owner != _thread_run) {
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
}
/*
* Get the next thread from the queue of threads waiting on
@ -357,8 +343,7 @@ pthread_mutex_unlock(pthread_mutex_t * mutex)
/* Check if the running thread is not the owner of the mutex: */
if ((*mutex)->m_owner != _thread_run) {
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
}
/* Check if there are still counts: */
else if ((*mutex)->m_data.m_count) {
@ -378,8 +363,7 @@ pthread_mutex_unlock(pthread_mutex_t * mutex)
/* Trap invalid mutex types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
break;
}

View File

@ -40,8 +40,7 @@ int pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
{
int ret;
if (attr == NULL || *attr == NULL) {
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
free(*attr);
*attr = NULL;

View File

@ -209,7 +209,6 @@ pthread_getspecific(pthread_key_t key)
/* Check for errors: */
if (pthread == NULL) {
/* Return an invalid argument error: */
errno = EINVAL;
data = NULL;
}
/* Check if there is specific data: */

View File

@ -44,8 +44,7 @@ pthread_cond_init(pthread_cond_t * cond, const pthread_condattr_t * cond_attr)
int rval = 0;
if (cond == NULL) {
errno = EINVAL;
rval = -1;
rval = EINVAL;
} else {
/*
* Check if a pointer to a condition variable attribute
@ -69,8 +68,7 @@ pthread_cond_init(pthread_cond_t * cond, const pthread_condattr_t * cond_attr)
/* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
rval = -1;
rval = EINVAL;
break;
}
@ -78,8 +76,7 @@ pthread_cond_init(pthread_cond_t * cond, const pthread_condattr_t * cond_attr)
if (rval == 0) {
if ((pcond = (pthread_cond_t)
malloc(sizeof(struct pthread_cond))) == NULL) {
errno = ENOMEM;
rval = -1;
rval = ENOMEM;
} else {
/*
* Initialise the condition variable
@ -102,8 +99,7 @@ pthread_cond_destroy(pthread_cond_t * cond)
int rval = 0;
if (cond == NULL || *cond == NULL) {
errno = EINVAL;
rval = -1;
rval = EINVAL;
} else {
/* Process according to condition variable type: */
switch ((*cond)->c_type) {
@ -115,8 +111,7 @@ pthread_cond_destroy(pthread_cond_t * cond)
/* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
rval = -1;
rval = EINVAL;
break;
}
@ -140,8 +135,7 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex)
int status;
if (cond == NULL || *cond == NULL) {
errno = EINVAL;
rval = -1;
rval = EINVAL;
} else {
/* Block signals: */
_thread_kern_sig_block(&status);
@ -176,8 +170,7 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex)
/* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
rval = -1;
rval = EINVAL;
break;
}
@ -197,8 +190,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
int status;
if (cond == NULL || *cond == NULL) {
errno = EINVAL;
rval = -1;
rval = EINVAL;
} else {
/* Block signals: */
_thread_kern_sig_block(&status);
@ -242,8 +234,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
/* Check if the wait timed out: */
else if (_thread_run->timeout) {
/* Return a timeout error: */
errno = ETIMEDOUT;
rval = -1;
rval = ETIMEDOUT;
}
}
break;
@ -251,8 +242,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
/* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
rval = -1;
rval = EINVAL;
break;
}
@ -272,8 +262,7 @@ pthread_cond_signal(pthread_cond_t * cond)
pthread_t pthread;
if (cond == NULL || *cond == NULL) {
errno = EINVAL;
rval = -1;
rval = EINVAL;
} else {
/* Block signals: */
_thread_kern_sig_block(&status);
@ -292,8 +281,7 @@ pthread_cond_signal(pthread_cond_t * cond)
/* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
rval = -1;
rval = EINVAL;
break;
}
@ -333,8 +321,7 @@ pthread_cond_broadcast(pthread_cond_t * cond)
/* Trap invalid condition variable types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
rval = -1;
rval = EINVAL;
break;
}

View File

@ -40,8 +40,7 @@ int pthread_condattr_destroy(pthread_condattr_t *attr)
{
int ret;
if (attr == NULL || *attr == NULL) {
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
free(*attr);
*attr = NULL;

View File

@ -45,8 +45,7 @@ pthread_condattr_init(pthread_condattr_t *attr)
if ((pattr = (pthread_condattr_t)
malloc(sizeof(struct pthread_cond_attr))) == NULL) {
errno = ENOMEM;
ret = -1;
ret = ENOMEM;
} else {
memcpy(pattr, &pthread_condattr_default,
sizeof(struct pthread_cond_attr));

View File

@ -49,8 +49,7 @@ pthread_detach(pthread_t * p_pthread)
/* Check for invalid calling parameters: */
if (p_pthread == NULL || (pthread = *p_pthread) == NULL) {
/* Return an invalid argument error: */
errno = EINVAL;
rval = -1;
rval = EINVAL;
}
/* Check if the thread has not been detached: */
else if ((pthread->attr.flags & PTHREAD_DETACHED) == 0) {
@ -70,8 +69,7 @@ pthread_detach(pthread_t * p_pthread)
*p_pthread = NULL;
} else {
/* Return an error: */
errno = ESRCH;
rval = -1;
rval = ESRCH;
}
/* Unblock signals: */

View File

@ -67,14 +67,12 @@ pthread_join(pthread_t pthread, void **thread_return)
if (pthread1 == NULL) {
/* Return an error: */
errno = ESRCH;
rval = -1;
rval = ESRCH;
/* Check if this thread has been detached: */
} else if ((pthread->attr.flags & PTHREAD_DETACHED) != 0) {
/* Return an error: */
errno = ESRCH;
rval = -1;
rval = ESRCH;
}
/* Check if the thread is not dead: */
else if (pthread->state != PS_DEAD) {
@ -96,8 +94,7 @@ pthread_join(pthread_t pthread, void **thread_return)
}
} else {
/* Return an error: */
errno = ESRCH;
rval = -1;
rval = ESRCH;
}
} else {
/* Check if the return value is required: */

View File

@ -45,8 +45,7 @@ pthread_mutexattr_init(pthread_mutexattr_t *attr)
if ((pattr = (pthread_mutexattr_t)
malloc(sizeof(struct pthread_mutex_attr))) == NULL) {
errno = ENOMEM;
ret = -1;
ret = ENOMEM;
} else {
memcpy(pattr, &pthread_mutexattr_default,
sizeof(struct pthread_mutex_attr));

View File

@ -46,8 +46,7 @@ pthread_mutex_init(pthread_mutex_t * mutex,
int status;
if (mutex == NULL) {
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
/* Check if default mutex attributes: */
if (mutex_attr == NULL || *mutex_attr == NULL) {
@ -55,8 +54,7 @@ pthread_mutex_init(pthread_mutex_t * mutex,
type = MUTEX_TYPE_FAST;
} else if ((*mutex_attr)->m_type >= MUTEX_TYPE_MAX) {
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
/* Use the requested mutex type: */
type = (*mutex_attr)->m_type;
@ -65,8 +63,7 @@ pthread_mutex_init(pthread_mutex_t * mutex,
/* Check no errors so far: */
if (ret == 0) {
if ((pmutex = (pthread_mutex_t) malloc(sizeof(struct pthread_mutex))) == NULL) {
errno = ENOMEM;
ret = -1;
ret = ENOMEM;
} else {
/* Reset the mutex flags: */
pmutex->m_flags = 0;
@ -90,8 +87,7 @@ pthread_mutex_init(pthread_mutex_t * mutex,
/* Trap invalid mutex types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
break;
}
if (ret == 0) {
@ -122,8 +118,7 @@ pthread_mutex_destroy(pthread_mutex_t * mutex)
int status;
if (mutex == NULL || *mutex == NULL) {
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
/* Block signals: */
_thread_kern_sig_block(&status);
@ -144,8 +139,7 @@ pthread_mutex_destroy(pthread_mutex_t * mutex)
/* Trap undefined mutex types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
break;
}
@ -169,8 +163,7 @@ pthread_mutex_trylock(pthread_mutex_t * mutex)
int status;
if (mutex == NULL || *mutex == NULL) {
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
/* Block signals: */
_thread_kern_sig_block(&status);
@ -185,8 +178,7 @@ pthread_mutex_trylock(pthread_mutex_t * mutex)
(*mutex)->m_owner = _thread_run;
} else {
/* Return a busy error: */
errno = EBUSY;
ret = -1;
ret = EBUSY;
}
break;
@ -203,8 +195,7 @@ pthread_mutex_trylock(pthread_mutex_t * mutex)
(*mutex)->m_data.m_count++;
} else {
/* Return a busy error: */
errno = EBUSY;
ret = -1;
ret = EBUSY;
}
} else {
/* Lock the mutex for the running thread: */
@ -215,8 +206,7 @@ pthread_mutex_trylock(pthread_mutex_t * mutex)
/* Trap invalid mutex types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
break;
}
@ -235,8 +225,7 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
int status;
if (mutex == NULL || *mutex == NULL) {
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
/* Block signals: */
_thread_kern_sig_block(&status);
@ -306,8 +295,7 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
/* Trap invalid mutex types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
break;
}
@ -326,8 +314,7 @@ pthread_mutex_unlock(pthread_mutex_t * mutex)
int status;
if (mutex == NULL || *mutex == NULL) {
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
/* Block signals: */
_thread_kern_sig_block(&status);
@ -339,8 +326,7 @@ pthread_mutex_unlock(pthread_mutex_t * mutex)
/* Check if the running thread is not the owner of the mutex: */
if ((*mutex)->m_owner != _thread_run) {
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
}
/*
* Get the next thread from the queue of threads waiting on
@ -357,8 +343,7 @@ pthread_mutex_unlock(pthread_mutex_t * mutex)
/* Check if the running thread is not the owner of the mutex: */
if ((*mutex)->m_owner != _thread_run) {
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
}
/* Check if there are still counts: */
else if ((*mutex)->m_data.m_count) {
@ -378,8 +363,7 @@ pthread_mutex_unlock(pthread_mutex_t * mutex)
/* Trap invalid mutex types: */
default:
/* Return an invalid argument error: */
errno = EINVAL;
ret = -1;
ret = EINVAL;
break;
}

View File

@ -40,8 +40,7 @@ int pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
{
int ret;
if (attr == NULL || *attr == NULL) {
errno = EINVAL;
ret = -1;
ret = EINVAL;
} else {
free(*attr);
*attr = NULL;

View File

@ -209,7 +209,6 @@ pthread_getspecific(pthread_key_t key)
/* Check for errors: */
if (pthread == NULL) {
/* Return an invalid argument error: */
errno = EINVAL;
data = NULL;
}
/* Check if there is specific data: */