]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/mach/hurd/sigsuspend.c
sunrpc: Rewrite with explicit TLS access using __thread
[thirdparty/glibc.git] / sysdeps / mach / hurd / sigsuspend.c
CommitLineData
b168057a 1/* Copyright (C) 1991-2015 Free Software Foundation, Inc.
3dadfa7e 2
ebbad4cc 3 This file is part of the GNU C Library.
28f540f4 4
ebbad4cc 5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
28f540f4 9
ebbad4cc
UD
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 13 Lesser General Public License for more details.
28f540f4 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
28f540f4 18
28f540f4
RM
19#include <errno.h>
20#include <hurd.h>
21#include <hurd/signal.h>
22#include <hurd/msg.h>
23
24/* Change the set of blocked signals to SET,
25 wait until a signal arrives, and restore the set of blocked signals. */
26int
a9ddb793 27__sigsuspend (set)
ebbad4cc 28 const sigset_t *set;
28f540f4
RM
29{
30 struct hurd_sigstate *ss;
31 sigset_t newmask, oldmask, pending;
32 mach_port_t wait;
33 mach_msg_header_t msg;
34
35 if (set != NULL)
36 /* Crash before locking. */
37 newmask = *set;
38
39 /* Get a fresh port we will wait on. */
40 wait = __mach_reply_port ();
41
42 ss = _hurd_self_sigstate ();
43
44 __spin_lock (&ss->lock);
45
46 oldmask = ss->blocked;
47 if (set != NULL)
48 /* Change to the new blocked signal mask. */
49 ss->blocked = newmask & ~_SIG_CANT_MASK;
50
51 /* Notice if any pending signals just became unblocked. */
52 pending = ss->pending & ~ss->blocked;
53
54 /* Tell the signal thread to message us when a signal arrives. */
55 ss->suspended = wait;
56 __spin_unlock (&ss->lock);
57
58 if (pending)
59 /* Tell the signal thread to check for pending signals. */
8f0c527e 60 __msg_sig_post (_hurd_msgport, 0, 0, __mach_task_self ());
28f540f4
RM
61
62 /* Wait for the signal thread's message. */
63 __mach_msg (&msg, MACH_RCV_MSG, 0, sizeof (msg), wait,
64 MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
65 __mach_port_destroy (__mach_task_self (), wait);
66
67 __spin_lock (&ss->lock);
68 ss->blocked = oldmask; /* Restore the old mask. */
69 pending = ss->pending & ~ss->blocked; /* Again check for pending signals. */
70 __spin_unlock (&ss->lock);
71
72 if (pending)
73 /* Tell the signal thread to check for pending signals. */
8f0c527e
RM
74 __msg_sig_post (_hurd_msgport, 0, 0, __mach_task_self ());
75
28f540f4
RM
76 /* We've been interrupted! And a good thing, too.
77 Otherwise we'd never return.
78 That's right; this function always returns an error. */
79 errno = EINTR;
80 return -1;
81}
37ba7d66 82libc_hidden_def (__sigsuspend)
610903b0 83strong_alias (__sigsuspend, sigsuspend_not_cancel)
a9ddb793 84weak_alias (__sigsuspend, sigsuspend)