/*************************************************************************** * Copyright (C) 2012 by Terraneo Federico and Luigi Rucco * * * * This program 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 2 of the License, or * * (at your option) any later version. * * * * This program 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. * * * * As a special exception, if other files instantiate templates or use * * macros or inline functions from this file, or you compile this file * * and link it with other works to produce a work based on this file, * * this file does not by itself cause the resulting work to be covered * * by the GNU General Public License. However the source code for this * * file must still be made available in accordance with the GNU General * * Public License. This exception does not invalidate any other reasons * * why a work based on this file might be covered by the GNU General * * Public License. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see * ***************************************************************************/ #ifndef PROCESS_POOL #define PROCESS_POOL #include #ifndef TEST_ALLOC #include #else //TEST_ALLOC #include #include #include #endif //TEST_ALLOC #ifdef WITH_PROCESSES namespace miosix { /** * This class allows to handle a memory area reserved for the allocation of * processes' images. This memory area is called process pool. */ class ProcessPool { public: /** * \return an instance of the process pool (singleton) */ static ProcessPool& instance(); /** * Allocate memory inside the process pool. * \param size size of the requested memory, must be a power of two, * and be grater or equal to blockSize. * \return a pointer to the allocated memory. Note that the pointer is * size-aligned, so that for example if a 16KByte block is requested, * the returned pointer is aligned on a 16KB boundary. This is so to * allow using the MPU of the Cortex-M3. * \throws runtime_error in case the requested allocation is invalid, * or bad_alloc if out of memory */ unsigned int *allocate(unsigned int size); /** * Deallocate a memory block. * \param ptr pointer to deallocate. * \throws runtime_error if the pointer is invalid */ void deallocate(unsigned int *ptr); #ifdef TEST_ALLOC /** * Print the state of the allocator, used for debugging */ void printAllocatedBlocks() { using namespace std; map::iterator it; cout<second << " allocated @ " << it->first< allocatedBlocks; #ifndef TEST_ALLOC miosix::FastMutex mutex; ///< Mutex to guard concurrent access #endif //TEST_ALLOC }; } //namespace miosix #endif //WITH_PROCESSES #endif //PROCESS_POOL