1*45faf784Sguenther /* $OpenBSD: rthread_mutex_prio.c,v 1.2 2014/06/23 00:43:15 guenther Exp $ */
23ba1f1c4Sguenther /*
33ba1f1c4Sguenther * Copyright (c) 2011 Philip Guenther <guenther@openbsd.org>
43ba1f1c4Sguenther *
53ba1f1c4Sguenther * Permission to use, copy, modify, and distribute this software for any
63ba1f1c4Sguenther * purpose with or without fee is hereby granted, provided that the above
73ba1f1c4Sguenther * copyright notice and this permission notice appear in all copies.
83ba1f1c4Sguenther *
93ba1f1c4Sguenther * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
103ba1f1c4Sguenther * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
113ba1f1c4Sguenther * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
123ba1f1c4Sguenther * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
133ba1f1c4Sguenther * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
143ba1f1c4Sguenther * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
153ba1f1c4Sguenther * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
163ba1f1c4Sguenther */
173ba1f1c4Sguenther
183ba1f1c4Sguenther
193ba1f1c4Sguenther #include <errno.h>
203ba1f1c4Sguenther
213ba1f1c4Sguenther #include <pthread.h>
223ba1f1c4Sguenther #include "rthread.h"
233ba1f1c4Sguenther
243ba1f1c4Sguenther int
pthread_mutex_getprioceiling(pthread_mutex_t * mutexp,int * prioceiling)253ba1f1c4Sguenther pthread_mutex_getprioceiling(pthread_mutex_t *mutexp, int *prioceiling)
263ba1f1c4Sguenther {
273ba1f1c4Sguenther pthread_mutex_t mutex = *mutexp;
283ba1f1c4Sguenther
293ba1f1c4Sguenther if (mutex->prioceiling == -1)
303ba1f1c4Sguenther return (EINVAL);
313ba1f1c4Sguenther *prioceiling = mutex->prioceiling;
323ba1f1c4Sguenther
333ba1f1c4Sguenther return (0);
343ba1f1c4Sguenther }
353ba1f1c4Sguenther
363ba1f1c4Sguenther int
pthread_mutex_setprioceiling(pthread_mutex_t * mutexp,int prioceiling,int * old_ceiling)373ba1f1c4Sguenther pthread_mutex_setprioceiling(pthread_mutex_t *mutexp, int prioceiling,
383ba1f1c4Sguenther int *old_ceiling)
393ba1f1c4Sguenther {
403ba1f1c4Sguenther pthread_mutex_t mutex = *mutexp;
413ba1f1c4Sguenther int ret;
423ba1f1c4Sguenther
433ba1f1c4Sguenther if (mutex->prioceiling == -1 ||
443ba1f1c4Sguenther prioceiling < PTHREAD_MIN_PRIORITY ||
453ba1f1c4Sguenther prioceiling > PTHREAD_MAX_PRIORITY) {
463ba1f1c4Sguenther ret = EINVAL;
473ba1f1c4Sguenther } else if ((ret = pthread_mutex_lock(mutexp)) == 0) {
483ba1f1c4Sguenther *old_ceiling = mutex->prioceiling;
493ba1f1c4Sguenther mutex->prioceiling = prioceiling;
503ba1f1c4Sguenther pthread_mutex_unlock(mutexp);
513ba1f1c4Sguenther }
523ba1f1c4Sguenther
533ba1f1c4Sguenther return (ret);
543ba1f1c4Sguenther }
55