Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-24 02:18:58

0001 #ifndef FWCore_Utilities_zero_allocator_h
0002 #define FWCore_Utilities_zero_allocator_h
0003 /*
0004     Copyright (c) 2005-2020 Intel Corporation
0005 
0006     Licensed under the Apache License, Version 2.0 (the "License");
0007     you may not use this file except in compliance with the License.
0008     You may obtain a copy of the License at
0009 
0010         http://www.apache.org/licenses/LICENSE-2.0
0011 
0012     Unless required by applicable law or agreed to in writing, software
0013     distributed under the License is distributed on an "AS IS" BASIS,
0014     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0015     See the License for the specific language governing permissions and
0016     limitations under the License.
0017 */
0018 
0019 #include "oneapi/tbb/tbb_allocator.h"
0020 #include <cstring>
0021 
0022 /* Copied from tbb_2020 branch's tbb/tbb_allocator linked here
0023    https://github.com/oneapi-src/oneTBB/blob/tbb_2020/include/tbb/tbb_allocator.h
0024    and renamed to edm namespace because it was removed from oneapi_2021 branch's
0025    tbb/tbb_allocator.
0026  */
0027 
0028 namespace edm {
0029   template <typename T, template <typename X> class Allocator = oneapi::tbb::tbb_allocator>
0030   class zero_allocator : public Allocator<T> {
0031   public:
0032     using value_type = T;
0033     using base_allocator_type = Allocator<T>;
0034     template <typename U>
0035     struct rebind {
0036       typedef zero_allocator<U, Allocator> other;
0037     };
0038 
0039     zero_allocator() throw() {}
0040     zero_allocator(const zero_allocator &a) throw() : base_allocator_type(a) {}
0041     template <typename U>
0042     zero_allocator(const zero_allocator<U> &a) throw() : base_allocator_type(Allocator<U>(a)) {}
0043 
0044     T *allocate(const std::size_t n, const void *hint = nullptr) {
0045       //T* ptr = base_allocator_type::allocate( n, hint );
0046       T *ptr = base_allocator_type::allocate(n);
0047       std::memset(static_cast<void *>(ptr), 0, n * sizeof(value_type));
0048       return ptr;
0049     }
0050   };
0051 
0052   template <typename T1, template <typename X1> class B1, typename T2, template <typename X2> class B2>
0053   inline bool operator==(const zero_allocator<T1, B1> &a, const zero_allocator<T2, B2> &b) {
0054     return static_cast<B1<T1> >(a) == static_cast<B2<T2> >(b);
0055   }
0056   template <typename T1, template <typename X1> class B1, typename T2, template <typename X2> class B2>
0057   inline bool operator!=(const zero_allocator<T1, B1> &a, const zero_allocator<T2, B2> &b) {
0058     return static_cast<B1<T1> >(a) != static_cast<B2<T2> >(b);
0059   }
0060 }  // namespace edm
0061 #endif