summaryrefslogtreecommitdiff
path: root/libports/inhibit-all-rpcs.c
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1996-01-27 17:13:41 +0000
committerMiles Bader <miles@gnu.org>1996-01-27 17:13:41 +0000
commitf0eb2440fbe0684531cf11984fb84c329e8866b2 (patch)
tree71e47c935995465ba895f6ae2bb21b992653a9ee /libports/inhibit-all-rpcs.c
parent0d84b8c1a374acd9ea99e4d412d25a50cd17b776 (diff)
(ports_inhibit_all_rpcs):
Be interruptable; return EINTR if interrupted, or EBUSY if already inhibited.
Diffstat (limited to 'libports/inhibit-all-rpcs.c')
-rw-r--r--libports/inhibit-all-rpcs.c59
1 files changed, 37 insertions, 22 deletions
diff --git a/libports/inhibit-all-rpcs.c b/libports/inhibit-all-rpcs.c
index 55076486..13aa62c6 100644
--- a/libports/inhibit-all-rpcs.c
+++ b/libports/inhibit-all-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.
@@ -23,37 +23,52 @@
#include <cthreads.h>
#include <hurd/ihash.h>
-void
+error_t
ports_inhibit_all_rpcs ()
{
- struct port_bucket *bucket;
- int this_one = 0;
- error_t interruptor (void *portstruct)
+ error_t err = 0;
+
+ mutex_lock (&_ports_lock);
+
+ if (_ports_flags & (_PORTS_INHIBITED | _PORTS_INHIBIT_WAIT))
+ err = EBUSY;
+ else
{
- struct port_info *pi = portstruct;
- struct rpc_info *rpc;
+ struct port_bucket *bucket;
+ int this_one = 0;
+ error_t interruptor (void *portstruct)
+ {
+ struct rpc_info *rpc;
+ struct port_info *pi = portstruct;
- for (rpc = pi->current_rpcs; rpc; rpc = rpc->next)
- if (hurd_thread_cancel (rpc->thread) == EINTR)
- this_one = 1;
- return 0;
- }
+ for (rpc = pi->current_rpcs; rpc; rpc = rpc->next)
+ if (hurd_thread_cancel (rpc->thread) == EINTR)
+ this_one = 1;
+ return 0;
+ }
- mutex_lock (&_ports_lock);
+ for (bucket = _ports_all_buckets; bucket; bucket = bucket->next)
+ ihash_iterate (bucket->htable, interruptor);
- for (bucket = _ports_all_buckets; bucket; bucket = bucket->next)
- ihash_iterate (bucket->htable, interruptor);
+ while (_ports_total_rpcs > this_one)
+ {
+ _ports_flags |= _PORTS_INHIBIT_WAIT;
+ if (hurd_condition_wait (&_ports_block, &_ports_lock))
+ /* We got cancelled. */
+ {
+ err = EINTR;
+ break;
+ }
+ }
- while (_ports_total_rpcs > this_one)
- {
- _ports_flags |= _PORTS_INHIBIT_WAIT;
- condition_wait (&_ports_block, &_ports_lock);
+ _ports_flags &= ~_PORTS_INHIBIT_WAIT;
+ if (! err)
+ _ports_flags |= _PORTS_INHIBITED;
}
- _ports_flags |= _PORTS_INHIBITED;
- _ports_flags &= ~_PORTS_INHIBIT_WAIT;
-
mutex_unlock (&_ports_lock);
+
+ return err;
}