Home ⌂Doc Index ◂Up ▴
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*/
node_handle(typename base_type::node *n)
base_type::allocator_type allocator_type
Value::second_type mapped_type
void allocator_swap(MyAlloc &my_allocator, OtherAlloc &other_allocator, traits_true_type)
void allocator_move_assignment(MyAlloc &my_allocator, OtherAlloc &other_allocator, traits_true_type)
node_handle_base< Value, Node, Allocator > base_type
void swap(node_handle_base &nh)
tbb::internal::allocator_traits< allocator_type > traits_type
allocator_traits< Alloc >::template rebind_alloc< T >::other type
node_handle_base(node_handle_base &&nh)
allocator_type get_allocator() const
node_handle_base< Key, Node, Allocator > base_type
mapped_type & mapped() const
void swap(atomic< T > &lhs, atomic< T > &rhs)
Definition: atomic.h:564
static void destroy(allocator_type &, T *p)
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
The graph class.
node_handle_base & operator=(node_handle_base &&nh)
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:319

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.