diff options
author | Miles Bader <miles@gnu.org> | 1997-08-20 20:33:03 +0000 |
---|---|---|
committer | Miles Bader <miles@gnu.org> | 1997-08-20 20:33:03 +0000 |
commit | 4709df1d86513975a004bdd58ba84158e45a650d (patch) | |
tree | aa25c1741627e2a218d4f49d8c1c8c0d0ceba96a | |
parent | 7864068cd5e53a8fdd220927da003f803f657341 (diff) |
Initial checkin.
-rw-r--r-- | libports/interrupted.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/libports/interrupted.c b/libports/interrupted.c new file mode 100644 index 00000000..e4cb2fc2 --- /dev/null +++ b/libports/interrupted.c @@ -0,0 +1,75 @@ +/* Keeping track of thread interruption + + Copyright (C) 1997 Free Software Foundation, Inc. + Written by Miles Bader <miles@gnu.ai.mit.edu> + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "ports.h" + +static spin_lock_t interrupted_lock = SPIN_LOCK_INITIALIZER; + +/* True if some active rpc has been interrupted. */ +static struct rpc_info *interrupted = 0; + +/* If the current thread's rpc has been interrupted with + ports_interrupt_rpcs, return true (and clear the interrupted flag). */ +int +ports_self_interrupted () +{ + struct rpc_info **rpc_p, *rpc; + thread_t self = hurd_thread_self (); + + spin_lock (&interrupted_lock); + for (rpc_p = &interrupted; *rpc_p; rpc_p = &rpc->interrupted_next) + { + rpc = *rpc_p; + if (rpc->thread == self) + { + *rpc_p = rpc->interrupted_next; + spin_unlock (&interrupted_lock); + rpc->interrupted_next = 0; + return 1; + } + } + spin_unlock (&interrupted_lock); + + return 0; +} + +/* Add RPC to the list of rpcs that have been interrupted. */ +void +_ports_record_interruption (struct rpc_info *rpc) +{ + struct rpc_info *i; + + spin_lock (&interrupted_lock); + + /* See if RPC is already in the interrupted list. */ + for (i = interrupted; i; i = i->interrupted_next) + if (i == rpc) + /* Yup, it is, so just leave it there. */ + { + spin_unlock (&interrupted_lock); + return; + } + + /* Nope, put it at the beginning. */ + rpc->interrupted_next = interrupted; + interrupted = rpc; + + spin_unlock (&interrupted_lock); +} |