171b3fa15SDavid Xu /*
271b3fa15SDavid Xu * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
371b3fa15SDavid Xu * All rights reserved.
471b3fa15SDavid Xu *
571b3fa15SDavid Xu * Redistribution and use in source and binary forms, with or without
671b3fa15SDavid Xu * modification, are permitted provided that the following conditions
771b3fa15SDavid Xu * are met:
871b3fa15SDavid Xu * 1. Redistributions of source code must retain the above copyright
971b3fa15SDavid Xu * notice, this list of conditions and the following disclaimer.
1071b3fa15SDavid Xu * 2. Redistributions in binary form must reproduce the above copyright
1171b3fa15SDavid Xu * notice, this list of conditions and the following disclaimer in the
1271b3fa15SDavid Xu * documentation and/or other materials provided with the distribution.
13d3b15642Szrj * 3. Neither the name of the author nor the names of any co-contributors
1471b3fa15SDavid Xu * may be used to endorse or promote products derived from this software
1571b3fa15SDavid Xu * without specific prior written permission.
1671b3fa15SDavid Xu *
1771b3fa15SDavid Xu * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
1871b3fa15SDavid Xu * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1971b3fa15SDavid Xu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2071b3fa15SDavid Xu * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2171b3fa15SDavid Xu * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2271b3fa15SDavid Xu * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2371b3fa15SDavid Xu * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2471b3fa15SDavid Xu * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2571b3fa15SDavid Xu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2671b3fa15SDavid Xu * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2771b3fa15SDavid Xu * SUCH DAMAGE.
2871b3fa15SDavid Xu */
29fc71f871SDavid Xu
30fc71f871SDavid Xu #include "namespace.h"
31fc71f871SDavid Xu #include <errno.h>
3271b3fa15SDavid Xu #include <stdlib.h>
3371b3fa15SDavid Xu #include <string.h>
3471b3fa15SDavid Xu #include <pthread.h>
35fc71f871SDavid Xu #include "un-namespace.h"
36fc71f871SDavid Xu
3771b3fa15SDavid Xu #include "thr_private.h"
3871b3fa15SDavid Xu
3971b3fa15SDavid Xu int
_pthread_condattr_init(pthread_condattr_t * attr)4071b3fa15SDavid Xu _pthread_condattr_init(pthread_condattr_t *attr)
4171b3fa15SDavid Xu {
4271b3fa15SDavid Xu pthread_condattr_t pattr;
4371b3fa15SDavid Xu int ret;
4471b3fa15SDavid Xu
45*cf8046a9Szrj pattr = __malloc(sizeof(struct __pthread_condattr_s));
46e7bf3f77SMatthew Dillon if (pattr == NULL) {
4771b3fa15SDavid Xu ret = ENOMEM;
4871b3fa15SDavid Xu } else {
4971b3fa15SDavid Xu memcpy(pattr, &_pthread_condattr_default,
50*cf8046a9Szrj sizeof(struct __pthread_condattr_s));
5171b3fa15SDavid Xu *attr = pattr;
5271b3fa15SDavid Xu ret = 0;
5371b3fa15SDavid Xu }
5471b3fa15SDavid Xu return (ret);
5571b3fa15SDavid Xu }
5671b3fa15SDavid Xu
5771b3fa15SDavid Xu int
_pthread_condattr_destroy(pthread_condattr_t * attr)5871b3fa15SDavid Xu _pthread_condattr_destroy(pthread_condattr_t *attr)
5971b3fa15SDavid Xu {
6071b3fa15SDavid Xu int ret;
6171b3fa15SDavid Xu
6271b3fa15SDavid Xu if (attr == NULL || *attr == NULL) {
6371b3fa15SDavid Xu ret = EINVAL;
6471b3fa15SDavid Xu } else {
65e7bf3f77SMatthew Dillon __free(*attr);
6671b3fa15SDavid Xu *attr = NULL;
6771b3fa15SDavid Xu ret = 0;
6871b3fa15SDavid Xu }
6971b3fa15SDavid Xu return(ret);
7071b3fa15SDavid Xu }
7171b3fa15SDavid Xu
7271b3fa15SDavid Xu int
_pthread_condattr_getclock(const pthread_condattr_t * __restrict attr,clockid_t * __restrict clock_id)73d33005aaSSascha Wildner _pthread_condattr_getclock(const pthread_condattr_t * __restrict attr,
74d33005aaSSascha Wildner clockid_t * __restrict clock_id)
7571b3fa15SDavid Xu {
7671b3fa15SDavid Xu if (attr == NULL || *attr == NULL)
7771b3fa15SDavid Xu return (EINVAL);
7871b3fa15SDavid Xu *clock_id = (*attr)->c_clockid;
7971b3fa15SDavid Xu return (0);
8071b3fa15SDavid Xu }
8171b3fa15SDavid Xu
8271b3fa15SDavid Xu int
_pthread_condattr_setclock(pthread_condattr_t * attr,clockid_t clock_id)83d074ee5bSDavid Xu _pthread_condattr_setclock(pthread_condattr_t *attr,
8471b3fa15SDavid Xu clockid_t clock_id)
8571b3fa15SDavid Xu {
8671b3fa15SDavid Xu if (attr == NULL || *attr == NULL)
8771b3fa15SDavid Xu return (EINVAL);
886bbb5e4aSSascha Wildner if (clock_id != CLOCK_REALTIME &&
8919451dc5Szrj clock_id != CLOCK_MONOTONIC) {
9071b3fa15SDavid Xu return (EINVAL);
9119451dc5Szrj }
9271b3fa15SDavid Xu (*attr)->c_clockid = clock_id;
9371b3fa15SDavid Xu return (0);
9471b3fa15SDavid Xu }
9571b3fa15SDavid Xu
9671b3fa15SDavid Xu int
_pthread_condattr_getpshared(const pthread_condattr_t * __restrict attr,int * __restrict pshared)97d33005aaSSascha Wildner _pthread_condattr_getpshared(const pthread_condattr_t * __restrict attr,
98d33005aaSSascha Wildner int * __restrict pshared)
9971b3fa15SDavid Xu {
10071b3fa15SDavid Xu if (attr == NULL || *attr == NULL)
10171b3fa15SDavid Xu return (EINVAL);
1024310b5baSSascha Wildner *pshared = PTHREAD_PROCESS_PRIVATE;
10371b3fa15SDavid Xu return (0);
10471b3fa15SDavid Xu }
10571b3fa15SDavid Xu
10671b3fa15SDavid Xu int
_pthread_condattr_setpshared(pthread_condattr_t * attr,int pshared)10771b3fa15SDavid Xu _pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared)
10871b3fa15SDavid Xu {
10971b3fa15SDavid Xu if (attr == NULL || *attr == NULL)
11071b3fa15SDavid Xu return (EINVAL);
11171b3fa15SDavid Xu
11271b3fa15SDavid Xu if (pshared != PTHREAD_PROCESS_PRIVATE)
11371b3fa15SDavid Xu return (EINVAL);
11471b3fa15SDavid Xu return (0);
11571b3fa15SDavid Xu }
1165a1048c8SDavid Xu
1175a1048c8SDavid Xu __strong_reference(_pthread_condattr_init, pthread_condattr_init);
1185a1048c8SDavid Xu __strong_reference(_pthread_condattr_destroy, pthread_condattr_destroy);
1195a1048c8SDavid Xu __strong_reference(_pthread_condattr_getclock, pthread_condattr_getclock);
1205a1048c8SDavid Xu __strong_reference(_pthread_condattr_setclock, pthread_condattr_setclock);
1215a1048c8SDavid Xu __strong_reference(_pthread_condattr_getpshared, pthread_condattr_getpshared);
1225a1048c8SDavid Xu __strong_reference(_pthread_condattr_setpshared, pthread_condattr_setpshared);
123