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