Embedded Multicore Building Blocks V1.0.0
thread_specific_storage.h
1 /*
2  * Copyright (c) 2014-2017, Siemens AG. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24  * POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #ifndef EMBB_BASE_THREAD_SPECIFIC_STORAGE_H_
28 #define EMBB_BASE_THREAD_SPECIFIC_STORAGE_H_
29 
30 #include <embb/base/c/thread_specific_storage.h>
31 #include <embb/base/c/internal/thread_index.h>
32 #include <embb/base/exceptions.h>
33 
34 namespace embb {
35 namespace base {
36 
37 namespace test {
41 class ThreadSpecificStorageTest;
42 }
43 
60 template<typename Type>
62  public:
73 
74 #ifdef DOXYGEN
75 
88  template<typename Initializer1, ...>
89  explicit ThreadSpecificStorage(
90  Initializer1 initializer1,
92  ...
93  );
94 #else
95 
98  template<typename Initializer>
99  explicit ThreadSpecificStorage(Initializer initializer);
100 
104  template<typename Initializer1, typename Initializer2>
105  ThreadSpecificStorage(Initializer1 initializer1, Initializer2 initializer2);
106 
110  template<typename Initializer1, typename Initializer2, typename Initializer3>
111  ThreadSpecificStorage(Initializer1 initializer1, Initializer2 initializer2,
112  Initializer3 initializer3);
113 
117  template<typename Initializer1, typename Initializer2, typename Initializer3,
118  typename Initializer4>
119  ThreadSpecificStorage(Initializer1 initializer1, Initializer2 initializer2,
120  Initializer3 initializer3, Initializer4 initializer4);
121 #endif // else defined(DOXYGEN)
122 
126  ~ThreadSpecificStorage();
127 
138  Type& Get();
139 
150  const Type& Get() const;
151 
152  private:
156  void Prepare();
157 
161  embb_tss_t rep_;
162 
166  bool* usage_flags_;
167 
171  friend class test::ThreadSpecificStorageTest;
172 };
173 
174 } // namespace base
175 } // namespace embb
176 
177 #include <embb/base/internal/thread_specific_storage-inl.h>
178 
179 #endif // EMBB_BASE_THREAD_SPECIFIC_STORAGE_H_
Definition: lock_free_mpmc_queue.h:40
opaque_type embb_tss_t
Opaque type representing a TSS.
Definition: thread_specific_storage.h:53
Represents thread-specific storage (TSS).
Definition: thread_specific_storage.h:61