VTK  9.5.20250806
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 auto iter = std::make_unique<ItImpl>();
77 iter->Iter = this->Internal.begin();
78 return iter;
79 };
80
81 std::unique_ptr<ItImplAbstract> end() override
82 {
83 auto iter = std::make_unique<ItImpl>();
84 iter->Iter = this->Internal.end();
85 return iter;
86 }
87
88private:
89 TLS Internal;
90
91 // disable copying
93 void operator=(const vtkSMPThreadLocalImpl&) = delete;
94};
95
96VTK_ABI_NAMESPACE_END
97} // namespace smp
98} // namespace detail
99} // namespace vtk
100
101#endif
virtual std::unique_ptr< ItImpl > begin()=0
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.