#include "lint.h"
#include "thr_uberdata.h"
#pragma weak _pthread_condattr_init = pthread_condattr_init
int
pthread_condattr_init(pthread_condattr_t *attr)
{
cvattr_t *ap;
if ((ap = lmalloc(sizeof (cvattr_t))) == NULL)
return (ENOMEM);
ap->pshared = PTHREAD_PROCESS_PRIVATE;
ap->clockid = CLOCK_REALTIME;
attr->__pthread_condattrp = ap;
return (0);
}
int
pthread_condattr_destroy(pthread_condattr_t *attr)
{
if (attr == NULL || attr->__pthread_condattrp == NULL)
return (EINVAL);
lfree(attr->__pthread_condattrp, sizeof (cvattr_t));
attr->__pthread_condattrp = NULL;
return (0);
}
int
pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock_id)
{
cvattr_t *ap;
if (attr != NULL && (ap = attr->__pthread_condattrp) != NULL &&
(clock_id == CLOCK_REALTIME || clock_id == CLOCK_HIGHRES)) {
ap->clockid = clock_id;
return (0);
}
return (EINVAL);
}
int
pthread_condattr_getclock(const pthread_condattr_t *attr, clockid_t *clock_id)
{
cvattr_t *ap;
if (attr != NULL && (ap = attr->__pthread_condattrp) != NULL &&
clock_id != NULL) {
*clock_id = ap->clockid;
return (0);
}
return (EINVAL);
}
int
pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared)
{
cvattr_t *ap;
if (attr != NULL && (ap = attr->__pthread_condattrp) != NULL &&
(pshared == PTHREAD_PROCESS_PRIVATE ||
pshared == PTHREAD_PROCESS_SHARED)) {
ap->pshared = pshared;
return (0);
}
return (EINVAL);
}
#pragma weak _pthread_condattr_getpshared = pthread_condattr_getpshared
int
pthread_condattr_getpshared(const pthread_condattr_t *attr, int *pshared)
{
cvattr_t *ap;
if (attr != NULL && (ap = attr->__pthread_condattrp) != NULL &&
pshared != NULL) {
*pshared = ap->pshared;
return (0);
}
return (EINVAL);
}
#pragma weak _pthread_cond_init = pthread_cond_init
int
pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
{
cvattr_t *ap;
int type;
clockid_t clock_id;
int error;
if (attr == NULL) {
type = PTHREAD_PROCESS_PRIVATE;
clock_id = CLOCK_REALTIME;
} else if ((ap = attr->__pthread_condattrp) != NULL) {
type = ap->pshared;
clock_id = ap->clockid;
} else {
return (EINVAL);
}
if (clock_id != CLOCK_REALTIME && clock_id != CLOCK_HIGHRES)
error = EINVAL;
else if ((error = cond_init((cond_t *)cond, type, NULL)) == 0)
((cond_t *)cond)->cond_clockid = (uint8_t)clock_id;
return (error);
}