xref: /openbsd-src/lib/librthread/rthread_mutex_prio.c (revision 45faf784b594bcdfcad8342ccc6fc81abd15cb3d)
1 /*	$OpenBSD: rthread_mutex_prio.c,v 1.2 2014/06/23 00:43:15 guenther Exp $ */
2 /*
3  * Copyright (c) 2011 Philip Guenther <guenther@openbsd.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 
19 #include <errno.h>
20 
21 #include <pthread.h>
22 #include "rthread.h"
23 
24 int
pthread_mutex_getprioceiling(pthread_mutex_t * mutexp,int * prioceiling)25 pthread_mutex_getprioceiling(pthread_mutex_t *mutexp, int *prioceiling)
26 {
27 	pthread_mutex_t mutex = *mutexp;
28 
29 	if (mutex->prioceiling == -1)
30 		return (EINVAL);
31 	*prioceiling = mutex->prioceiling;
32 
33 	return (0);
34 }
35 
36 int
pthread_mutex_setprioceiling(pthread_mutex_t * mutexp,int prioceiling,int * old_ceiling)37 pthread_mutex_setprioceiling(pthread_mutex_t *mutexp, int prioceiling,
38     int *old_ceiling)
39 {
40 	pthread_mutex_t mutex = *mutexp;
41 	int ret;
42 
43 	if (mutex->prioceiling == -1 ||
44 	    prioceiling < PTHREAD_MIN_PRIORITY ||
45 	    prioceiling > PTHREAD_MAX_PRIORITY) {
46 		ret = EINVAL;
47 	} else if ((ret = pthread_mutex_lock(mutexp)) == 0) {
48 		*old_ceiling = mutex->prioceiling;
49 		mutex->prioceiling = prioceiling;
50 		pthread_mutex_unlock(mutexp);
51 	}
52 
53 	return (ret);
54 }
55