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 <sys/param.h>
34 #include <sys/signalvar.h>
37 #include "thr_private.h"
39 LT10_COMPAT_PRIVATE(__sigwait);
40 LT10_COMPAT_PRIVATE(_sigwait);
41 LT10_COMPAT_DEFAULT(sigwait);
42 LT10_COMPAT_PRIVATE(__sigtimedwait);
43 LT10_COMPAT_PRIVATE(_sigtimedwait);
44 LT10_COMPAT_DEFAULT(sigtimedwait);
45 LT10_COMPAT_PRIVATE(__sigwaitinfo);
46 LT10_COMPAT_PRIVATE(_sigwaitinfo);
47 LT10_COMPAT_DEFAULT(sigwaitinfo);
49 __weak_reference(__sigwait, sigwait);
50 __weak_reference(__sigtimedwait, sigtimedwait);
51 __weak_reference(__sigwaitinfo, sigwaitinfo);
54 lib_sigtimedwait(const sigset_t *set, siginfo_t *info,
55 const struct timespec * timeout)
57 struct pthread *curthread = _get_curthread();
60 struct sigwait_data waitdata;
65 if (curthread->attr.flags & PTHREAD_SCOPE_SYSTEM) {
68 return (__sys_sigtimedwait((sigset_t *)set, info,
69 (struct timespec *)timeout));
73 * Initialize the set of signals that will be waited on:
77 /* These signals can't be waited on. */
78 SIGDELSET(waitset, SIGKILL);
79 SIGDELSET(waitset, SIGSTOP);
82 * POSIX says that the _application_ must explicitly install
83 * a dummy handler for signals that are SIG_IGN in order
84 * to sigwait on them. Note that SIG_IGN signals are left in
85 * the mask because a subsequent sigaction could enable an
89 crit = _kse_critical_enter();
90 KSE_SCHED_LOCK(curthread->kse, curthread->kseg);
91 for (i = 1; i <= _SIG_MAXSIG; ++i) {
92 if (SIGISMEMBER(waitset, i) &&
93 SIGISMEMBER(curthread->sigpend, i)) {
94 SIGDELSET(curthread->sigpend, i);
95 siginfo = curthread->siginfo[i - 1];
96 KSE_SCHED_UNLOCK(curthread->kse,
98 _kse_critical_leave(crit);
103 curthread->timeout = 0;
104 curthread->interrupted = 0;
105 _thr_set_timeout(timeout);
106 /* Wait for a signal: */
107 siginfo.si_signo = 0;
108 waitdata.waitset = &waitset;
109 waitdata.siginfo = &siginfo;
110 curthread->data.sigwait = &waitdata;
111 THR_SET_STATE(curthread, PS_SIGWAIT);
112 _thr_sched_switch_unlocked(curthread);
114 * Return the signal number to the caller:
116 if (siginfo.si_signo > 0) {
117 ret = siginfo.si_signo;
119 if (curthread->interrupted)
121 else if (curthread->timeout)
125 curthread->timeout = 0;
126 curthread->interrupted = 0;
128 * Probably unnecessary, but since it's in a union struct
129 * we don't know how it could be used in the future.
131 curthread->data.sigwait = NULL;
134 if (ret > 0 && info != NULL)
141 __sigtimedwait(const sigset_t *set, siginfo_t *info,
142 const struct timespec * timeout)
144 struct pthread *curthread = _get_curthread();
147 _thr_cancel_enter(curthread);
148 ret = lib_sigtimedwait(set, info, timeout);
149 _thr_cancel_leave(curthread, 1);
153 int _sigtimedwait(const sigset_t *set, siginfo_t *info,
154 const struct timespec * timeout)
156 return lib_sigtimedwait(set, info, timeout);
160 __sigwaitinfo(const sigset_t *set, siginfo_t *info)
162 struct pthread *curthread = _get_curthread();
165 _thr_cancel_enter(curthread);
166 ret = lib_sigtimedwait(set, info, NULL);
167 _thr_cancel_leave(curthread, 1);
172 _sigwaitinfo(const sigset_t *set, siginfo_t *info)
174 return lib_sigtimedwait(set, info, NULL);
178 __sigwait(const sigset_t *set, int *sig)
180 struct pthread *curthread = _get_curthread();
183 _thr_cancel_enter(curthread);
184 ret = lib_sigtimedwait(set, NULL, NULL);
191 _thr_cancel_leave(curthread, 1);
196 _sigwait(const sigset_t *set, int *sig)
200 ret = lib_sigtimedwait(set, NULL, NULL);