Source-Changes-HG archive

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

[src/trunk]: src/sys/external/bsd/drm2/include/linux linux: New rb_move(&to, ...



details:   https://anonhg.NetBSD.org/src/rev/a8ad94514b70
branches:  trunk
changeset: 362431:a8ad94514b70
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Feb 27 14:18:34 2022 +0000

description:
linux: New rb_move(&to, &from) to replace `to = from'.

NetBSD rbtree(3) is not relocatable, so this extra step is needed.
Unfortunately, there's no easy way to automate detection of where we
need to apply this in ported code...

diffstat:

 sys/external/bsd/drm2/include/linux/rbtree.h |  23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)

diffs (37 lines):

diff -r 45c8547d45dc -r a8ad94514b70 sys/external/bsd/drm2/include/linux/rbtree.h
--- a/sys/external/bsd/drm2/include/linux/rbtree.h      Sun Feb 27 14:18:25 2022 +0000
+++ b/sys/external/bsd/drm2/include/linux/rbtree.h      Sun Feb 27 14:18:34 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rbtree.h,v 1.17 2022/02/27 14:18:25 riastradh Exp $    */
+/*     $NetBSD: rbtree.h,v 1.18 2022/02/27 14:18:34 riastradh Exp $    */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -203,6 +203,27 @@
        }
 }
 
+/*
+ * Extension to Linux API, which allows copying a struct rb_root object
+ * with `=' or `memcpy' and no additional relocation.
+ */
+static inline void
+rb_move(struct rb_root *to, struct rb_root *from)
+{
+       struct rb_node *root;
+
+       *to = *from;
+       memset(from, 0, sizeof(*from)); /* paranoia */
+       if ((root = to->rbr_tree.rbt_root) == NULL)
+               return;
+
+       /*
+        * The root node's `parent' is a strict-aliasing-unsafe hack
+        * pointing at the root of the tree.
+        */
+       RB_SET_FATHER(root, (struct rb_node *)(void *)&to->rbr_tree.rbt_root);
+}
+
 #define        rbtree_postorder_for_each_entry_safe(ENTRY, TMP, ROOT, FIELD)         \
        for ((ENTRY) = rb_entry_safe(rb_first_postorder(ROOT),                \
                    __typeof__(*(ENTRY)), FIELD);                             \



Home | Main Index | Thread Index | Old Index