1 /* $NetBSD: pthread_misc.c,v 1.13 2009/01/11 02:46:48 christos Exp $ */
4 * Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Nathan J. Williams.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __RCSID("$NetBSD: pthread_misc.c,v 1.13 2009/01/11 02:46:48 christos Exp $");
39 #include <sys/types.h>
41 #include <sys/signal.h>
48 #include "pthread_int.h"
50 int pthread__sched_yield(void);
52 int _sys___sigprocmask14(int, const sigset_t
*, sigset_t
*);
53 int _sys_sched_yield(void);
55 __strong_alias(__libc_thr_sigsetmask
,pthread_sigmask
)
56 __strong_alias(__sigprocmask14
,pthread_sigmask
)
57 __strong_alias(__libc_thr_yield
,pthread__sched_yield
)
60 pthread_getschedparam(pthread_t thread
, int *policy
, struct sched_param
*param
)
63 if (pthread__find(thread
) != 0)
66 if (_sched_getparam(getpid(), thread
->pt_lid
, policy
, param
) < 0)
73 pthread_setschedparam(pthread_t thread
, int policy
,
74 const struct sched_param
*param
)
76 struct sched_param sp
;
78 if (pthread__find(thread
) != 0)
81 memcpy(&sp
, param
, sizeof(struct sched_param
));
82 if (_sched_setparam(getpid(), thread
->pt_lid
, policy
, &sp
) < 0)
89 pthread_getaffinity_np(pthread_t thread
, size_t size
, cpuset_t
*cpuset
)
92 if (pthread__find(thread
) != 0)
95 if (_sched_getaffinity(getpid(), thread
->pt_lid
, size
, cpuset
) < 0)
102 pthread_setaffinity_np(pthread_t thread
, size_t size
, cpuset_t
*cpuset
)
105 if (pthread__find(thread
) != 0)
108 if (_sched_setaffinity(getpid(), thread
->pt_lid
, size
, cpuset
) < 0)
115 pthread_setschedprio(pthread_t thread
, int prio
)
117 struct sched_param sp
;
119 if (pthread__find(thread
) != 0)
122 sp
.sched_priority
= prio
;
123 if (_sched_setparam(getpid(), thread
->pt_lid
, SCHED_NONE
, &sp
) < 0)
130 pthread_kill(pthread_t thread
, int sig
)
133 if ((sig
< 0) || (sig
>= _NSIG
))
135 if (pthread__find(thread
) != 0)
137 if (_lwp_kill(thread
->pt_lid
, sig
))
143 pthread_sigmask(int how
, const sigset_t
*set
, sigset_t
*oset
)
146 if (_sys___sigprocmask14(how
, set
, oset
))
152 pthread__sched_yield(void)
157 self
= pthread__self();
159 /* Memory barrier for unlocked mutex release. */
162 error
= _sys_sched_yield();