Update.
[glibc.git] / sysdeps / mach / hurd / sigsuspend.c
blobec7849557a08dd7c9a1e8d185df4eed67a643842
1 /* Copyright (C) 1991, 92, 93, 94, 95, 96, 97 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 Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 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 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 #include <errno.h>
20 #include <hurd.h>
21 #include <hurd/signal.h>
22 #include <hurd/msg.h>
24 /* Change the set of blocked signals to SET,
25 wait until a signal arrives, and restore the set of blocked signals. */
26 /* XXX should be __sigsuspend ? */
27 int
28 sigsuspend (set)
29 const sigset_t *set;
31 struct hurd_sigstate *ss;
32 sigset_t newmask, oldmask, pending;
33 mach_port_t wait;
34 mach_msg_header_t msg;
36 if (set != NULL)
37 /* Crash before locking. */
38 newmask = *set;
40 /* Get a fresh port we will wait on. */
41 wait = __mach_reply_port ();
43 ss = _hurd_self_sigstate ();
45 __spin_lock (&ss->lock);
47 oldmask = ss->blocked;
48 if (set != NULL)
49 /* Change to the new blocked signal mask. */
50 ss->blocked = newmask & ~_SIG_CANT_MASK;
52 /* Notice if any pending signals just became unblocked. */
53 pending = ss->pending & ~ss->blocked;
55 /* Tell the signal thread to message us when a signal arrives. */
56 ss->suspended = wait;
57 __spin_unlock (&ss->lock);
59 if (pending)
60 /* Tell the signal thread to check for pending signals. */
61 __msg_sig_post (_hurd_msgport, 0, 0, __mach_task_self ());
63 /* Wait for the signal thread's message. */
64 __mach_msg (&msg, MACH_RCV_MSG, 0, sizeof (msg), wait,
65 MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
66 __mach_port_destroy (__mach_task_self (), wait);
68 __spin_lock (&ss->lock);
69 ss->blocked = oldmask; /* Restore the old mask. */
70 pending = ss->pending & ~ss->blocked; /* Again check for pending signals. */
71 __spin_unlock (&ss->lock);
73 if (pending)
74 /* Tell the signal thread to check for pending signals. */
75 __msg_sig_post (_hurd_msgport, 0, 0, __mach_task_self ());
77 /* We've been interrupted! And a good thing, too.
78 Otherwise we'd never return.
79 That's right; this function always returns an error. */
80 errno = EINTR;
81 return -1;