diff options
author | Miles Bader <miles@gnu.org> | 1996-01-27 17:14:41 +0000 |
---|---|---|
committer | Miles Bader <miles@gnu.org> | 1996-01-27 17:14:41 +0000 |
commit | d5c41139d706edb396a81f6c561543e8d19c3455 (patch) | |
tree | ce917d3c820bb4d1b7ca0ecdb953583fbce96513 | |
parent | afc60f5c854981a5fd714ca667c4b4594b15377b (diff) |
(ports_inhibit_class_rpcs):
Be interruptable; return EINTR if interrupted, or EBUSY if already inhibited.
-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; +} |