Replace FSF snail mail address with URLs.
[glibc.git] / sysdeps / mach / hurd / sigsuspend.c
blob3e611f80afc4b662af3b8eef552e08b1fbcd1179
1 /* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2002, 2007
2 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #include <errno.h>
21 #include <hurd.h>
22 #include <hurd/signal.h>
23 #include <hurd/msg.h>
25 /* Change the set of blocked signals to SET,
26 wait until a signal arrives, and restore the set of blocked signals. */
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;
83 libc_hidden_def (__sigsuspend)
84 strong_alias (__sigsuspend, sigsuspend_not_cancel)
85 weak_alias (__sigsuspend, sigsuspend)