1 /*	$OpenBSD: uthread_rwlockattr.c,v 1.4 2000/01/04 22:34:24 alex Exp $	*/
2 /*-
3  * Copyright (c) 1998 Alex Nash
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD: uthread_rwlockattr.c,v 1.3 1999/08/28 00:03:45 peter Exp $
28  */
29 
30 #ifdef _THREAD_SAFE
31 #include <errno.h>
32 #include <stdlib.h>
33 
34 #include <pthread.h>
35 #include "pthread_private.h"
36 
37 int
pthread_rwlockattr_destroy(pthread_rwlockattr_t * rwlockattr)38 pthread_rwlockattr_destroy (pthread_rwlockattr_t *rwlockattr)
39 {
40 	pthread_rwlockattr_t prwlockattr;
41 
42 	if (rwlockattr == NULL)
43 		return(EINVAL);
44 
45 	prwlockattr = *rwlockattr;
46 
47 	if (prwlockattr == NULL)
48 		return(EINVAL);
49 
50 	free(prwlockattr);
51 
52 	return(0);
53 }
54 
55 int
pthread_rwlockattr_getpshared(const pthread_rwlockattr_t * rwlockattr,int * pshared)56 pthread_rwlockattr_getpshared (const pthread_rwlockattr_t *rwlockattr,
57 	int *pshared)
58 {
59 	*pshared = (*rwlockattr)->pshared;
60 
61 	return(0);
62 }
63 
64 int
pthread_rwlockattr_init(pthread_rwlockattr_t * rwlockattr)65 pthread_rwlockattr_init (pthread_rwlockattr_t *rwlockattr)
66 {
67 	pthread_rwlockattr_t prwlockattr;
68 
69 	if (rwlockattr == NULL)
70 		return(EINVAL);
71 
72 	prwlockattr = (pthread_rwlockattr_t)
73 		malloc(sizeof(struct pthread_rwlockattr));
74 
75 	if (prwlockattr == NULL)
76 		return(ENOMEM);
77 
78 	prwlockattr->pshared 	= PTHREAD_PROCESS_PRIVATE;
79 	*rwlockattr		= prwlockattr;
80 
81 	return(0);
82 }
83 
84 int
pthread_rwlockattr_setpshared(pthread_rwlockattr_t * rwlockattr,int pshared)85 pthread_rwlockattr_setpshared (pthread_rwlockattr_t *rwlockattr,
86 	int pshared)
87 {
88 	/* only PTHREAD_PROCESS_PRIVATE is supported */
89 	if (pshared != PTHREAD_PROCESS_PRIVATE)
90 		return(EINVAL);
91 
92 	(*rwlockattr)->pshared = pshared;
93 
94 	return(0);
95 }
96 
97 #endif /* _THREAD_SAFE */
98