summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libports/inhibit-port-rpcs.c47
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;
}