source: rtems-libbsd/rtemsbsd/powerpc/include/linux/rbtree.h @ 65d6fa2

55-freebsd-126-freebsd-12
Last change on this file since 65d6fa2 was 28ee86a, checked in by Sebastian Huber <sebastian.huber@…>, on 04/27/16 at 09:58:19

Import DPAA driver snapshot

Imported from Freescale Linux repository

git://git.freescale.com/ppc/upstream/linux.git

commit 2774c204cd8bfc56a200ff4dcdfc9cdf5b6fc161.

Linux compatibility layer is partly from FreeBSD.

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 * Copyright (c) 2013 embedded brains GmbH
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27
28#ifndef _LINUX_RBTREE_H
29#define _LINUX_RBTREE_H
30
31#include <rtems/score/rbtree.h>
32
33struct rb_node {
34  struct rb_node *rb_left;
35  struct rb_node *rb_right;
36  struct rb_node *rb_parent;
37  int rb_color;
38};
39
40RTEMS_STATIC_ASSERT(
41  sizeof( struct rb_node ) == sizeof( RBTree_Node ),
42  rb_node_size
43);
44
45RTEMS_STATIC_ASSERT(
46  offsetof( struct rb_node, rb_left ) == offsetof( RBTree_Node, Node.rbe_left ),
47  rb_node_left
48);
49
50RTEMS_STATIC_ASSERT(
51  offsetof( struct rb_node, rb_right ) == offsetof( RBTree_Node, Node.rbe_right ),
52  rb_node_right
53);
54
55RTEMS_STATIC_ASSERT(
56  offsetof( struct rb_node, rb_parent ) == offsetof( RBTree_Node, Node.rbe_parent ),
57  rb_node_parent
58);
59
60RTEMS_STATIC_ASSERT(
61  offsetof( struct rb_node, rb_color ) == offsetof( RBTree_Node, Node.rbe_color ),
62  rb_node_color
63);
64
65struct rb_root {
66  struct rb_node *rb_node;
67};
68
69RTEMS_STATIC_ASSERT(
70  sizeof( struct rb_root ) == sizeof( RBTree_Control ),
71  rb_root_size
72);
73
74RTEMS_STATIC_ASSERT(
75  offsetof( struct rb_root, rb_node ) == offsetof( RBTree_Control, rbh_root ),
76  rb_root_node
77);
78
79#undef RB_ROOT
80#define RB_ROOT ( (struct rb_root) { NULL } )
81
82#define rb_entry( p, container, field ) RTEMS_CONTAINER_OF( p, container, field )
83
84static inline void rb_insert_color( struct rb_node *node, struct rb_root *root)
85{
86  _RBTree_Insert_color( (RBTree_Control *) root, (RBTree_Node *) node );
87}
88
89static inline void rb_erase( struct rb_node *node, struct rb_root *root )
90{
91  _RBTree_Extract( (RBTree_Control *) root, (RBTree_Node *) node );
92}
93
94static inline struct rb_node *rb_next( struct rb_node *node )
95{
96  return (struct rb_node *) _RBTree_Successor( (RBTree_Node *) node );
97}
98
99static inline struct rb_node *rb_prev( struct rb_node *node )
100{
101  return (struct rb_node *) _RBTree_Predecessor( (RBTree_Node *) node );
102}
103
104static inline struct rb_node *rb_first( struct rb_root *root )
105{
106  return (struct rb_node *) _RBTree_Minimum( (RBTree_Control *) root );
107}
108
109static inline struct rb_node *rb_last( struct rb_root *root )
110{
111  return (struct rb_node *) _RBTree_Maximum( (RBTree_Control *) root );
112}
113
114static inline void rb_replace_node(
115  struct rb_node *victim,
116  struct rb_node *replacement,
117  struct rb_root *root
118)
119{
120  _RBTree_Replace_node(
121    (RBTree_Control *) root,
122    (RBTree_Node *) victim,
123    (RBTree_Node *) replacement
124  );
125}
126
127static inline void rb_link_node(
128  struct rb_node *node,
129  struct rb_node *parent,
130  struct rb_node **link
131)
132{
133  _RBTree_Initialize_node( (RBTree_Node *) node );
134  _RBTree_Add_child(
135    (RBTree_Node *) node,
136    (RBTree_Node *) parent,
137    (RBTree_Node **) link
138  );
139}
140
141static inline struct rb_node *rb_parent( struct rb_node *node )
142{
143  return (struct rb_node *) _RBTree_Parent( (RBTree_Node *) node );
144}
145
146#endif /* _LINUX_RBTREE_H */
Note: See TracBrowser for help on using the repository browser.