![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
00001 /* 00002 Copyright 2005-2010 Intel Corporation. All Rights Reserved. 00003 00004 This file is part of Threading Building Blocks. 00005 00006 Threading Building Blocks is free software; you can redistribute it 00007 and/or modify it under the terms of the GNU General Public License 00008 version 2 as published by the Free Software Foundation. 00009 00010 Threading Building Blocks is distributed in the hope that it will be 00011 useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00012 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with Threading Building Blocks; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 00019 As a special exception, you may use this file as part of a free software 00020 library without restriction. Specifically, if other files instantiate 00021 templates or use macros or inline functions from this file, or you compile 00022 this file and link it with other files to produce an executable, this 00023 file does not by itself cause the resulting executable to be covered by 00024 the GNU General Public License. This exception does not however 00025 invalidate any other reasons why the executable file might be covered by 00026 the GNU General Public License. 00027 */ 00028 00029 #ifndef __TBB_cache_aligned_allocator_H 00030 #define __TBB_cache_aligned_allocator_H 00031 00032 #include <new> 00033 #include "tbb_stddef.h" 00034 00035 namespace tbb { 00036 00038 namespace internal { 00040 00041 size_t __TBB_EXPORTED_FUNC NFS_GetLineSize(); 00042 00044 00045 void* __TBB_EXPORTED_FUNC NFS_Allocate( size_t n_element, size_t element_size, void* hint ); 00046 00048 00050 void __TBB_EXPORTED_FUNC NFS_Free( void* ); 00051 } 00053 00054 #if _MSC_VER && !defined(__INTEL_COMPILER) 00055 // Workaround for erroneous "unreferenced parameter" warning in method destroy. 00056 #pragma warning (push) 00057 #pragma warning (disable: 4100) 00058 #endif 00059 00061 00064 template<typename T> 00065 class cache_aligned_allocator { 00066 public: 00067 typedef typename internal::allocator_type<T>::value_type value_type; 00068 typedef value_type* pointer; 00069 typedef const value_type* const_pointer; 00070 typedef value_type& reference; 00071 typedef const value_type& const_reference; 00072 typedef size_t size_type; 00073 typedef ptrdiff_t difference_type; 00074 template<typename U> struct rebind { 00075 typedef cache_aligned_allocator<U> other; 00076 }; 00077 00078 cache_aligned_allocator() throw() {} 00079 cache_aligned_allocator( const cache_aligned_allocator& ) throw() {} 00080 template<typename U> cache_aligned_allocator(const cache_aligned_allocator<U>&) throw() {} 00081 00082 pointer address(reference x) const {return &x;} 00083 const_pointer address(const_reference x) const {return &x;} 00084 00086 pointer allocate( size_type n, const void* hint=0 ) { 00087 // The "hint" argument is always ignored in NFS_Allocate thus const_cast shouldn't hurt 00088 return pointer(internal::NFS_Allocate( n, sizeof(value_type), const_cast<void*>(hint) )); 00089 } 00090 00092 void deallocate( pointer p, size_type ) { 00093 internal::NFS_Free(p); 00094 } 00095 00097 size_type max_size() const throw() { 00098 return (~size_t(0)-internal::NFS_MaxLineSize)/sizeof(value_type); 00099 } 00100 00102 void construct( pointer p, const value_type& value ) {::new((void*)(p)) value_type(value);} 00103 00105 void destroy( pointer p ) {p->~value_type();} 00106 }; 00107 00108 #if _MSC_VER && !defined(__INTEL_COMPILER) 00109 #pragma warning (pop) 00110 #endif // warning 4100 is back 00111 00113 00114 template<> 00115 class cache_aligned_allocator<void> { 00116 public: 00117 typedef void* pointer; 00118 typedef const void* const_pointer; 00119 typedef void value_type; 00120 template<typename U> struct rebind { 00121 typedef cache_aligned_allocator<U> other; 00122 }; 00123 }; 00124 00125 template<typename T, typename U> 00126 inline bool operator==( const cache_aligned_allocator<T>&, const cache_aligned_allocator<U>& ) {return true;} 00127 00128 template<typename T, typename U> 00129 inline bool operator!=( const cache_aligned_allocator<T>&, const cache_aligned_allocator<U>& ) {return false;} 00130 00131 } // namespace tbb 00132 00133 #endif /* __TBB_cache_aligned_allocator_H */
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.