diff options
-rw-r--r-- | libports/inhibit-class-rpcs.c | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/libports/inhibit-class-rpcs.c b/libports/inhibit-class-rpcs.c index 5b5a602b..00b9b361 100644 --- a/libports/inhibit-class-rpcs.c +++ b/libports/inhibit-class-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,31 +22,43 @@ #include <hurd.h> #include <cthreads.h> -void +error_t ports_inhibit_class_rpcs (struct port_class *class) { - struct port_info *pi; - struct rpc_info *rpc; - int this_one; + error_t err = 0; mutex_lock (&_ports_lock); - this_one = 0; - for (pi = class->ports; pi; pi = pi->next) - for (rpc = pi->current_rpcs; rpc; rpc = rpc->next) - if (hurd_thread_cancel (rpc->thread) == EINTR) - this_one = 1; - - while (class->rpcs > this_one) + if (class->flags & (PORT_CLASS_INHIBITED | PORT_CLASS_INHIBIT_WAIT)) + err = EBUSY; + else { - class->flags |= PORT_CLASS_INHIBIT_WAIT; - condition_wait (&_ports_block, &_ports_lock); - } + struct port_info *pi; + struct rpc_info *rpc; + int this_one = 0; - class->flags |= PORT_CLASS_INHIBITED; - class->flags &= ~PORT_CLASS_INHIBIT_WAIT; + for (pi = class->ports; pi; pi = pi->next) + for (rpc = pi->current_rpcs; rpc; rpc = rpc->next) + if (hurd_thread_cancel (rpc->thread) == EINTR) + this_one = 1; - mutex_unlock (&_ports_lock); -} + while (class->rpcs > this_one) + { + class->flags |= PORT_CLASS_INHIBIT_WAIT; + if (hurd_condition_wait (&_ports_block, &_ports_lock)) + /* We got cancelled. */ + { + err = EINTR; + break; + } + } + class->flags &= ~PORT_CLASS_INHIBIT_WAIT; + if (! err) + class->flags |= PORT_CLASS_INHIBITED; + } + + mutex_unlock (&_ports_lock); + return err; +} |