Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
_node_handle_impl.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2019-2020 Intel Corporation
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 #ifndef __TBB_node_handle_H
18 #define __TBB_node_handle_H
19 
20 #include "_allocator_traits.h"
21 #include "../tbb_config.h"
22 
23 
24 namespace tbb {
25 
26 // This classes must be declared here for correct friendly relationship
27 // TODO: Consider creation some internal class to access node_handle private fields without any friendly classes
28 namespace interface5 {
29 namespace internal {
30  template <typename T, typename Allocator>
31  class split_ordered_list;
32  template <typename Traits>
33  class concurrent_unordered_base;
34 }
35 }
36 
37 namespace interface10{
38 namespace internal {
39  template<typename Traits>
40  class concurrent_skip_list;
41 }
42 }
43 
44 namespace internal {
45 
46 template<typename Value, typename Node, typename Allocator>
48 public:
49  typedef Allocator allocator_type;
50 protected:
51  typedef Node node;
53 public:
54 
57  my_allocator(std::move(nh.my_allocator)) {
58  nh.my_node = NULL;
59  }
60 
61  bool empty() const { return my_node == NULL; }
62  explicit operator bool() const { return my_node != NULL; }
63 
65 
68  my_node = nh.my_node;
69  typedef typename traits_type::propagate_on_container_move_assignment pocma_type;
70  tbb::internal::allocator_move_assignment(my_allocator, nh.my_allocator, pocma_type());
71  nh.deactivate();
72  return *this;
73  }
74 
75  void swap(node_handle_base& nh) {
77  typedef typename traits_type::propagate_on_container_swap pocs_type;
79  }
80 
82  return my_allocator;
83  }
84 
85 protected:
87 
89  if(my_node) {
92  node_allocator.deallocate(my_node, 1);
93  }
94  }
95 
96  void deactivate() { my_node = NULL; }
97 
100 };
101 
102 // node handle for maps
103 template<typename Key, typename Value, typename Node, typename Allocator>
104 class node_handle : public node_handle_base<Value, Node, Allocator> {
106 public:
107  typedef Key key_type;
108  typedef typename Value::second_type mapped_type;
110 
112 
113  key_type& key() const {
114  __TBB_ASSERT(!this->empty(), "Cannot get key from the empty node_type object");
115  return *const_cast<key_type*>(&(this->my_node->value().first));
116  }
117 
118  mapped_type& mapped() const {
119  __TBB_ASSERT(!this->empty(), "Cannot get mapped value from the empty node_type object");
120  return this->my_node->value().second;
121  }
122 
123 private:
124  template<typename T, typename A>
126 
127  template<typename Traits>
129 
130  template<typename Traits>
132 
133  node_handle(typename base_type::node* n) : base_type(n) {}
134 };
135 
136 // node handle for sets
137 template<typename Key, typename Node, typename Allocator>
138 class node_handle<Key, Key, Node, Allocator> : public node_handle_base<Key, Node, Allocator> {
140 public:
141  typedef Key value_type;
143 
145 
146  value_type& value() const {
147  __TBB_ASSERT(!this->empty(), "Cannot get value from the empty node_type object");
148  return *const_cast<value_type*>(&(this->my_node->value()));
149  }
150 
151 private:
152  template<typename T, typename A>
154 
155  template<typename Traits>
157 
158  template<typename Traits>
160 
161  node_handle(typename base_type::node* n) : base_type(n) {}
162 };
163 
164 
165 }// namespace internal
166 }// namespace tbb
167 
168 #endif /*__TBB_node_handle_H*/
tbb::internal::node_handle::allocator_type
base_type::allocator_type allocator_type
Definition: _node_handle_impl.h:109
tbb::internal::node_handle::node_handle
node_handle(typename base_type::node *n)
Definition: _node_handle_impl.h:133
tbb::internal::node_handle< Key, Key, Node, Allocator >::node_handle
node_handle(typename base_type::node *n)
Definition: _node_handle_impl.h:161
internal
Definition: _flow_graph_async_msg_impl.h:24
tbb::internal::node_handle_base::node_handle_base
node_handle_base(node_handle_base &&nh)
Definition: _node_handle_impl.h:56
tbb::internal::node_handle_base::allocator_type
Allocator allocator_type
Definition: _node_handle_impl.h:49
tbb::internal::node_handle::node_handle
node_handle()
Definition: _node_handle_impl.h:111
__TBB_ASSERT
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
tbb::internal::allocator_move_assignment
void allocator_move_assignment(MyAlloc &my_allocator, OtherAlloc &other_allocator, traits_true_type)
Definition: _allocator_traits.h:59
tbb::internal::node_handle_base::node_handle_base
node_handle_base()
Definition: _node_handle_impl.h:55
tbb::internal::allocator_traits< allocator_type >::destroy
static void destroy(allocator_type &, T *p)
Definition: _allocator_traits.h:133
tbb::internal::node_handle_base
Definition: _node_handle_impl.h:47
tbb
The graph class.
Definition: serial/tbb/parallel_for.h:46
tbb::internal::allocator_swap
void allocator_swap(MyAlloc &my_allocator, OtherAlloc &other_allocator, traits_true_type)
Definition: _allocator_traits.h:69
tbb::internal::swap
void swap(atomic< T > &lhs, atomic< T > &rhs)
Definition: atomic.h:564
tbb::interface5::internal::concurrent_unordered_base
Definition: _concurrent_unordered_impl.h:63
tbb::internal::node_handle_base::node_handle_base
node_handle_base(node *n)
Definition: _node_handle_impl.h:86
tbb::internal::node_handle< Key, Key, Node, Allocator >::allocator_type
base_type::allocator_type allocator_type
Definition: _node_handle_impl.h:142
tbb::internal::node_handle_base::my_allocator
allocator_type my_allocator
Definition: _node_handle_impl.h:99
tbb::internal::node_handle_base::deactivate
void deactivate()
Definition: _node_handle_impl.h:96
tbb::internal::node_handle_base::traits_type
tbb::internal::allocator_traits< allocator_type > traits_type
Definition: _node_handle_impl.h:52
tbb::internal::node_handle_base::empty
bool empty() const
Definition: _node_handle_impl.h:61
tbb::internal::node_handle_base::operator=
node_handle_base & operator=(node_handle_base &&nh)
Definition: _node_handle_impl.h:66
tbb::internal::node_handle_base::swap
void swap(node_handle_base &nh)
Definition: _node_handle_impl.h:75
tbb::move
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:319
tbb::internal::node_handle::key
key_type & key() const
Definition: _node_handle_impl.h:113
tbb::internal::node_handle::key_type
Key key_type
Definition: _node_handle_impl.h:107
tbb::internal::node_handle::base_type
node_handle_base< Value, Node, Allocator > base_type
Definition: _node_handle_impl.h:105
tbb::interface5::internal::split_ordered_list
Definition: _concurrent_unordered_impl.h:61
tbb::internal::node_handle_base::~node_handle_base
~node_handle_base()
Definition: _node_handle_impl.h:64
tbb::internal::node_handle_base::my_node
node * my_node
Definition: _node_handle_impl.h:98
tbb::internal::bool_constant
Definition: tbb_stddef.h:486
_allocator_traits.h
tbb::internal::node_handle_base::internal_destroy
void internal_destroy()
Definition: _node_handle_impl.h:88
tbb::internal::node_handle::mapped
mapped_type & mapped() const
Definition: _node_handle_impl.h:118
tbb::internal::allocator_traits< allocator_type >
tbb::internal::node_handle
Definition: _node_handle_impl.h:104
tbb::internal::node_handle< Key, Key, Node, Allocator >::value
value_type & value() const
Definition: _node_handle_impl.h:146
tbb::internal::node_handle< Key, Key, Node, Allocator >::base_type
node_handle_base< Key, Node, Allocator > base_type
Definition: _node_handle_impl.h:139
tbb::internal::node_handle_base::node
Node node
Definition: _node_handle_impl.h:51
tbb::internal::node_handle_base::get_allocator
allocator_type get_allocator() const
Definition: _node_handle_impl.h:81
tbb::internal::node_handle< Key, Key, Node, Allocator >::node_handle
node_handle()
Definition: _node_handle_impl.h:144
tbb::internal::allocator_rebind::type
allocator_traits< Alloc >::template rebind_alloc< T >::other type
Definition: _allocator_traits.h:149
tbb::interface10::internal::concurrent_skip_list
Definition: _concurrent_skip_list_impl.h:220
tbb::internal::node_handle::mapped_type
Value::second_type mapped_type
Definition: _node_handle_impl.h:108
tbb::internal::node_handle< Key, Key, Node, Allocator >::value_type
Key value_type
Definition: _node_handle_impl.h:141

Copyright © 2005-2020 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.