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. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by John Birrell.
17 * 4. Neither the name of the author nor the names of any co-contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <sys/param.h>
37 #include <sys/signalvar.h>
40 #include "thr_private.h"
42 __weak_reference(__sigwait, sigwait);
43 __weak_reference(__sigtimedwait, sigtimedwait);
44 __weak_reference(__sigwaitinfo, sigwaitinfo);
47 lib_sigtimedwait(const sigset_t *set, siginfo_t *info,
48 const struct timespec * timeout)
50 struct pthread *curthread = _get_curthread();
53 struct sigwait_data waitdata;
58 if (curthread->attr.flags & PTHREAD_SCOPE_SYSTEM) {
61 return (__sys_sigtimedwait((sigset_t *)set, info,
62 (struct timespec *)timeout));
66 * Initialize the set of signals that will be waited on:
70 /* These signals can't be waited on. */
71 SIGDELSET(waitset, SIGKILL);
72 SIGDELSET(waitset, SIGSTOP);
75 * POSIX says that the _application_ must explicitly install
76 * a dummy handler for signals that are SIG_IGN in order
77 * to sigwait on them. Note that SIG_IGN signals are left in
78 * the mask because a subsequent sigaction could enable an
82 crit = _kse_critical_enter();
83 KSE_SCHED_LOCK(curthread->kse, curthread->kseg);
84 for (i = 1; i <= _SIG_MAXSIG; ++i) {
85 if (SIGISMEMBER(waitset, i) &&
86 SIGISMEMBER(curthread->sigpend, i)) {
87 SIGDELSET(curthread->sigpend, i);
88 siginfo = curthread->siginfo[i - 1];
89 KSE_SCHED_UNLOCK(curthread->kse,
91 _kse_critical_leave(crit);
96 curthread->timeout = 0;
97 curthread->interrupted = 0;
98 _thr_set_timeout(timeout);
99 /* Wait for a signal: */
100 siginfo.si_signo = 0;
101 waitdata.waitset = &waitset;
102 waitdata.siginfo = &siginfo;
103 curthread->data.sigwait = &waitdata;
104 THR_SET_STATE(curthread, PS_SIGWAIT);
105 _thr_sched_switch_unlocked(curthread);
107 * Return the signal number to the caller:
109 if (siginfo.si_signo > 0) {
110 ret = siginfo.si_signo;
112 if (curthread->interrupted)
114 else if (curthread->timeout)
118 curthread->timeout = 0;
119 curthread->interrupted = 0;
121 * Probably unnecessary, but since it's in a union struct
122 * we don't know how it could be used in the future.
124 curthread->data.sigwait = NULL;
127 if (ret > 0 && info != NULL)
134 __sigtimedwait(const sigset_t *set, siginfo_t *info,
135 const struct timespec * timeout)
137 struct pthread *curthread = _get_curthread();
140 _thr_cancel_enter(curthread);
141 ret = lib_sigtimedwait(set, info, timeout);
142 _thr_cancel_leave(curthread, 1);
146 int _sigtimedwait(const sigset_t *set, siginfo_t *info,
147 const struct timespec * timeout)
149 return lib_sigtimedwait(set, info, timeout);
153 __sigwaitinfo(const sigset_t *set, siginfo_t *info)
155 struct pthread *curthread = _get_curthread();
158 _thr_cancel_enter(curthread);
159 ret = lib_sigtimedwait(set, info, NULL);
160 _thr_cancel_leave(curthread, 1);
165 _sigwaitinfo(const sigset_t *set, siginfo_t *info)
167 return lib_sigtimedwait(set, info, NULL);
171 __sigwait(const sigset_t *set, int *sig)
173 struct pthread *curthread = _get_curthread();
176 _thr_cancel_enter(curthread);
177 ret = lib_sigtimedwait(set, NULL, NULL);
184 _thr_cancel_leave(curthread, 1);
189 _sigwait(const sigset_t *set, int *sig)
193 ret = lib_sigtimedwait(set, NULL, NULL);