1a091d823SDavid Xu /* 2a091d823SDavid Xu * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>. 3a091d823SDavid Xu * All rights reserved. 4a091d823SDavid Xu * 5a091d823SDavid Xu * Redistribution and use in source and binary forms, with or without 6a091d823SDavid Xu * modification, are permitted provided that the following conditions 7a091d823SDavid Xu * are met: 8a091d823SDavid Xu * 1. Redistributions of source code must retain the above copyright 9a091d823SDavid Xu * notice, this list of conditions and the following disclaimer. 10a091d823SDavid Xu * 2. Redistributions in binary form must reproduce the above copyright 11a091d823SDavid Xu * notice, this list of conditions and the following disclaimer in the 12a091d823SDavid Xu * documentation and/or other materials provided with the distribution. 13a091d823SDavid Xu * 3. All advertising materials mentioning features or use of this software 14a091d823SDavid Xu * must display the following acknowledgement: 15a091d823SDavid Xu * This product includes software developed by Daniel Eischen. 16a091d823SDavid Xu * 4. Neither the name of the author nor the names of any co-contributors 17a091d823SDavid Xu * may be used to endorse or promote products derived from this software 18a091d823SDavid Xu * without specific prior written permission. 19a091d823SDavid Xu * 20a091d823SDavid Xu * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND 21a091d823SDavid Xu * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22a091d823SDavid Xu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23a091d823SDavid Xu * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 24a091d823SDavid Xu * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25a091d823SDavid Xu * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26a091d823SDavid Xu * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27a091d823SDavid Xu * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28a091d823SDavid Xu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29a091d823SDavid Xu * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30a091d823SDavid Xu * SUCH DAMAGE. 31a091d823SDavid Xu * 32a091d823SDavid Xu * $FreeBSD$ 33a091d823SDavid Xu */ 34a091d823SDavid Xu 3537a6356bSDavid Xu #include "namespace.h" 36a091d823SDavid Xu #include <errno.h> 37a091d823SDavid Xu #include <pthread.h> 3837a6356bSDavid Xu #include "un-namespace.h" 39a091d823SDavid Xu 40a091d823SDavid Xu #include "thr_private.h" 41a091d823SDavid Xu 42a091d823SDavid Xu __weak_reference(_pthread_getschedparam, pthread_getschedparam); 43a091d823SDavid Xu 44a091d823SDavid Xu int 45a091d823SDavid Xu _pthread_getschedparam(pthread_t pthread, int *policy, 46a091d823SDavid Xu struct sched_param *param) 47a091d823SDavid Xu { 48a091d823SDavid Xu struct pthread *curthread = _get_curthread(); 497b4f8f03SDavid Xu int ret; 50a091d823SDavid Xu 517b4f8f03SDavid Xu if (policy == NULL || param == NULL) 527b4f8f03SDavid Xu return (EINVAL); 537b4f8f03SDavid Xu 547b4f8f03SDavid Xu if (pthread == curthread) { 55a091d823SDavid Xu /* 56a091d823SDavid Xu * Avoid searching the thread list when it is the current 57a091d823SDavid Xu * thread. 58a091d823SDavid Xu */ 597b4f8f03SDavid Xu THR_LOCK(curthread); 607b4f8f03SDavid Xu 617b4f8f03SDavid Xu /* 627b4f8f03SDavid Xu * XXX Here we need two separated syscalls, atomic is only 637b4f8f03SDavid Xu * guaranteed in thread library, a new syscall is needed. 647b4f8f03SDavid Xu */ 657b4f8f03SDavid Xu 667b4f8f03SDavid Xu *policy = sched_getscheduler((pid_t)curthread->tid); 677b4f8f03SDavid Xu if (*policy == -1) 687b4f8f03SDavid Xu ret = errno; 697b4f8f03SDavid Xu else { 707b4f8f03SDavid Xu ret = sched_getparam((pid_t)curthread->tid, param); 717b4f8f03SDavid Xu if (ret == -1) 727b4f8f03SDavid Xu ret = errno; 737b4f8f03SDavid Xu } 747b4f8f03SDavid Xu THR_UNLOCK(curthread); 75a091d823SDavid Xu } 76a091d823SDavid Xu /* Find the thread in the list of active threads. */ 77a091d823SDavid Xu else if ((ret = _thr_ref_add(curthread, pthread, /*include dead*/0)) 78a091d823SDavid Xu == 0) { 79a091d823SDavid Xu THR_THREAD_LOCK(curthread, pthread); 807b4f8f03SDavid Xu *policy = sched_getscheduler((pid_t)pthread->tid); 817b4f8f03SDavid Xu if (*policy == -1) 827b4f8f03SDavid Xu ret = errno; 837b4f8f03SDavid Xu else { 847b4f8f03SDavid Xu ret = sched_getparam((pid_t)pthread->tid, param); 857b4f8f03SDavid Xu if (ret == -1) 867b4f8f03SDavid Xu ret = errno; 877b4f8f03SDavid Xu } 88a091d823SDavid Xu THR_THREAD_UNLOCK(curthread, pthread); 89a091d823SDavid Xu _thr_ref_delete(curthread, pthread); 90a091d823SDavid Xu } 91a091d823SDavid Xu return (ret); 92a091d823SDavid Xu } 93