diff options
Diffstat (limited to 'libports')
-rw-r--r-- | libports/Makefile | 9 | ||||
-rw-r--r-- | libports/bucket-iterate.c | 49 | ||||
-rw-r--r-- | libports/class-iterate.c | 37 |
3 files changed, 73 insertions, 22 deletions
diff --git a/libports/Makefile b/libports/Makefile index f0ce6f76..2cc38d63 100644 --- a/libports/Makefile +++ b/libports/Makefile @@ -1,5 +1,5 @@ -# -# Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. +# +# Copyright (C) 1995,96,97,99 Free Software Foundation, Inc. # Written by Michael I. Bushnell. # # This file is part of the GNU Hurd. @@ -30,7 +30,7 @@ SRCS = create-bucket.c create-class.c \ inhibit-all-rpcs.c resume-port-rpcs.c resume-class-rpcs.c \ resume-bucket-rpcs.c resume-all-rpcs.c interrupt-rpcs.c \ init.c complete-deallocate.c get-right.c count-class.c count-bucket.c \ - enable-class.c enable-bucket.c bucket-iterate.c stubs.c \ + enable-class.c enable-bucket.c bucket-iterate.c class-iterate.c stubs.c \ notify-dead-name.c notify-no-senders.c notify-port-destroyed.c \ notify-msg-accepted.c notify-port-deleted.c notify-send-once.c \ interrupt-operation.c interrupt-on-notify.c interrupt-notified-rpcs.c \ @@ -43,8 +43,7 @@ installhdrs = ports.h HURDLIBS= ihash OBJS = $(SRCS:.c=.o) notifyServer.o interruptServer.o - + MIGCOMSFLAGS = -prefix ports_ include ../Makeconf - diff --git a/libports/bucket-iterate.c b/libports/bucket-iterate.c index 9b49579f..1bfd73e3 100644 --- a/libports/bucket-iterate.c +++ b/libports/bucket-iterate.c @@ -1,5 +1,5 @@ -/* - Copyright (C) 1995 Free Software Foundation, Inc. +/* Iterate a function over the ports in a bucket. + Copyright (C) 1995, 1999 Free Software Foundation, Inc. Written by Michael I. Bushnell. This file is part of the GNU Hurd. @@ -22,13 +22,17 @@ #include <cthreads.h> #include <hurd/ihash.h> -/* This is obsecenely ineffecient. ihash and ports need to cooperate - more closely to do it effeciently. */ + +/* Internal entrypoint for both ports_bucket_iterate and ports_class_iterate. + If CLASS is non-null, call FUN only for ports in that class. */ error_t -ports_bucket_iterate (struct port_bucket *bucket, - error_t (*fun)(void *)) +_ports_bucket_class_iterate (struct port_bucket *bucket, + struct port_class *class, + error_t (*fun)(void *)) { - struct item + /* This is obsecenely ineffecient. ihash and ports need to cooperate + more closely to do it effeciently. */ + struct item { struct item *next; void *p; @@ -36,22 +40,26 @@ ports_bucket_iterate (struct port_bucket *bucket, struct item *i, *nxt; error_t err; - error_t enqueue (void *pi) + error_t enqueue (void *arg) { + struct port_info *const pi = arg; struct item *j; - - j = malloc (sizeof (struct item)); - j->next = list; - j->p = pi; - list = j; - ((struct port_info *)pi)->refcnt++; + + if (class == 0 || pi->class == class) + { + j = malloc (sizeof (struct item)); + j->next = list; + j->p = pi; + list = j; + pi->refcnt++; + } return 0; } - + mutex_lock (&_ports_lock); ihash_iterate (bucket->htable, enqueue); mutex_unlock (&_ports_lock); - + err = 0; for (i = list; i; i = nxt) { @@ -62,4 +70,11 @@ ports_bucket_iterate (struct port_bucket *bucket, free (i); } return err; -} +} + +error_t +ports_bucket_iterate (struct port_bucket *bucket, + error_t (*fun)(void *)) +{ + return _ports_bucket_class_iterate (bucket, 0, fun); +} diff --git a/libports/class-iterate.c b/libports/class-iterate.c new file mode 100644 index 00000000..1e349497 --- /dev/null +++ b/libports/class-iterate.c @@ -0,0 +1,37 @@ +/* Iterate a function over the ports in a class. + Copyright (C) 1999 Free Software Foundation, Inc. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "ports.h" +#include <cthreads.h> +#include <hurd/ihash.h> + +error_t +ports_class_iterate (struct port_class *class, + error_t (*fun)(void *)) +{ + mutex_lock (&_ports_lock); + if (class->ports != 0) + { + struct port_bucket *bucket = class->ports->bucket; + mutex_unlock (&_ports_lock); + return _ports_bucket_class_iterate (bucket, class, fun); + } + mutex_unlock (&_ports_lock); + return 0; +} |