diff options
author | Miles Bader <miles@gnu.org> | 1996-01-27 17:10:45 +0000 |
---|---|---|
committer | Miles Bader <miles@gnu.org> | 1996-01-27 17:10:45 +0000 |
commit | 049d3e7d8ac652b9221f25bc1271a792be46db38 (patch) | |
tree | ebcd97731ccd4894a48f9d224973a572c060f1f9 | |
parent | e08da7524e5bbb2c92a2773343ca633be726c3a8 (diff) |
(ports_inhibit_port_rpcs):
Be interruptable; return EINTR if interrupted, or EBUSY if already inhibited.
-rw-r--r-- | libports/inhibit-port-rpcs.c | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/libports/inhibit-port-rpcs.c b/libports/inhibit-port-rpcs.c index f4ddf497..4ec5d853 100644 --- a/libports/inhibit-port-rpcs.c +++ b/libports/inhibit-port-rpcs.c @@ -1,5 +1,5 @@ /* - Copyright (C) 1995 Free Software Foundation, Inc. + Copyright (C) 1995, 1996 Free Software Foundation, Inc. Written by Michael I. Bushnell. This file is part of the GNU Hurd. @@ -22,29 +22,44 @@ #include <hurd.h> #include <cthreads.h> -void +error_t ports_inhibit_port_rpcs (void *portstruct) { + error_t err = 0; struct port_info *pi = portstruct; - struct rpc_info *rpc, *this_rpc; mutex_lock (&_ports_lock); - this_rpc = 0; - for (rpc = pi->current_rpcs; rpc; rpc = rpc->next) - if (hurd_thread_cancel (rpc->thread) == EINTR) - this_rpc = rpc; - - while (pi->current_rpcs - /* If this thread's RPC is the only one left, that doesn't count. */ - && !(pi->current_rpcs == this_rpc && ! this_rpc->next)) + if (pi->flags & (PORT_INHIBITED | PORT_INHIBIT_WAIT)) + err = EBUSY; + else { - pi->flags |= PORT_INHIBIT_WAIT; - condition_wait (&_ports_block, &_ports_lock); - } + struct rpc_info *rpc; + struct rpc_info *this_rpc = 0; + + for (rpc = pi->current_rpcs; rpc; rpc = rpc->next) + if (hurd_thread_cancel (rpc->thread) == EINTR) + this_rpc = rpc; - pi->flags |= PORT_INHIBITED; - pi->flags &= ~PORT_INHIBIT_WAIT; + while (pi->current_rpcs + /* If this thread's RPC is the only one left, it doesn't count. */ + && !(pi->current_rpcs == this_rpc && ! this_rpc->next)) + { + pi->flags |= PORT_INHIBIT_WAIT; + if (hurd_condition_wait (&_ports_block, &_ports_lock)) + /* We got cancelled. */ + { + err = EINTR; + break; + } + } + + pi->flags &= ~PORT_INHIBIT_WAIT; + if (! err) + pi->flags |= PORT_INHIBITED; + } mutex_unlock (&_ports_lock); + + return err; } |