2 * Copyright (c) 2005 David Xu <davidxu@freebsd.org>
3 * Copyright (C) 2003 Daniel M. Eischen <deischen@freebsd.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice unmodified, this list of conditions, and the following
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/types.h>
31 #include <sys/signalvar.h>
32 #include <sys/rtprio.h>
35 #include "thr_private.h"
37 /*#define DEBUG_THREAD_KERN */
38 #ifdef DEBUG_THREAD_KERN
39 #define DBG_MSG stdout_debug
45 * This is called when the first thread (other than the initial
49 _thr_setthreaded(int threaded)
51 if (((threaded == 0) ^ (__isthreaded == 0)) == 0)
54 __isthreaded = threaded;
64 _thr_signal_block(struct pthread *curthread)
68 if (curthread->sigblock > 0) {
69 curthread->sigblock++;
73 SIGDELSET(set, SIGBUS);
74 SIGDELSET(set, SIGILL);
75 SIGDELSET(set, SIGFPE);
76 SIGDELSET(set, SIGSEGV);
77 SIGDELSET(set, SIGTRAP);
78 __sys_sigprocmask(SIG_BLOCK, &set, &curthread->sigmask);
79 curthread->sigblock++;
83 _thr_signal_unblock(struct pthread *curthread)
85 if (--curthread->sigblock == 0)
86 __sys_sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL);
90 _thr_send_sig(struct pthread *thread, int sig)
92 return thr_kill(thread->tid, sig);
96 _thr_assert_lock_level()
98 PANIC("locklevel <= 0");
102 _rtp_to_schedparam(const struct rtprio *rtp, int *policy,
103 struct sched_param *param)
106 case RTP_PRIO_REALTIME:
108 param->sched_priority = RTP_PRIO_MAX - rtp->prio;
111 *policy = SCHED_FIFO;
112 param->sched_priority = RTP_PRIO_MAX - rtp->prio;
115 *policy = SCHED_OTHER;
116 param->sched_priority = 0;
123 _schedparam_to_rtp(int policy, const struct sched_param *param,
128 rtp->type = RTP_PRIO_REALTIME;
129 rtp->prio = RTP_PRIO_MAX - param->sched_priority;
132 rtp->type = RTP_PRIO_FIFO;
133 rtp->prio = RTP_PRIO_MAX - param->sched_priority;
137 rtp->type = RTP_PRIO_NORMAL;
145 _thr_getscheduler(lwpid_t lwpid, int *policy, struct sched_param *param)
150 ret = rtprio_thread(RTP_LOOKUP, lwpid, &rtp);
153 _rtp_to_schedparam(&rtp, policy, param);
158 _thr_setscheduler(lwpid_t lwpid, int policy, const struct sched_param *param)
162 _schedparam_to_rtp(policy, param, &rtp);
163 return (rtprio_thread(RTP_SET, lwpid, &rtp));