1 //depot/projects/kse/lib/libpthread/thread/thr_sigwait.c#1 - branch change 15154 (text+ko)
3 * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
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, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the author nor the names of any co-contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include "namespace.h"
35 #include <sys/param.h>
36 #include <sys/signalvar.h>
39 #include "un-namespace.h"
40 #include "thr_private.h"
42 int __sigtimedwait(const sigset_t *set, siginfo_t *info,
43 const struct timespec *timeout);
44 int __sigwaitinfo(const sigset_t *set, siginfo_t *info);
45 int __sigwait(const sigset_t *set, int *sig);
46 int _sigtimedwait(const sigset_t *set, siginfo_t *info,
47 const struct timespec *timeout);
48 int _sigwaitinfo(const sigset_t *set, siginfo_t *info);
49 int _sigwait(const sigset_t *set, int *sig);
51 __weak_reference(__sigwait, sigwait);
52 __weak_reference(__sigtimedwait, sigtimedwait);
53 __weak_reference(__sigwaitinfo, sigwaitinfo);
56 lib_sigtimedwait(const sigset_t *set, siginfo_t *info,
57 const struct timespec *timeout)
59 struct pthread *curthread = _get_curthread();
62 struct sigwait_data waitdata;
67 if (curthread->attr.flags & PTHREAD_SCOPE_SYSTEM) {
70 return (__sys_sigtimedwait(set, info, timeout));
74 * Initialize the set of signals that will be waited on:
78 /* These signals can't be waited on. */
79 SIGDELSET(waitset, SIGKILL);
80 SIGDELSET(waitset, SIGSTOP);
83 * POSIX says that the _application_ must explicitly install
84 * a dummy handler for signals that are SIG_IGN in order
85 * to sigwait on them. Note that SIG_IGN signals are left in
86 * the mask because a subsequent sigaction could enable an
90 crit = _kse_critical_enter();
91 KSE_SCHED_LOCK(curthread->kse, curthread->kseg);
92 for (i = 1; i <= _SIG_MAXSIG; ++i) {
93 if (SIGISMEMBER(waitset, i) &&
94 SIGISMEMBER(curthread->sigpend, i)) {
95 SIGDELSET(curthread->sigpend, i);
96 siginfo = curthread->siginfo[i - 1];
97 KSE_SCHED_UNLOCK(curthread->kse,
99 _kse_critical_leave(crit);
104 curthread->timeout = 0;
105 curthread->interrupted = 0;
106 _thr_set_timeout(timeout);
107 /* Wait for a signal: */
108 siginfo.si_signo = 0;
109 waitdata.waitset = &waitset;
110 waitdata.siginfo = &siginfo;
111 curthread->data.sigwait = &waitdata;
112 THR_SET_STATE(curthread, PS_SIGWAIT);
113 _thr_sched_switch_unlocked(curthread);
115 * Return the signal number to the caller:
117 if (siginfo.si_signo > 0) {
118 ret = siginfo.si_signo;
120 if (curthread->interrupted)
122 else if (curthread->timeout)
126 curthread->timeout = 0;
127 curthread->interrupted = 0;
129 * Probably unnecessary, but since it's in a union struct
130 * we don't know how it could be used in the future.
132 curthread->data.sigwait = NULL;
135 if (ret > 0 && info != NULL)
142 __sigtimedwait(const sigset_t *set, siginfo_t *info,
143 const struct timespec * timeout)
145 struct pthread *curthread = _get_curthread();
148 _thr_cancel_enter(curthread);
149 ret = lib_sigtimedwait(set, info, timeout);
150 _thr_cancel_leave(curthread, 1);
154 int _sigtimedwait(const sigset_t *set, siginfo_t *info,
155 const struct timespec * timeout)
157 return lib_sigtimedwait(set, info, timeout);
161 __sigwaitinfo(const sigset_t *set, siginfo_t *info)
163 struct pthread *curthread = _get_curthread();
166 _thr_cancel_enter(curthread);
167 ret = lib_sigtimedwait(set, info, NULL);
168 _thr_cancel_leave(curthread, 1);
173 _sigwaitinfo(const sigset_t *set, siginfo_t *info)
175 return lib_sigtimedwait(set, info, NULL);
179 __sigwait(const sigset_t *set, int *sig)
181 struct pthread *curthread = _get_curthread();
184 _thr_cancel_enter(curthread);
185 ret = lib_sigtimedwait(set, NULL, NULL);
192 _thr_cancel_leave(curthread, 1);
197 _sigwait(const sigset_t *set, int *sig)
201 ret = lib_sigtimedwait(set, NULL, NULL);