Extend hash enumeration API to accept an opaque pointer
authorDavide Libenzi <dlibenzi@google.com>
Tue, 27 Oct 2015 21:46:49 +0000 (14:46 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 18 Nov 2015 17:54:57 +0000 (09:54 -0800)
Extend hash enumeration API to accept an opaque pointer.

Signed-off-by: Davide Libenzi <dlibenzi@google.com>
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/include/hashtable.h
kern/src/hashtable.c
kern/src/monitor.c
kern/src/process.c
kern/src/schedule.c

index 65d4893..cfbe5f9 100644 (file)
@@ -286,9 +286,11 @@ ssize_t fnname (hashtable_itr_t *i, hashtable_t *h, keytype *k) \
 }
 
 /* Runs func on each member of the hash table */
-void hash_for_each(struct hashtable *hash, void func(void*));
+void hash_for_each(struct hashtable *hash, void func(void *, void *),
+                                  void *opaque);
 /* Same, but removes the item too */
-void hash_for_each_remove(struct hashtable *hash, void func(void*));
+void hash_for_each_remove(struct hashtable *hash, void func(void *, void *),
+                                                 void *opaque);
 
 /*
  * Copyright (c) 2002, 2004, Christopher Clark
index 1762eb8..e582853 100644 (file)
@@ -416,13 +416,14 @@ hashtable_iterator_search(hashtable_itr_t *itr,
 }
 
 /* Runs func on each member of the hash table */
-void hash_for_each(struct hashtable *hash, void func(void*))
+void hash_for_each(struct hashtable *hash, void func(void *, void *),
+                                  void *opaque)
 {
        if (hashtable_count(hash)) {
                struct hashtable_itr *iter = hashtable_iterator(hash);
                do {
                        void *item = hashtable_iterator_value(iter);
-                       func(item);
+                       func(item, opaque);
                } while (hashtable_iterator_advance(iter));
                kfree(iter);
        }
@@ -430,13 +431,14 @@ void hash_for_each(struct hashtable *hash, void func(void*))
 
 /* Runs func on each member of the hash table, removing the item after
  * processing it.  Make sure func frees the item, o/w you'll leak. */
-void hash_for_each_remove(struct hashtable *hash, void func(void*))
+void hash_for_each_remove(struct hashtable *hash, void func(void *, void *),
+                                                 void *opaque)
 {
        if (hashtable_count(hash)) {
                struct hashtable_itr *iter = hashtable_iterator(hash);
                do {
                        void *item = hashtable_iterator_value(iter);
-                       func(item);
+                       func(item, opaque);
                } while (hashtable_iterator_remove(iter));
                kfree(iter);
        }
index 6932b1a..05bf595 100644 (file)
@@ -962,13 +962,13 @@ int mon_fs(int argc, char **argv, struct hw_trapframe *hw_tf)
                        printk("DENTRY     FLAGS      REFCNT NAME\n");
                        printk("--------------------------------\n");
                        /* Hash helper */
-                       void print_dcache_entry(void *item)
+                       void print_dcache_entry(void *item, void *opaque)
                        {
                                struct dentry *d_i = (struct dentry*)item;
                                printk("%p %p %02d     %s\n", d_i, d_i->d_flags,
                                       kref_refcnt(&d_i->d_kref), d_i->d_name.name);
                        }
-                       hash_for_each(sb->s_dcache, print_dcache_entry);
+                       hash_for_each(sb->s_dcache, print_dcache_entry, NULL);
                }
                if (argc < 3)
                        return 0;
index 7086ae3..b8a6f75 100644 (file)
@@ -2224,7 +2224,7 @@ void __tlbshootdown(uint32_t srcid, long a0, long a1, long a2)
 
 void print_allpids(void)
 {
-       void print_proc_state(void *item)
+       void print_proc_state(void *item, void *opaque)
        {
                struct proc *p = (struct proc*)item;
                assert(p);
@@ -2241,7 +2241,7 @@ void print_allpids(void)
               PROC_PROGNAME_SZ - 5, "");
        printk("------------------------------%s\n", dashes);
        spin_lock(&pid_hash_lock);
-       hash_for_each(pid_hash, print_proc_state);
+       hash_for_each(pid_hash, print_proc_state, NULL);
        spin_unlock(&pid_hash_lock);
 }
 
@@ -2326,7 +2326,7 @@ void print_proc_info(pid_t pid)
 void check_my_owner(void)
 {
        struct per_cpu_info *pcpui = &per_cpu_info[core_id()];
-       void shazbot(void *item)
+       void shazbot(void *item, void *opaque)
        {
                struct proc *p = (struct proc*)item;
                struct vcore *vc_i;
@@ -2353,7 +2353,7 @@ void check_my_owner(void)
        extern int booting;
        if (!booting && !pcpui->owning_proc) {
                spin_lock(&pid_hash_lock);
-               hash_for_each(pid_hash, shazbot);
+               hash_for_each(pid_hash, shazbot, NULL);
                spin_unlock(&pid_hash_lock);
        }
 }
index 8512851..f4c6394 100644 (file)
@@ -917,12 +917,12 @@ void print_resources(struct proc *p)
 void print_all_resources(void)
 {
        /* Hash helper */
-       void __print_resources(void *item)
+       void __print_resources(void *item, void *opaque)
        {
                print_resources((struct proc*)item);
        }
        spin_lock(&pid_hash_lock);
-       hash_for_each(pid_hash, __print_resources);
+       hash_for_each(pid_hash, __print_resources, NULL);
        spin_unlock(&pid_hash_lock);
 }