1 /* Copyright (C) 1996,97,2001,02 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 #include <hurd/signal.h>
23 #include <hurd/sigpreempt.h>
26 /* Select any of pending signals from SET or wait for any to arrive. */
28 __sigwait (const sigset_t
*set
, int *sig
)
30 struct hurd_sigstate
*ss
;
33 struct hurd_signal_preemptor preemptor
;
36 mach_msg_header_t msg
;
39 preempt_fun (struct hurd_signal_preemptor
*pe
,
40 struct hurd_sigstate
*ss
,
42 struct hurd_signal_detail
*detail
)
45 /* We've already been run; don't interfere. */
50 /* Make sure this is all kosher */
51 assert (__sigismember (&mask
, signo
));
53 /* Make sure this signal is unblocked */
54 __sigdelset (&ss
->blocked
, signo
);
62 assert (sig
== signo
);
66 wait
= __mach_reply_port ();
69 /* Crash before locking */
72 __sigemptyset (&mask
);
74 ss
= _hurd_self_sigstate ();
75 __spin_lock (&ss
->lock
);
77 /* See if one of these signals is currently pending. */
78 __sigandset (&ready
, &ss
->pending
, &mask
);
79 if (! __sigisemptyset (&ready
))
81 for (signo
= 1; signo
< NSIG
; signo
++)
82 if (__sigismember (&ready
, signo
))
84 __sigdelset (&ready
, signo
);
87 /* Huh? Where'd it go? */
91 /* Wait for one of them to show up. */
95 /* Make the preemptor */
96 preemptor
.signals
= mask
;
99 preemptor
.preemptor
= preempt_fun
;
100 preemptor
.handler
= handler
;
102 /* Install this preemptor */
103 preemptor
.next
= ss
->preemptors
;
104 ss
->preemptors
= &preemptor
;
106 __spin_unlock (&ss
->lock
);
109 __mach_msg (&msg
, MACH_RCV_MSG
, 0, sizeof (msg
), wait
,
110 MACH_MSG_TIMEOUT_NONE
, MACH_PORT_NULL
);
117 __spin_lock (&ss
->lock
);
119 /* Delete our preemptor. */
120 assert (ss
->preemptors
== &preemptor
);
121 ss
->preemptors
= preemptor
.next
;
126 spin_unlock (&ss
->lock
);
128 __mach_port_destroy (__mach_task_self (), wait
);
133 weak_alias (__sigwait
, sigwait
)