/* * This file is part of RawTherapee. * * Copyright (c) 2004-2012 Gabor Horvath , Oliver Duis * * RawTherapee is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * RawTherapee is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with RawTherapee. If not, see . */ #ifndef _ALIGNEDBUFFER_ #define _ALIGNEDBUFFER_ #include #include #include // Aligned buffer that should be faster template class AlignedBuffer { private: T* real ; public: T* data ; bool inUse; AlignedBuffer (size_t size, size_t align=16) { real = new T[size+2*align]; data = (T*)((uintptr_t)real + (align-((uintptr_t)real)%align)); inUse=true; } ~AlignedBuffer () { delete [] real; } }; // Multi processor version, use with OpenMP template class AlignedBufferMP { private: Glib::Mutex mtx; std::vector*> buffers; size_t size; public: AlignedBufferMP(size_t sizeP) { size=sizeP; } ~AlignedBufferMP() { for (int i=0;i* acquire() { Glib::Mutex::Lock lock(mtx); // Find available buffer for (int i;iinUse) { buffers[i]->inUse=true; return buffers[i]; } } // Add new buffer if nothing is free AlignedBuffer* buffer=new AlignedBuffer(size); buffers.push_back(buffer); return buffer; } void release(AlignedBuffer* buffer) { Glib::Mutex::Lock lock(mtx); buffer->inUse=false; } }; #endif