Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/oneapi/tbb/combinable.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     Copyright (c) 2005-2021 Intel Corporation
0003 
0004     Licensed under the Apache License, Version 2.0 (the "License");
0005     you may not use this file except in compliance with the License.
0006     You may obtain a copy of the License at
0007 
0008         http://www.apache.org/licenses/LICENSE-2.0
0009 
0010     Unless required by applicable law or agreed to in writing, software
0011     distributed under the License is distributed on an "AS IS" BASIS,
0012     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013     See the License for the specific language governing permissions and
0014     limitations under the License.
0015 */
0016 
0017 #ifndef __TBB_combinable_H
0018 #define __TBB_combinable_H
0019 
0020 #include "detail/_namespace_injection.h"
0021 
0022 #include "enumerable_thread_specific.h"
0023 #include "cache_aligned_allocator.h"
0024 
0025 namespace tbb {
0026 namespace detail {
0027 namespace d1 {
0028 /** \name combinable **/
0029 //@{
0030 //! Thread-local storage with optional reduction
0031 /** @ingroup containers */
0032 template <typename T>
0033 class combinable {
0034     using my_alloc = typename tbb::cache_aligned_allocator<T>;
0035     using my_ets_type = typename tbb::enumerable_thread_specific<T, my_alloc, ets_no_key>;
0036     my_ets_type my_ets;
0037 
0038 public:
0039     combinable() = default;
0040 
0041     template <typename Finit>
0042     explicit combinable(Finit _finit) : my_ets(_finit) { }
0043 
0044     void clear() { my_ets.clear(); }
0045 
0046     T& local() { return my_ets.local(); }
0047 
0048     T& local(bool& exists) { return my_ets.local(exists); }
0049 
0050     // combine_func_t has signature T(T,T) or T(const T&, const T&)
0051     template <typename CombineFunc>
0052     T combine(CombineFunc f_combine) { return my_ets.combine(f_combine); }
0053 
0054     // combine_func_t has signature void(T) or void(const T&)
0055     template <typename CombineFunc>
0056     void combine_each(CombineFunc f_combine) { my_ets.combine_each(f_combine); }
0057 };
0058 
0059 } // namespace d1
0060 } // namespace detail
0061 
0062 inline namespace v1 {
0063 using detail::d1::combinable;
0064 } // inline namespace v1
0065 
0066 } // namespace tbb
0067 
0068 #endif /* __TBB_combinable_H */
0069