27 #ifndef MEMORY_BUFFER_THREAD_HEADER 28 #define MEMORY_BUFFER_THREAD_HEADER 34 #ifdef USE_SSE_INTRINSICS 39 #include <emmintrin.h> 41 #include <pmmintrin.h> 49 class Memory_aligned {
51 inline void *
operator new (
size_t s) {
52 void * p = _mm_malloc (s, 16);
54 throw std::bad_alloc();
59 inline void *
operator new[] (
size_t s) {
60 void * p = _mm_malloc (s, 16);
62 throw std::bad_alloc();
67 inline void operator delete (
void * p) {
71 inline void operator delete[] (
void * p) {
76 class Memory_buffer_thread :
public Memory_aligned {
80 static Memory_buffer_thread* ptr_to_instance;
83 static volatile char ptr_to_instance_is_valid;
84 static unsigned int bufSize;
85 Memory_buffer_thread(Memory_buffer_thread
const &);
87 Memory_buffer_thread() {}
90 static Memory_buffer_thread& instance();
92 void get_buffer(
size_t size, T* & buffer)
const {
93 if (
sizeof(T) * size > bufSize)
94 throw std::runtime_error(
"In Memory_buffer_thread::get_buffer : " 95 "Allocated buffer smaller than requested " 99 for (
int ind = 0; ind <= omp_get_level(); ind++) {
100 int tmp = omp_get_ancestor_thread_num(ind);
101 threadID = threadID > tmp ? threadID : tmp;
105 throw std::runtime_error(
"In Memory_buffer_thread::get_buffer : " 107 if ((
unsigned)threadID >= buffers.size())
108 throw std::runtime_error(
"In Memory_buffer_thread::get_buffer : " 109 "thread id larger than number of buffers");
110 buffer = (T*)buffers[threadID];
112 void init_buffers(
unsigned int const nThreads);
113 ~Memory_buffer_thread();
115 std::vector<char*> buffers;
Definition: allocate.cc:30