xref: /dflybsd-src/lib/libthread_xu/thread/thr_condattr.c (revision 71b3fa151e714295cd932238bb91973cd4a02c55)
1*71b3fa15SDavid Xu /*
2*71b3fa15SDavid Xu  * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
3*71b3fa15SDavid Xu  * All rights reserved.
4*71b3fa15SDavid Xu  *
5*71b3fa15SDavid Xu  * Redistribution and use in source and binary forms, with or without
6*71b3fa15SDavid Xu  * modification, are permitted provided that the following conditions
7*71b3fa15SDavid Xu  * are met:
8*71b3fa15SDavid Xu  * 1. Redistributions of source code must retain the above copyright
9*71b3fa15SDavid Xu  *    notice, this list of conditions and the following disclaimer.
10*71b3fa15SDavid Xu  * 2. Redistributions in binary form must reproduce the above copyright
11*71b3fa15SDavid Xu  *    notice, this list of conditions and the following disclaimer in the
12*71b3fa15SDavid Xu  *    documentation and/or other materials provided with the distribution.
13*71b3fa15SDavid Xu  * 3. All advertising materials mentioning features or use of this software
14*71b3fa15SDavid Xu  *    must display the following acknowledgement:
15*71b3fa15SDavid Xu  *	This product includes software developed by John Birrell.
16*71b3fa15SDavid Xu  * 4. Neither the name of the author nor the names of any co-contributors
17*71b3fa15SDavid Xu  *    may be used to endorse or promote products derived from this software
18*71b3fa15SDavid Xu  *    without specific prior written permission.
19*71b3fa15SDavid Xu  *
20*71b3fa15SDavid Xu  * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
21*71b3fa15SDavid Xu  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22*71b3fa15SDavid Xu  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23*71b3fa15SDavid Xu  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24*71b3fa15SDavid Xu  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25*71b3fa15SDavid Xu  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26*71b3fa15SDavid Xu  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27*71b3fa15SDavid Xu  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28*71b3fa15SDavid Xu  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29*71b3fa15SDavid Xu  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30*71b3fa15SDavid Xu  * SUCH DAMAGE.
31*71b3fa15SDavid Xu  *
32*71b3fa15SDavid Xu  * $DragonFly: src/lib/libthread_xu/thread/thr_condattr.c,v 1.1 2005/02/01 12:38:27 davidxu Exp $
33*71b3fa15SDavid Xu  */
34*71b3fa15SDavid Xu #include <stdlib.h>
35*71b3fa15SDavid Xu #include <string.h>
36*71b3fa15SDavid Xu #include <errno.h>
37*71b3fa15SDavid Xu #include <pthread.h>
38*71b3fa15SDavid Xu #include "thr_private.h"
39*71b3fa15SDavid Xu 
40*71b3fa15SDavid Xu __weak_reference(_pthread_condattr_init, pthread_condattr_init);
41*71b3fa15SDavid Xu __weak_reference(_pthread_condattr_destroy, pthread_condattr_destroy);
42*71b3fa15SDavid Xu __weak_reference(_pthread_condattr_getclock, pthread_condattr_getclock);
43*71b3fa15SDavid Xu __weak_reference(_pthread_condattr_setclock, pthread_condattr_setclock);
44*71b3fa15SDavid Xu __weak_reference(_pthread_condattr_getpshared, pthread_condattr_getpshared);
45*71b3fa15SDavid Xu __weak_reference(_pthread_condattr_setpshared, pthread_condattr_setpshared);
46*71b3fa15SDavid Xu 
47*71b3fa15SDavid Xu int
48*71b3fa15SDavid Xu _pthread_condattr_init(pthread_condattr_t *attr)
49*71b3fa15SDavid Xu {
50*71b3fa15SDavid Xu 	pthread_condattr_t pattr;
51*71b3fa15SDavid Xu 	int ret;
52*71b3fa15SDavid Xu 
53*71b3fa15SDavid Xu 	if ((pattr = (pthread_condattr_t)
54*71b3fa15SDavid Xu 	    malloc(sizeof(struct pthread_cond_attr))) == NULL) {
55*71b3fa15SDavid Xu 		ret = ENOMEM;
56*71b3fa15SDavid Xu 	} else {
57*71b3fa15SDavid Xu 		memcpy(pattr, &_pthread_condattr_default,
58*71b3fa15SDavid Xu 		    sizeof(struct pthread_cond_attr));
59*71b3fa15SDavid Xu 		*attr = pattr;
60*71b3fa15SDavid Xu 		ret = 0;
61*71b3fa15SDavid Xu 	}
62*71b3fa15SDavid Xu 	return (ret);
63*71b3fa15SDavid Xu }
64*71b3fa15SDavid Xu 
65*71b3fa15SDavid Xu int
66*71b3fa15SDavid Xu _pthread_condattr_destroy(pthread_condattr_t *attr)
67*71b3fa15SDavid Xu {
68*71b3fa15SDavid Xu 	int	ret;
69*71b3fa15SDavid Xu 
70*71b3fa15SDavid Xu 	if (attr == NULL || *attr == NULL) {
71*71b3fa15SDavid Xu 		ret = EINVAL;
72*71b3fa15SDavid Xu 	} else {
73*71b3fa15SDavid Xu 		free(*attr);
74*71b3fa15SDavid Xu 		*attr = NULL;
75*71b3fa15SDavid Xu 		ret = 0;
76*71b3fa15SDavid Xu 	}
77*71b3fa15SDavid Xu 	return(ret);
78*71b3fa15SDavid Xu }
79*71b3fa15SDavid Xu 
80*71b3fa15SDavid Xu int
81*71b3fa15SDavid Xu _pthread_condattr_getclock(const pthread_condattr_t *attr,
82*71b3fa15SDavid Xu        clockid_t *clock_id)
83*71b3fa15SDavid Xu {
84*71b3fa15SDavid Xu 	if (attr == NULL || *attr == NULL)
85*71b3fa15SDavid Xu 		return (EINVAL);
86*71b3fa15SDavid Xu 	*clock_id = (*attr)->c_clockid;
87*71b3fa15SDavid Xu 	return (0);
88*71b3fa15SDavid Xu }
89*71b3fa15SDavid Xu 
90*71b3fa15SDavid Xu int
91*71b3fa15SDavid Xu _pthread_condattr_setclock(const pthread_condattr_t *attr,
92*71b3fa15SDavid Xu        clockid_t clock_id)
93*71b3fa15SDavid Xu {
94*71b3fa15SDavid Xu 	if (attr == NULL || *attr == NULL)
95*71b3fa15SDavid Xu 		return (EINVAL);
96*71b3fa15SDavid Xu 	if (clock_id != CLOCK_REALTIME)
97*71b3fa15SDavid Xu 		return (EINVAL);
98*71b3fa15SDavid Xu 	(*attr)->c_clockid = clock_id;
99*71b3fa15SDavid Xu 	return (0);
100*71b3fa15SDavid Xu }
101*71b3fa15SDavid Xu 
102*71b3fa15SDavid Xu int
103*71b3fa15SDavid Xu _pthread_condattr_getpshared(const pthread_condattr_t *attr,
104*71b3fa15SDavid Xu 	int *pshared)
105*71b3fa15SDavid Xu {
106*71b3fa15SDavid Xu 	if (attr == NULL || *attr == NULL)
107*71b3fa15SDavid Xu 		return (EINVAL);
108*71b3fa15SDavid Xu 
109*71b3fa15SDavid Xu 	pshared = PTHREAD_PROCESS_PRIVATE;
110*71b3fa15SDavid Xu 	return (0);
111*71b3fa15SDavid Xu }
112*71b3fa15SDavid Xu 
113*71b3fa15SDavid Xu int
114*71b3fa15SDavid Xu _pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared)
115*71b3fa15SDavid Xu {
116*71b3fa15SDavid Xu 	if (attr == NULL || *attr == NULL)
117*71b3fa15SDavid Xu 		return (EINVAL);
118*71b3fa15SDavid Xu 
119*71b3fa15SDavid Xu 	if  (pshared != PTHREAD_PROCESS_PRIVATE)
120*71b3fa15SDavid Xu 		return (EINVAL);
121*71b3fa15SDavid Xu 	return (0);
122*71b3fa15SDavid Xu }
123