144963Sjb/* 244963Sjb * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>. 344963Sjb * All rights reserved. 444963Sjb * 544963Sjb * Redistribution and use in source and binary forms, with or without 644963Sjb * modification, are permitted provided that the following conditions 744963Sjb * are met: 844963Sjb * 1. Redistributions of source code must retain the above copyright 944963Sjb * notice, this list of conditions and the following disclaimer. 1044963Sjb * 2. Redistributions in binary form must reproduce the above copyright 1144963Sjb * notice, this list of conditions and the following disclaimer in the 1244963Sjb * documentation and/or other materials provided with the distribution. 1344963Sjb * 3. All advertising materials mentioning features or use of this software 1444963Sjb * must display the following acknowledgement: 1544963Sjb * This product includes software developed by Daniel Eischen. 1644963Sjb * 4. Neither the name of the author nor the names of any co-contributors 1744963Sjb * may be used to endorse or promote products derived from this software 1844963Sjb * without specific prior written permission. 1944963Sjb * 2044963Sjb * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND 2144963Sjb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2244963Sjb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2344963Sjb * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2444963Sjb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2544963Sjb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2644963Sjb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2744963Sjb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2844963Sjb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2944963Sjb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3044963Sjb * SUCH DAMAGE. 3144963Sjb * 3250476Speter * $FreeBSD$ 3344963Sjb */ 34174112Sdeischen 35174112Sdeischen#include "namespace.h" 3644963Sjb#include <string.h> 3744963Sjb#include <stdlib.h> 3844963Sjb#include <errno.h> 3944963Sjb#include <pthread.h> 40174112Sdeischen#include "un-namespace.h" 41103388Smini#include "thr_private.h" 4244963Sjb 4375369Sdeischen__weak_reference(_pthread_mutexattr_getprioceiling, pthread_mutexattr_getprioceiling); 4475369Sdeischen__weak_reference(_pthread_mutexattr_setprioceiling, pthread_mutexattr_setprioceiling); 4575369Sdeischen__weak_reference(_pthread_mutex_getprioceiling, pthread_mutex_getprioceiling); 4675369Sdeischen__weak_reference(_pthread_mutex_setprioceiling, pthread_mutex_setprioceiling); 4771581Sdeischen 4844963Sjbint 4971581Sdeischen_pthread_mutexattr_getprioceiling(pthread_mutexattr_t *mattr, int *prioceiling) 5044963Sjb{ 5144963Sjb int ret = 0; 5244963Sjb 5344963Sjb if ((mattr == NULL) || (*mattr == NULL)) 5444963Sjb ret = EINVAL; 5544963Sjb else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT) 5644963Sjb ret = EINVAL; 5744963Sjb else 5844963Sjb *prioceiling = (*mattr)->m_ceiling; 5944963Sjb 6044963Sjb return(ret); 6144963Sjb} 6244963Sjb 6344963Sjbint 6471581Sdeischen_pthread_mutexattr_setprioceiling(pthread_mutexattr_t *mattr, int prioceiling) 6544963Sjb{ 6644963Sjb int ret = 0; 6744963Sjb 6844963Sjb if ((mattr == NULL) || (*mattr == NULL)) 6944963Sjb ret = EINVAL; 7044963Sjb else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT) 7144963Sjb ret = EINVAL; 7244963Sjb else 7344963Sjb (*mattr)->m_ceiling = prioceiling; 7444963Sjb 7544963Sjb return(ret); 7644963Sjb} 7744963Sjb 7844963Sjbint 7971581Sdeischen_pthread_mutex_getprioceiling(pthread_mutex_t *mutex, 8071581Sdeischen int *prioceiling) 8144963Sjb{ 8244963Sjb int ret; 8344963Sjb 8444963Sjb if ((mutex == NULL) || (*mutex == NULL)) 8544963Sjb ret = EINVAL; 8644963Sjb else if ((*mutex)->m_protocol != PTHREAD_PRIO_PROTECT) 8744963Sjb ret = EINVAL; 88174112Sdeischen else { 89174112Sdeischen *prioceiling = (*mutex)->m_prio; 90174112Sdeischen ret = 0; 91174112Sdeischen } 92174112Sdeischen return (ret); 9344963Sjb} 9444963Sjb 9544963Sjbint 9671581Sdeischen_pthread_mutex_setprioceiling(pthread_mutex_t *mutex, 9771581Sdeischen int prioceiling, int *old_ceiling) 9844963Sjb{ 9944963Sjb int ret = 0; 100117300Sdavidxu int tmp; 10144963Sjb 10244963Sjb if ((mutex == NULL) || (*mutex == NULL)) 10344963Sjb ret = EINVAL; 10444963Sjb else if ((*mutex)->m_protocol != PTHREAD_PRIO_PROTECT) 10544963Sjb ret = EINVAL; 106113658Sdeischen /* Lock the mutex: */ 107174112Sdeischen else if ((ret = _pthread_mutex_lock(mutex)) == 0) { 108117300Sdavidxu tmp = (*mutex)->m_prio; 109117300Sdavidxu /* Set the new ceiling: */ 110113658Sdeischen (*mutex)->m_prio = prioceiling; 11144963Sjb 112113658Sdeischen /* Unlock the mutex: */ 113174112Sdeischen ret = _pthread_mutex_unlock(mutex); 114117300Sdavidxu 115117300Sdavidxu /* Return the old ceiling: */ 116117300Sdavidxu *old_ceiling = tmp; 11744963Sjb } 11844963Sjb return(ret); 11944963Sjb} 120