VTK  9.4.20241118
vtkSMPThreadLocalImpl.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
3// .NAME vtkSMPThreadLocal - A TBB based thread local storage implementation.
4
5#ifndef TBBvtkSMPThreadLocalImpl_h
6#define TBBvtkSMPThreadLocalImpl_h
7
9
10#ifdef _MSC_VER
11#pragma push_macro("__TBB_NO_IMPLICIT_LINKAGE")
12#define __TBB_NO_IMPLICIT_LINKAGE 1
13#endif
14
15#include <tbb/enumerable_thread_specific.h>
16
17#ifdef _MSC_VER
18#pragma pop_macro("__TBB_NO_IMPLICIT_LINKAGE")
19#endif
20
21#include <iterator>
22#include <utility> // For std::move
23
24namespace vtk
25{
26namespace detail
27{
28namespace smp
29{
30VTK_ABI_NAMESPACE_BEGIN
31
32template <typename T>
34{
35 typedef tbb::enumerable_thread_specific<T> TLS;
36 typedef typename TLS::iterator TLSIter;
38
39public:
41
42 explicit vtkSMPThreadLocalImpl(const T& exemplar)
43 : Internal(exemplar)
44 {
45 }
46
47 T& Local() override { return this->Internal.local(); }
48
49 size_t size() const override { return this->Internal.size(); }
50
51 class ItImpl : public vtkSMPThreadLocalImplAbstract<T>::ItImpl
52 {
53 public:
54 void Increment() override { ++this->Iter; }
55
56 bool Compare(ItImplAbstract* other) override
57 {
58 return this->Iter == static_cast<ItImpl*>(other)->Iter;
59 }
60
61 T& GetContent() override { return *this->Iter; }
62
63 T* GetContentPtr() override { return &*this->Iter; }
64
65 protected:
66 ItImpl* CloneImpl() const override { return new ItImpl(*this); };
67
68 private:
69 TLSIter Iter;
70
71 friend class vtkSMPThreadLocalImpl<BackendType::TBB, T>;
72 };
73
74 std::unique_ptr<ItImplAbstract> begin() override
75 {
76 // XXX(c++14): use std::make_unique
77 auto iter = std::unique_ptr<ItImpl>(new ItImpl());
78 iter->Iter = this->Internal.begin();
79 // XXX(c++14): remove std::move and cast variable
80 std::unique_ptr<ItImplAbstract> abstractIt(std::move(iter));
81 return abstractIt;
82 };
83
84 std::unique_ptr<ItImplAbstract> end() override
85 {
86 // XXX(c++14): use std::make_unique
87 auto iter = std::unique_ptr<ItImpl>(new ItImpl());
88 iter->Iter = this->Internal.end();
89 // XXX(c++14): remove std::move and cast variable
90 std::unique_ptr<ItImplAbstract> abstractIt(std::move(iter));
91 return abstractIt;
92 }
93
94private:
95 TLS Internal;
96
97 // disable copying
99 void operator=(const vtkSMPThreadLocalImpl&) = delete;
100};
101
102VTK_ABI_NAMESPACE_END
103} // namespace smp
104} // namespace detail
105} // namespace vtk
106
107#endif
virtual std::unique_ptr< ItImpl > begin()=0
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.