VTK  9.2.6
vtkSMPThreadLocalImpl.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkSMPThreadLocalImpl.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 // .NAME vtkSMPThreadLocal - A TBB based thread local storage implementation.
16 
17 #ifndef TBBvtkSMPThreadLocalImpl_h
18 #define TBBvtkSMPThreadLocalImpl_h
19 
21 
22 #ifdef _MSC_VER
23 #pragma push_macro("__TBB_NO_IMPLICIT_LINKAGE")
24 #define __TBB_NO_IMPLICIT_LINKAGE 1
25 #endif
26 
27 #include <tbb/enumerable_thread_specific.h>
28 
29 #ifdef _MSC_VER
30 #pragma pop_macro("__TBB_NO_IMPLICIT_LINKAGE")
31 #endif
32 
33 #include <iterator>
34 #include <utility> // For std::move
35 
36 namespace vtk
37 {
38 namespace detail
39 {
40 namespace smp
41 {
42 
43 template <typename T>
45 {
46  typedef tbb::enumerable_thread_specific<T> TLS;
47  typedef typename TLS::iterator TLSIter;
49 
50 public:
52 
53  explicit vtkSMPThreadLocalImpl(const T& exemplar)
54  : Internal(exemplar)
55  {
56  }
57 
58  T& Local() override { return this->Internal.local(); }
59 
60  size_t size() const override { return this->Internal.size(); }
61 
63  {
64  public:
65  void Increment() override { ++this->Iter; }
66 
67  bool Compare(ItImplAbstract* other) override
68  {
69  return this->Iter == static_cast<ItImpl*>(other)->Iter;
70  }
71 
72  T& GetContent() override { return *this->Iter; }
73 
74  T* GetContentPtr() override { return &*this->Iter; }
75 
76  protected:
77  virtual ItImpl* CloneImpl() const override { return new ItImpl(*this); };
78 
79  private:
80  TLSIter Iter;
81 
83  };
84 
85  std::unique_ptr<ItImplAbstract> begin() override
86  {
87  // XXX(c++14): use std::make_unique
88  auto iter = std::unique_ptr<ItImpl>(new ItImpl());
89  iter->Iter = this->Internal.begin();
90  // XXX(c++14): remove std::move and cast variable
91  std::unique_ptr<ItImplAbstract> abstractIt(std::move(iter));
92  return abstractIt;
93  };
94 
95  std::unique_ptr<ItImplAbstract> end() override
96  {
97  // XXX(c++14): use std::make_unique
98  auto iter = std::unique_ptr<ItImpl>(new ItImpl());
99  iter->Iter = this->Internal.end();
100  // XXX(c++14): remove std::move and cast variable
101  std::unique_ptr<ItImplAbstract> abstractIt(std::move(iter));
102  return abstractIt;
103  }
104 
105 private:
106  TLS Internal;
107 
108  // disable copying
110  void operator=(const vtkSMPThreadLocalImpl&) = delete;
111 };
112 
113 } // namespace smp
114 } // namespace detail
115 } // namespace vtk
116 
117 #endif
virtual std::unique_ptr< ItImpl > begin()=0
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.