aboutsummaryrefslogtreecommitdiff
path: root/hurd/thread-cancel.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1995-08-14 22:49:23 +0000
committerRoland McGrath <roland@gnu.org>1995-08-14 22:49:23 +0000
commit54da5be39c868b55c234c23bb38eb42babc084d7 (patch)
tree64fe7cd0dfeaef3a8b6f469f3a7a83a3a974067a /hurd/thread-cancel.c
parent047f282dd7e83f24abce284dcc9d2d78cab42f9b (diff)
downloadglibc-54da5be39c868b55c234c23bb38eb42babc084d7.zip
glibc-54da5be39c868b55c234c23bb38eb42babc084d7.tar.gz
glibc-54da5be39c868b55c234c23bb38eb42babc084d7.tar.bz2
Mon Aug 14 16:51:13 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
* hurd/thread-cancel.c: New file. * sysdeps/mach/hurd/i386/trampoline.c (_hurd_setup_sighandler): In rpc_wait case, frob mach_msg args to set timeout on receive. (_hurdsig_rcv_interrupted_p): Function removed. * sysdeps/mach/hurd/alpha/trampoline.c: Likewise. * sysdeps/mach/hurd/hppa/trampoline.c: Likewise. * sysdeps/mach/hurd/mips/trampoline.c: Likewise. * hurd/intr-msg.c: New file. * hurd/hurd/signal.h (struct hurd_sigstate): New member `cancel'. (_hurdsig_rcv_interrupted_p): Declaration removed. (HURD_EINTR_RPC): Macro removed. (_hurd_longjmp_thread_state, _hurd_interrupted_rpc_timeout): Declare these. * hurd/intr-rpc.h: New file. * hurd/intr-rpc.defs: Just import intr-rpc.h. * hurd/hurdsig.c (_hurd_interrupted_rpc_timeout): New variable. (interrupted_reply_port_location): Take new flag arg; only catch faults if it's set. (abort_rpcs): Rename to _hurdsig_abort_rpcs; take same new flag arg. No longer use _hurdsig_rcv_interrupted_p; instead compare PC to &_hurd_intr_rpc_msg_in_trap. If before it, mutate state to simulate MACH_SEND_INTERRUPTED return; on it, interrupt the operation. All callers changed. * hurd/hurd.h (hurd_thread_cancel, hurd_check_cancel): Declare these. * hurd/Makefile (distribute): Remove intr-rpc.awk. (sig): Add thread-cancel. (transform-user-stub, transform-user-stub-output): Variables removed. * sysdeps/mach/hurd/dl-sysdep.c: Change all RPCs from `__hurd_intr_rpc_*' to `__*'. (_hurd_intr_rpc_mach_msg): New function. (_hurd_thread_sigstate): Function removed. * sysdeps/mach/hurd/ioctl.c: Use _hurd_intr_rpc_mach_msg function, instead of __mach_msg inside HURD_EINTR_RPC macro. * sysdeps/generic/morecore.c [__GNU_LIBRARY__]: Declare `__sbrk' to take ptrdiff_t arg. * sysdeps/mach/hurd/fork.c: Remove _hurd_longjmp_thread_state decl. * sysdeps/mach/hurd/kill.c (kill_pid): Don't make `inline'. * libc-symbols.h [GCC >= 2.7] (strong_alias, weak_symbol, weak_alias): Use `extern' storage class.
Diffstat (limited to 'hurd/thread-cancel.c')
-rw-r--r--hurd/thread-cancel.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/hurd/thread-cancel.c b/hurd/thread-cancel.c
new file mode 100644
index 0000000..db527c3
--- /dev/null
+++ b/hurd/thread-cancel.c
@@ -0,0 +1,86 @@
+/* Thread cancellation support.
+Copyright (C) 1995 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <hurd/signal.h>
+#include <hurd/interrupt.h>
+#include <assert.h>
+#include <thread_state.h>
+
+
+/* See hurdsig.c. */
+extern mach_port_t _hurdsig_abort_rpcs (struct hurd_sigstate *ss,
+ int signo, int sigthread,
+ struct machine_thread_all_state *,
+ int *state_change,
+ mach_port_t *reply_port,
+ mach_msg_type_name_t reply_port_type,
+ int untraced);
+
+error_t
+hurd_thread_cancel (thread_t thread)
+{
+ struct hurd_sigstate *ss = _hurd_thread_sigstate (thread);
+ struct machine_thread_all_state state;
+ int state_change;
+ error_t err;
+
+ if (! ss)
+ return EINVAL;
+
+ __spin_lock (&ss->lock);
+ assert (! ss->critical_section);
+ ss->critical_section = 1;
+ err = __thread_suspend (thread);
+ __spin_unlock (&ss->lock);
+
+ if (! err)
+ {
+ /* Set the flag telling the thread its operation is being cancelled. */
+ ss->cancel = 1;
+
+ /* Interrupt any interruptible RPC now in progress. */
+ state.set = 0;
+ _hurdsig_abort_rpcs (ss, 0, 0, &state, &state_change, NULL, 0, 0);
+ if (state_change)
+ err = __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR,
+ (natural_t *) &state.basic,
+ MACHINE_THREAD_STATE_COUNT);
+
+ __thread_resume (thread);
+ }
+
+ _hurd_critical_section_unlock (ss);
+ return err;
+}
+
+
+int
+hurd_check_cancel (void)
+{
+ struct hurd_sigstate *ss = _hurd_self_sigstate ();
+ int cancel;
+
+ __spin_lock (&ss->lock);
+ assert (! ss->critical_section);
+ cancel = ss->cancel;
+ ss->cancel = 0;
+ __spin_unlock (&ss->lock);
+
+ return cancel;
+}