1*849948d5Skurt /* $OpenBSD: rthread_mutexattr.c,v 1.3 2012/04/13 13:50:37 kurt Exp $ */
2d3690317Sguenther /*
3d3690317Sguenther * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
4d3690317Sguenther * Copyright (c) 2011 Philip Guenther <guenther@openbsd.org>
5d3690317Sguenther * All Rights Reserved.
6d3690317Sguenther *
7d3690317Sguenther * Permission to use, copy, modify, and distribute this software for any
8d3690317Sguenther * purpose with or without fee is hereby granted, provided that the above
9d3690317Sguenther * copyright notice and this permission notice appear in all copies.
10d3690317Sguenther *
11d3690317Sguenther * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12d3690317Sguenther * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13d3690317Sguenther * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14d3690317Sguenther * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15d3690317Sguenther * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16d3690317Sguenther * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17d3690317Sguenther * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18d3690317Sguenther */
19d3690317Sguenther /*
20d3690317Sguenther * Mutex attributes
21d3690317Sguenther */
22d3690317Sguenther
23d3690317Sguenther
24d3690317Sguenther #include <stdlib.h>
25d3690317Sguenther #include <unistd.h>
26d3690317Sguenther #include <errno.h>
27d3690317Sguenther
28d3690317Sguenther #include <pthread.h>
2975dc9675Sguenther #include <pthread_np.h>
30d3690317Sguenther
31d3690317Sguenther #include "rthread.h"
32d3690317Sguenther
33d3690317Sguenther int
pthread_mutexattr_init(pthread_mutexattr_t * attrp)34d3690317Sguenther pthread_mutexattr_init(pthread_mutexattr_t *attrp)
35d3690317Sguenther {
36d3690317Sguenther pthread_mutexattr_t attr;
37d3690317Sguenther
38d3690317Sguenther attr = calloc(1, sizeof(*attr));
39d3690317Sguenther if (!attr)
40d3690317Sguenther return (errno);
41*849948d5Skurt attr->ma_type = PTHREAD_MUTEX_DEFAULT;
42d3690317Sguenther *attrp = attr;
43d3690317Sguenther
44d3690317Sguenther return (0);
45d3690317Sguenther }
46d3690317Sguenther
47d3690317Sguenther int
pthread_mutexattr_destroy(pthread_mutexattr_t * attrp)48d3690317Sguenther pthread_mutexattr_destroy(pthread_mutexattr_t *attrp)
49d3690317Sguenther {
50d3690317Sguenther free(*attrp);
51d3690317Sguenther *attrp = NULL;
52d3690317Sguenther
53d3690317Sguenther return (0);
54d3690317Sguenther }
55d3690317Sguenther
56d3690317Sguenther int
pthread_mutexattr_settype(pthread_mutexattr_t * attrp,int type)57d3690317Sguenther pthread_mutexattr_settype(pthread_mutexattr_t *attrp, int type)
58d3690317Sguenther {
59d3690317Sguenther if (type < PTHREAD_MUTEX_ERRORCHECK || type >= PTHREAD_MUTEX_TYPE_MAX)
60d3690317Sguenther return (EINVAL);
61d3690317Sguenther (*attrp)->ma_type = type;
62d3690317Sguenther return (0);
63d3690317Sguenther }
64d3690317Sguenther
65d3690317Sguenther int
pthread_mutexattr_gettype(pthread_mutexattr_t * attrp,int * type)66d3690317Sguenther pthread_mutexattr_gettype(pthread_mutexattr_t *attrp, int *type)
67d3690317Sguenther {
68d3690317Sguenther *type = (*attrp)->ma_type;
69d3690317Sguenther return (0);
70d3690317Sguenther }
71d3690317Sguenther
72d3690317Sguenther int
pthread_mutexattr_setprotocol(pthread_mutexattr_t * attrp,int protocol)73d3690317Sguenther pthread_mutexattr_setprotocol(pthread_mutexattr_t *attrp, int protocol)
74d3690317Sguenther {
75d3690317Sguenther if (protocol < PTHREAD_PRIO_NONE || protocol > PTHREAD_PRIO_PROTECT)
76d3690317Sguenther return (EINVAL);
77d3690317Sguenther (*attrp)->ma_protocol = protocol;
78d3690317Sguenther return (0);
79d3690317Sguenther }
80d3690317Sguenther
81d3690317Sguenther int
pthread_mutexattr_getprotocol(pthread_mutexattr_t * attrp,int * protocol)82d3690317Sguenther pthread_mutexattr_getprotocol(pthread_mutexattr_t *attrp, int *protocol)
83d3690317Sguenther {
84d3690317Sguenther *protocol = (*attrp)->ma_protocol;
85d3690317Sguenther return (0);
86d3690317Sguenther }
87d3690317Sguenther
88d3690317Sguenther int
pthread_mutexattr_setprioceiling(pthread_mutexattr_t * attrp,int prioceiling)89d3690317Sguenther pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attrp, int prioceiling)
90d3690317Sguenther {
91d3690317Sguenther if (prioceiling < PTHREAD_MIN_PRIORITY ||
92d3690317Sguenther prioceiling > PTHREAD_MAX_PRIORITY)
93d3690317Sguenther return (EINVAL);
94d3690317Sguenther (*attrp)->ma_prioceiling = prioceiling;
95d3690317Sguenther return (0);
96d3690317Sguenther }
97d3690317Sguenther
98d3690317Sguenther int
pthread_mutexattr_getprioceiling(pthread_mutexattr_t * attrp,int * prioceiling)99d3690317Sguenther pthread_mutexattr_getprioceiling(pthread_mutexattr_t *attrp, int *prioceiling)
100d3690317Sguenther {
101d3690317Sguenther *prioceiling = (*attrp)->ma_prioceiling;
102d3690317Sguenther return (0);
103d3690317Sguenther }
104d3690317Sguenther
10575dc9675Sguenther int
pthread_mutexattr_getkind_np(pthread_mutexattr_t attrp)10675dc9675Sguenther pthread_mutexattr_getkind_np(pthread_mutexattr_t attrp)
10775dc9675Sguenther {
10875dc9675Sguenther int ret;
10975dc9675Sguenther
11075dc9675Sguenther if (attrp == NULL)
11175dc9675Sguenther ret = EINVAL;
11275dc9675Sguenther else
11375dc9675Sguenther ret = attrp->ma_type;
11475dc9675Sguenther
11575dc9675Sguenther return(ret);
11675dc9675Sguenther }
11775dc9675Sguenther
11875dc9675Sguenther int
pthread_mutexattr_setkind_np(pthread_mutexattr_t * attrp,int kind)11975dc9675Sguenther pthread_mutexattr_setkind_np(pthread_mutexattr_t *attrp, int kind)
12075dc9675Sguenther {
12175dc9675Sguenther int ret;
12275dc9675Sguenther
12375dc9675Sguenther if (attrp == NULL || *attrp == NULL ||
12475dc9675Sguenther kind < PTHREAD_MUTEX_ERRORCHECK || kind >= PTHREAD_MUTEX_TYPE_MAX)
12575dc9675Sguenther ret = EINVAL;
12675dc9675Sguenther else {
12775dc9675Sguenther (*attrp)->ma_type = kind;
12875dc9675Sguenther ret = 0;
12975dc9675Sguenther }
13075dc9675Sguenther
13175dc9675Sguenther return (ret);
13275dc9675Sguenther }
133