]> git.ipfire.org Git - thirdparty/glibc.git/blame - hurd/thread-cancel.c
Mon Aug 14 16:51:13 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
[thirdparty/glibc.git] / hurd / thread-cancel.c
CommitLineData
54da5be3
RM
1/* Thread cancellation support.
2Copyright (C) 1995 Free Software Foundation, Inc.
3This file is part of the GNU C Library.
4
5The GNU C Library is free software; you can redistribute it and/or
6modify it under the terms of the GNU Library General Public License as
7published by the Free Software Foundation; either version 2 of the
8License, or (at your option) any later version.
9
10The GNU C Library is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13Library General Public License for more details.
14
15You should have received a copy of the GNU Library General Public
16License along with the GNU C Library; see the file COPYING.LIB. If
17not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18Cambridge, MA 02139, USA. */
19
20#include <hurd/signal.h>
21#include <hurd/interrupt.h>
22#include <assert.h>
23#include <thread_state.h>
24
25
26/* See hurdsig.c. */
27extern mach_port_t _hurdsig_abort_rpcs (struct hurd_sigstate *ss,
28 int signo, int sigthread,
29 struct machine_thread_all_state *,
30 int *state_change,
31 mach_port_t *reply_port,
32 mach_msg_type_name_t reply_port_type,
33 int untraced);
34
35error_t
36hurd_thread_cancel (thread_t thread)
37{
38 struct hurd_sigstate *ss = _hurd_thread_sigstate (thread);
39 struct machine_thread_all_state state;
40 int state_change;
41 error_t err;
42
43 if (! ss)
44 return EINVAL;
45
46 __spin_lock (&ss->lock);
47 assert (! ss->critical_section);
48 ss->critical_section = 1;
49 err = __thread_suspend (thread);
50 __spin_unlock (&ss->lock);
51
52 if (! err)
53 {
54 /* Set the flag telling the thread its operation is being cancelled. */
55 ss->cancel = 1;
56
57 /* Interrupt any interruptible RPC now in progress. */
58 state.set = 0;
59 _hurdsig_abort_rpcs (ss, 0, 0, &state, &state_change, NULL, 0, 0);
60 if (state_change)
61 err = __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR,
62 (natural_t *) &state.basic,
63 MACHINE_THREAD_STATE_COUNT);
64
65 __thread_resume (thread);
66 }
67
68 _hurd_critical_section_unlock (ss);
69 return err;
70}
71
72
73int
74hurd_check_cancel (void)
75{
76 struct hurd_sigstate *ss = _hurd_self_sigstate ();
77 int cancel;
78
79 __spin_lock (&ss->lock);
80 assert (! ss->critical_section);
81 cancel = ss->cancel;
82 ss->cancel = 0;
83 __spin_unlock (&ss->lock);
84
85 return cancel;
86}