Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/external/bsd Rewrite hashtable.h locally so it might wor...



details:   https://anonhg.NetBSD.org/src/rev/db1f4a98670f
branches:  trunk
changeset: 992425:db1f4a98670f
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Aug 27 06:23:19 2018 +0000

description:
Rewrite hashtable.h locally so it might work here.

diffstat:

 sys/external/bsd/common/include/linux/list.h    |  29 ++++++++-
 sys/external/bsd/drm2/include/linux/hashtable.h |  85 ++++++++++++++----------
 2 files changed, 78 insertions(+), 36 deletions(-)

diffs (165 lines):

diff -r e431619cbda2 -r db1f4a98670f sys/external/bsd/common/include/linux/list.h
--- a/sys/external/bsd/common/include/linux/list.h      Mon Aug 27 06:19:26 2018 +0000
+++ b/sys/external/bsd/common/include/linux/list.h      Mon Aug 27 06:23:19 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: list.h,v 1.5 2014/08/20 15:26:52 riastradh Exp $       */
+/*     $NetBSD: list.h,v 1.6 2018/08/27 06:23:19 riastradh Exp $       */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -259,6 +259,25 @@
        LIST_ENTRY(hlist_node) hln_entry;
 };
 
+/*
+ * XXX This works only because LIST_HEAD_INITIALIZER doesn't actually
+ * use the name.  Really, this is just initialization to a null
+ * pointer.
+ */
+#define        HLIST_HEAD_INIT LIST_HEAD_INITIALIZER(dummy)
+
+static inline void
+INIT_HLIST_HEAD(struct hlist_head *head)
+{
+       LIST_INIT(head);
+}
+
+static inline bool
+hlist_empty(struct hlist_head *head)
+{
+       return LIST_EMPTY(head);
+}
+
 static inline struct hlist_node *
 hlist_first(struct hlist_head *head)
 {
@@ -306,6 +325,14 @@
                (VAR) = hlist_entry(LIST_NEXT(&(VAR)->FIELD, hln_entry),      \
                    typeof(*(VAR)), FIELD))
 
+#define        hlist_for_each_entry_safe(VAR, NEXT, HEAD, FIELD)                     \
+       for ((VAR) = hlist_entry(LIST_FIRST((HEAD)), typeof(*(VAR)), FIELD),  \
+               (NEXT) = (&(VAR)->FIELD == NULL ? NULL :                      \
+                   hlist_entry(LIST_NEXT(&(VAR)->FIELD, hln_entry),          \
+                       typeof(*(VAR)), FIELD));                              \
+            &(VAR)->FIELD != NULL;                                           \
+               (VAR) = (NEXT))
+
 /*
  * XXX The nominally RCU-safe APIs below lack dependent read barriers,
  * so they're not actually RCU-safe...on the alpha, anyway.  Someone^TM
diff -r e431619cbda2 -r db1f4a98670f sys/external/bsd/drm2/include/linux/hashtable.h
--- a/sys/external/bsd/drm2/include/linux/hashtable.h   Mon Aug 27 06:19:26 2018 +0000
+++ b/sys/external/bsd/drm2/include/linux/hashtable.h   Mon Aug 27 06:23:19 2018 +0000
@@ -1,61 +1,76 @@
-/*     $OpenBSD$       */
-/*
- * Copyright (c) 2013, 2014, 2015 Mark Kettenis
- * Copyright (c) 2017 Martin Pieuchot
+/*     $NetBSD: hashtable.h,v 1.4 2018/08/27 06:23:19 riastradh Exp $  */
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
  *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
  *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef _LINUX_HASHTABLE_H_
 #define _LINUX_HASHTABLE_H_
 
+#include <sys/cdefs.h>
+
 #include <linux/list.h>
 
-#define DECLARE_HASHTABLE(name, bits) struct list_head name[1 << (bits)]
+/*
+ * XXX This assumes that HLIST_HEAD_INIT is just initialization to a
+ * null pointer.
+ */
+#define DECLARE_HASHTABLE(name, bits)                                        \
+       struct hlist_head name[1u << (bits)] = { HLIST_HEAD_INIT }
 
 static inline void
-__hash_init(struct list_head *table, u_int size)
+__hash_init(struct hlist_head *hash, unsigned n)
 {
-       u_int i;
 
-       for (i = 0; i < size; i++)
-               INIT_LIST_HEAD(&table[i]);
+       while (n --> 0)
+               INIT_HLIST_HEAD(&hash[n]);
 }
 
 static inline bool
-__hash_empty(struct list_head *table, u_int size)
+__hash_empty(struct hlist_head *hash, unsigned n)
 {
-       u_int i;
 
-       for (i = 0; i < size; i++) {
-               if (!list_empty(&table[i]))
+       while (n --> 0) {
+               if (!hlist_empty(&hash[n]))
                        return false;
        }
 
        return true;
 }
 
-#define __hash(table, key)     &table[key % (nitems(table) - 1)]
-
-#define hash_init(table)       __hash_init(table, nitems(table))
-#define hash_add(table, node, key) \
-       hlist_add_head(node, __hash(table, key))
-#define hash_del(node)         hlist_del_init(node)
-#define hash_empty(table)      __hash_empty(table, nitems(table))
-#define hash_for_each_possible(table, obj, member, key) \
-       hlist_for_each_entry(obj, __hash(table, key), member)
-#define hash_for_each_safe(table, i, tmp, obj, member)         \
-       for (i = 0; i < nitems(table); i++)             \
-              list_for_each_entry_safe(obj, tmp, &table[i], member)
+#define        hash_init(h)            __hash_init((h), __arraycount(h))
+#define        hash_add(h, n, k)       hlist_add_head(n, &(h)[(k) % __arraycount(h)])
+#define        hash_del(n)             hlist_del_init(n)
+#define        hash_empty(h)           __hash_empty((h), __arraycount(h))
+#define        hash_for_each_possible(h, n, f, k)                                    \
+       hlist_for_each_entry(n, &(h)[(k) % __arraycount(h)], f)
+#define        hash_for_each_safe(h, i, t, n, f)                                     \
+       for ((i) = 0; (i) < __arraycount(h); (i)++)                           \
+               hlist_for_each_entry_safe(n, t, &(h)[i], f)
 
 #endif /*_LINUX_HASHTABLE_H_*/



Home | Main Index | Thread Index | Old Index