00001 00029 #ifndef GALOIS_RUNTIME_CACHELINESTORAGE_H 00030 #define GALOIS_RUNTIME_CACHELINESTORAGE_H 00031 00032 #include "Galois/config.h" 00033 #include "Galois/Runtime/ll/CompilerSpecific.h" 00034 00035 #include GALOIS_CXX11_STD_HEADER(utility) 00036 00037 namespace Galois { 00038 namespace Runtime { 00039 namespace LL { 00040 00041 template<typename T, int REM> 00042 struct CacheLineImpl { 00043 GALOIS_ATTRIBUTE_ALIGN_CACHE_LINE T data; 00044 char pad[REM]; 00045 00046 CacheLineImpl() :data() {} 00047 00048 CacheLineImpl(const T& v) :data(v) {} 00049 00050 template<typename A> 00051 explicit CacheLineImpl(A&& v) :data(std::forward<A>(v)) {} 00052 00053 explicit operator T() { return data; } 00054 }; 00055 00056 template<typename T> 00057 struct CacheLineImpl<T, 0> { 00058 GALOIS_ATTRIBUTE_ALIGN_CACHE_LINE T data; 00059 00060 CacheLineImpl() :data() {} 00061 00062 CacheLineImpl(const T& v) :data(v) {} 00063 00064 template<typename A> 00065 explicit CacheLineImpl(A&& v) :data(std::forward<A>(v)) {} 00066 00067 explicit operator T() { return data; } 00068 }; 00069 00070 // Store an item with padding 00071 template<typename T> 00072 struct CacheLineStorage : public CacheLineImpl<T, GALOIS_CACHE_LINE_SIZE % sizeof(T)> { 00073 typedef CacheLineImpl<T, GALOIS_CACHE_LINE_SIZE % sizeof(T)> PTy; 00074 00075 CacheLineStorage() :PTy() {} 00076 00077 CacheLineStorage(const T& v) :PTy(v) {} 00078 00079 // XXX(ddn): Forwarding is still wonky in XLC 00080 #if !defined(__IBMCPP__) || __IBMCPP__ > 1210 00081 template<typename A> 00082 explicit CacheLineStorage(A&& v) :PTy(std::forward<A>(v)) {} 00083 #endif 00084 00085 explicit operator T() { return this->data; } 00086 00087 CacheLineStorage& operator=(const T& v) { this->data = v; return *this; } 00088 }; 00089 00090 } 00091 } 00092 } // end namespace Galois 00093 00094 #endif