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