From 049d3e7d8ac652b9221f25bc1271a792be46db38 Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Sat, 27 Jan 1996 17:10:45 +0000 Subject: (ports_inhibit_port_rpcs): Be interruptable; return EINTR if interrupted, or EBUSY if already inhibited. --- libports/inhibit-port-rpcs.c | 47 +++++++++++++++++++++++++++++--------------- 1 file 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 #include -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; } -- cgit v1.2.3