1
/* sigwaiter.c - Signal handling functions.
2
Copyright (C) 2008 Free Software Foundation, Inc.
3
Written by Neal H. Walfield <neal@gnu.org>.
5
This file is part of the GNU Hurd.
7
The GNU Hurd is free software; you can redistribute it and/or
8
modify it under the terms of the GNU Lesser General Public License
9
as published by the Free Software Foundation; either version 3 of
10
the License, or (at your option) any later version.
12
The GNU Hurd is distributed in the hope that it will be useful, but
13
WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
Lesser General Public License for more details.
17
You should have received a copy of the GNU Lesser General Public
18
License along with this program. If not, see
19
<http://www.gnu.org/licenses/>. */
21
#include "sig-internal.h"
23
#include <hurd/futex.h>
25
struct sigwaiter *sigwaiters;
28
sigwaiter_block (struct signal_state *ss, const sigset_t *restrict set)
30
assert (pthread_mutex_trylock (&sig_lock) == EBUSY);
31
assert (pthread_mutex_trylock (&ss->lock) == EBUSY);
33
assert (! ss->sigwaiter);
35
struct sigwaiter waiter;
37
waiter.next = sigwaiters;
40
assert (! waiter.next->prev);
41
waiter.next->prev = &waiter;
47
waiter.info.si_signo = 0;
48
waiter.signals = *set;
50
ss->sigwaiter = &waiter;
52
pthread_mutex_unlock (&ss->lock);
53
pthread_mutex_unlock (&sig_lock);
55
futex_wait (&waiter.info.si_signo, 0);
58
pthread_mutex_lock (&ss->lock);
60
pthread_mutex_unlock (&ss->lock);
63
assert (waiter.info.si_signo);
68
sigwaiter_unblock (struct sigwaiter *waiter)
70
assert (pthread_mutex_trylock (&sig_lock) == EBUSY);
71
assert (pthread_mutex_trylock (&waiter->ss->lock) == EBUSY);
73
struct sigwaiter *prev = waiter->prev;
74
struct sigwaiter *next = waiter->next;
84
sigdelset (&process_pending, waiter->info.si_signo);
85
sigdelset (&waiter->ss->pending, waiter->info.si_signo);
87
pthread_mutex_unlock (&waiter->ss->lock);
88
pthread_mutex_unlock (&sig_lock);
90
futex_wake (&waiter->info.si_signo, 1);