Ignore:
Timestamp:
Jan 23, 2021, 10:25:24 PM (5 years ago)
Author:
Paul Smedley
Message:

Update rbtree to linux 5.10.10 code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GPL/branches/uniaud32-next/include/linux/rbtree.h

    r625 r651  
     1/* SPDX-License-Identifier: GPL-2.0-or-later */
    12/*
    23  Red Black Trees
    34  (C) 1999  Andrea Arcangeli <andrea@suse.de>
    45 
    5   This program is free software; you can redistribute it and/or modify
    6   it under the terms of the GNU General Public License as published by
    7   the Free Software Foundation; either version 2 of the License, or
    8   (at your option) any later version.
    9 
    10   This program is distributed in the hope that it will be useful,
    11   but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   GNU General Public License for more details.
    14 
    15   You should have received a copy of the GNU General Public License
    16   along with this program; if not, write to the Free Software
    17   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    186
    197  linux/include/linux/rbtree.h
     
    2412  performances and genericity...
    2513
    26   See Documentation/rbtree.txt for documentation and samples.
     14  See Documentation/core-api/rbtree.rst for documentation and samples.
    2715*/
    28 /* from 4.19.163 */
     16/* from 5.10.10 */
    2917
    3018#ifndef _LINUX_RBTREE_H
     
    4634};
    4735
    48 /*
    49  * Leftmost-cached rbtrees.
    50  *
    51  * We do not cache the rightmost node based on footprint
    52  * size vs number of potential users that could benefit
    53  * from O(1) rb_last(). Just not worth it, users that want
    54  * this feature can always implement the logic explicitly.
    55  * Furthermore, users that want to cache both pointers may
    56  * find it a bit asymmetric, but that's ok.
    57  */
    58 struct rb_root_cached {
    59         struct rb_root rb_root;
    60         struct rb_node *rb_leftmost;
    61 };
    62 
    6336#define rb_parent(r)   ((struct rb_node *)((r)->__rb_parent_color & ~3))
    6437
    6538#define RB_ROOT (struct rb_root) { NULL, }
    66 #define RB_ROOT_CACHED (struct rb_root_cached) { {NULL, }, NULL }
    6739#define rb_entry(ptr, type, member) container_of(ptr, type, member)
    6840
     
    8658extern struct rb_node *rb_last(const struct rb_root *);
    8759
    88 extern void rb_insert_color_cached(struct rb_node *,
    89                                    struct rb_root_cached *, bool);
    90 extern void rb_erase_cached(struct rb_node *node, struct rb_root_cached *);
    91 /* Same as rb_first(), but O(1) */
    92 #define rb_first_cached(root) (root)->rb_leftmost
    93 
    9460/* Postorder iteration - always visit the parent after its children */
    9561extern struct rb_node *rb_first_postorder(const struct rb_root *);
     
    10167extern void rb_replace_node_rcu(struct rb_node *victim, struct rb_node *new,
    10268                                struct rb_root *root);
    103 extern void rb_replace_node_cached(struct rb_node *victim, struct rb_node *new,
    104                                    struct rb_root_cached *root);
    10569
    10670static inline void rb_link_node(struct rb_node *node, struct rb_node *parent,
     
    152116             pos = n)
    153117
     118/*
     119 * Leftmost-cached rbtrees.
     120 *
     121 * We do not cache the rightmost node based on footprint
     122 * size vs number of potential users that could benefit
     123 * from O(1) rb_last(). Just not worth it, users that want
     124 * this feature can always implement the logic explicitly.
     125 * Furthermore, users that want to cache both pointers may
     126 * find it a bit asymmetric, but that's ok.
     127 */
     128struct rb_root_cached {
     129        struct rb_root rb_root;
     130        struct rb_node *rb_leftmost;
     131};
     132
     133#define RB_ROOT_CACHED (struct rb_root_cached) { {NULL, }, NULL }
     134
     135/* Same as rb_first(), but O(1) */
     136#define rb_first_cached(root) (root)->rb_leftmost
     137
     138static inline void rb_insert_color_cached(struct rb_node *node,
     139                                          struct rb_root_cached *root,
     140                                          bool leftmost)
     141{
     142        if (leftmost)
     143                root->rb_leftmost = node;
     144        rb_insert_color(node, &root->rb_root);
     145}
     146
     147static inline void rb_erase_cached(struct rb_node *node,
     148                                   struct rb_root_cached *root)
     149{
     150        if (root->rb_leftmost == node)
     151                root->rb_leftmost = rb_next(node);
     152        rb_erase(node, &root->rb_root);
     153}
     154
     155static inline void rb_replace_node_cached(struct rb_node *victim,
     156                                          struct rb_node *new,
     157                                          struct rb_root_cached *root)
     158{
     159        if (root->rb_leftmost == victim)
     160                root->rb_leftmost = new;
     161        rb_replace_node(victim, new, &root->rb_root);
     162}
     163
    154164#endif  /* _LINUX_RBTREE_H */
Note: See TracChangeset for help on using the changeset viewer.