]> git.ipfire.org Git - thirdparty/glibc.git/blame - hurd/thread-cancel.c
Update to 2.1.x development version
[thirdparty/glibc.git] / hurd / thread-cancel.c
CommitLineData
54da5be3 1/* Thread cancellation support.
c84142e8
UD
2 Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
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
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
54da5be3
RM
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,
8f0c527e 28 int signo, int sigthread,
54da5be3
RM
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;
7752137a
RM
45 if (ss == _hurd_self_sigstate ())
46 return EINTR; /* Bozo. */
54da5be3 47
8f0c527e
RM
48 assert (! __spin_lock_locked (&ss->critical_section_lock));
49 __spin_lock (&ss->critical_section_lock);
54da5be3 50 __spin_lock (&ss->lock);
54da5be3
RM
51 err = __thread_suspend (thread);
52 __spin_unlock (&ss->lock);
53
54 if (! err)
55 {
56 /* Set the flag telling the thread its operation is being cancelled. */
57 ss->cancel = 1;
58
59 /* Interrupt any interruptible RPC now in progress. */
60 state.set = 0;
61 _hurdsig_abort_rpcs (ss, 0, 0, &state, &state_change, NULL, 0, 0);
8f0c527e 62 if (state_change)
54da5be3
RM
63 err = __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR,
64 (natural_t *) &state.basic,
65 MACHINE_THREAD_STATE_COUNT);
66
3cf595e5
RM
67 if (ss->cancel_hook)
68 /* The code being cancelled has a special wakeup function.
69 Calling this should make the thread wake up and check the
70 cancellation flag. */
71 (*ss->cancel_hook) ();
72
54da5be3
RM
73 __thread_resume (thread);
74 }
75
76 _hurd_critical_section_unlock (ss);
77 return err;
78}
79
80
81int
82hurd_check_cancel (void)
83{
84 struct hurd_sigstate *ss = _hurd_self_sigstate ();
85 int cancel;
86
87 __spin_lock (&ss->lock);
8f0c527e 88 assert (! __spin_lock_locked (&ss->critical_section_lock));
54da5be3
RM
89 cancel = ss->cancel;
90 ss->cancel = 0;
91 __spin_unlock (&ss->lock);
92
93 return cancel;
94}