pthread_misc.c revision 1.2 1 /* $NetBSD: pthread_misc.c,v 1.2 2007/08/16 13:54:17 ad Exp $ */
2
3 /*-
4 * Copyright (c) 2001, 2006, 2007 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Nathan J. Williams.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __RCSID("$NetBSD: pthread_misc.c,v 1.2 2007/08/16 13:54:17 ad Exp $");
41
42 #include <sys/types.h>
43 #include <sys/signal.h>
44 #include <sys/time.h>
45
46 #include <errno.h>
47 #include <lwp.h>
48
49 #include "pthread.h"
50 #include "pthread_int.h"
51
52 int _sys___sigprocmask14(int, const sigset_t *, sigset_t *);
53 int _sys_nanosleep(const struct timespec *, struct timespec *);
54
55 __strong_alias(_nanosleep, nanosleep)
56 __strong_alias(__libc_thr_sigsetmask,pthread_sigmask)
57 __strong_alias(__sigprocmask14,pthread_sigmask)
58 __strong_alias(__libc_thr_yield,_sys_sched_yield)
59
60 /*ARGSUSED*/
61 int
62 pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param)
63 {
64 if (param == NULL || policy == NULL)
65 return EINVAL;
66 param->sched_priority = 0;
67 *policy = SCHED_RR;
68 return 0;
69 }
70
71 /*ARGSUSED*/
72 int
73 pthread_setschedparam(pthread_t thread, int policy,
74 const struct sched_param *param)
75 {
76 if (param == NULL || policy < SCHED_FIFO || policy > SCHED_RR)
77 return EINVAL;
78 if (param->sched_priority > 0 || policy != SCHED_RR)
79 return ENOTSUP;
80 return 0;
81 }
82
83 int
84 pthread_kill(pthread_t thread, int sig)
85 {
86
87 if ((sig < 0) || (sig >= _NSIG))
88 return EINVAL;
89 if (pthread__find(thread) != 0)
90 return ESRCH;
91
92 return _lwp_kill(thread->pt_lid, sig);
93 }
94
95 int
96 pthread_sigmask(int how, const sigset_t *set, sigset_t *oset)
97 {
98
99 return _sys___sigprocmask14(how, set, oset);
100 }
101
102 int
103 nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
104 {
105
106 /*
107 * For now, just nanosleep. In the future, maybe pass a ucontext_t
108 * to _lwp_nanosleep() and allow it to recycle our kernel stack.
109 */
110 return _sys_nanosleep(rqtp, rmtp);
111 }
112