1 /* Thread cancellation support.
2 Copyright (C) 1995, 1996 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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
17 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18 Cambridge, MA 02139, USA. */
20 #include <hurd/signal.h>
21 #include <hurd/interrupt.h>
23 #include <thread_state.h>
27 extern mach_port_t
_hurdsig_abort_rpcs (struct hurd_sigstate
*ss
,
28 int signo
, int sigthread
,
29 struct machine_thread_all_state
*,
31 mach_port_t
*reply_port
,
32 mach_msg_type_name_t reply_port_type
,
36 hurd_thread_cancel (thread_t thread
)
38 struct hurd_sigstate
*ss
= _hurd_thread_sigstate (thread
);
39 struct machine_thread_all_state state
;
45 if (ss
== _hurd_self_sigstate ())
46 return EINTR
; /* Bozo. */
48 assert (! __spin_lock_locked (&ss
->critical_section_lock
));
49 __spin_lock (&ss
->critical_section_lock
);
50 __spin_lock (&ss
->lock
);
51 err
= __thread_suspend (thread
);
52 __spin_unlock (&ss
->lock
);
56 /* Set the flag telling the thread its operation is being cancelled. */
59 /* Interrupt any interruptible RPC now in progress. */
61 _hurdsig_abort_rpcs (ss
, 0, 0, &state
, &state_change
, NULL
, 0, 0);
63 err
= __thread_set_state (thread
, MACHINE_THREAD_STATE_FLAVOR
,
64 (natural_t
*) &state
.basic
,
65 MACHINE_THREAD_STATE_COUNT
);
68 /* The code being cancelled has a special wakeup function.
69 Calling this should make the thread wake up and check the
71 (*ss
->cancel_hook
) ();
73 __thread_resume (thread
);
76 _hurd_critical_section_unlock (ss
);
82 hurd_check_cancel (void)
84 struct hurd_sigstate
*ss
= _hurd_self_sigstate ();
87 __spin_lock (&ss
->lock
);
88 assert (! __spin_lock_locked (&ss
->critical_section_lock
));
91 __spin_unlock (&ss
->lock
);