1df57947fSPedro F. Giffuni /*- 2df57947fSPedro F. Giffuni * SPDX-License-Identifier: BSD-4-Clause 3df57947fSPedro F. Giffuni * 4a091d823SDavid Xu * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>. 5a091d823SDavid Xu * All rights reserved. 6a091d823SDavid Xu * 7a091d823SDavid Xu * Redistribution and use in source and binary forms, with or without 8a091d823SDavid Xu * modification, are permitted provided that the following conditions 9a091d823SDavid Xu * are met: 10a091d823SDavid Xu * 1. Redistributions of source code must retain the above copyright 11a091d823SDavid Xu * notice, this list of conditions and the following disclaimer. 12a091d823SDavid Xu * 2. Redistributions in binary form must reproduce the above copyright 13a091d823SDavid Xu * notice, this list of conditions and the following disclaimer in the 14a091d823SDavid Xu * documentation and/or other materials provided with the distribution. 15a091d823SDavid Xu * 3. All advertising materials mentioning features or use of this software 16a091d823SDavid Xu * must display the following acknowledgement: 17a091d823SDavid Xu * This product includes software developed by Daniel Eischen. 18a091d823SDavid Xu * 4. Neither the name of the author nor the names of any co-contributors 19a091d823SDavid Xu * may be used to endorse or promote products derived from this software 20a091d823SDavid Xu * without specific prior written permission. 21a091d823SDavid Xu * 22a091d823SDavid Xu * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND 23a091d823SDavid Xu * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24a091d823SDavid Xu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25a091d823SDavid Xu * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 26a091d823SDavid Xu * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27a091d823SDavid Xu * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28a091d823SDavid Xu * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29a091d823SDavid Xu * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30a091d823SDavid Xu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31a091d823SDavid Xu * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32a091d823SDavid Xu * SUCH DAMAGE. 33a091d823SDavid Xu */ 34a091d823SDavid Xu 3532793011SKonstantin Belousov #include <sys/cdefs.h> 3632793011SKonstantin Belousov __FBSDID("$FreeBSD$"); 3732793011SKonstantin Belousov 3837a6356bSDavid Xu #include "namespace.h" 39e6747c7cSDavid Xu #include <sys/types.h> 40e6747c7cSDavid Xu #include <sys/rtprio.h> 41a091d823SDavid Xu #include <errno.h> 42a091d823SDavid Xu #include <pthread.h> 4337a6356bSDavid Xu #include "un-namespace.h" 44a091d823SDavid Xu 45a091d823SDavid Xu #include "thr_private.h" 46a091d823SDavid Xu 47a091d823SDavid Xu __weak_reference(_pthread_getschedparam, pthread_getschedparam); 48a091d823SDavid Xu 49a091d823SDavid Xu int 50*b6413b6dSPedro F. Giffuni _pthread_getschedparam(pthread_t pthread, int * __restrict policy, 51*b6413b6dSPedro F. Giffuni struct sched_param * __restrict param) 52a091d823SDavid Xu { 53a091d823SDavid Xu struct pthread *curthread = _get_curthread(); 545674256cSDavid Xu int ret = 0; 55a091d823SDavid Xu 567b4f8f03SDavid Xu if (policy == NULL || param == NULL) 577b4f8f03SDavid Xu return (EINVAL); 587b4f8f03SDavid Xu 59a091d823SDavid Xu /* 60a091d823SDavid Xu * Avoid searching the thread list when it is the current 61a091d823SDavid Xu * thread. 62a091d823SDavid Xu */ 63340e384dSDavid Xu if (pthread == curthread) 647b4f8f03SDavid Xu THR_LOCK(curthread); 65340e384dSDavid Xu else if ((ret = _thr_find_thread(curthread, pthread, /*include dead*/0))) 66340e384dSDavid Xu return (ret); 67e2dc286cSDavid Xu *policy = pthread->attr.sched_policy; 68e2dc286cSDavid Xu param->sched_priority = pthread->attr.prio; 69a091d823SDavid Xu THR_THREAD_UNLOCK(curthread, pthread); 70a091d823SDavid Xu return (ret); 71a091d823SDavid Xu } 72