diff options
author | Miles Bader <miles@gnu.org> | 1996-01-27 17:14:21 +0000 |
---|---|---|
committer | Miles Bader <miles@gnu.org> | 1996-01-27 17:14:21 +0000 |
commit | afc60f5c854981a5fd714ca667c4b4594b15377b (patch) | |
tree | 5636c9e571638a71887eed235f4afb41d77ac1d7 | |
parent | f0eb2440fbe0684531cf11984fb84c329e8866b2 (diff) |
(ports_inhibit_bucket_rpcs):
Be interruptable; return EINTR if interrupted, or EBUSY if already inhibited.
-rw-r--r-- | libports/inhibit-bucket-rpcs.c | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/libports/inhibit-bucket-rpcs.c b/libports/inhibit-bucket-rpcs.c index 09345755..a04906ff 100644 --- a/libports/inhibit-bucket-rpcs.c +++ b/libports/inhibit-bucket-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,34 +23,48 @@ #include <cthreads.h> #include <hurd/ihash.h> -void +error_t ports_inhibit_bucket_rpcs (struct port_bucket *bucket) { - int this_one = 0; + error_t err = 0; - error_t interruptor (void *portstruct) + mutex_lock (&_ports_lock); + + if (bucket->flags & (PORT_BUCKET_INHIBITED | PORT_BUCKET_INHIBIT_WAIT)) + err = EBUSY; + else { - struct port_info *pi = portstruct; - struct rpc_info *rpc; + 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); + ihash_iterate (bucket->htable, interruptor); - ihash_iterate (bucket->htable, interruptor); + while (bucket->rpcs > this_one) + { + bucket->flags |= PORT_BUCKET_INHIBIT_WAIT; + if (hurd_condition_wait (&_ports_block, &_ports_lock)) + /* We got cancelled. */ + { + err = EINTR; + break; + } + } - while (bucket->rpcs > this_one) - { - bucket->flags |= PORT_BUCKET_INHIBIT_WAIT; - condition_wait (&_ports_block, &_ports_lock); + bucket->flags &= ~PORT_BUCKET_INHIBIT_WAIT; + if (! err) + bucket->flags |= PORT_BUCKET_INHIBITED; } - bucket->flags |= PORT_BUCKET_INHIBITED; - bucket->flags &= ~PORT_CLASS_INHIBIT_WAIT; - mutex_unlock (&_ports_lock); + + return err; } |