mbed OS5

Fork of UIPEthernet by Zoltan Hudak

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mempool.h Source File

mempool.h

00001 /*
00002  mempool.h - sleek implementation of a memory pool
00003  Copyright (c) 2013 Norbert Truchsess <norbert.truchsess@t-online.de>
00004  All rights reserved.
00005 
00006  This program is free software: you can redistribute it and/or modify
00007  it under the terms of the GNU General Public License as published by
00008  the Free Software Foundation, either version 3 of the License, or
00009  (at your option) any later version.
00010 
00011  This program is distributed in the hope that it will be useful,
00012  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  GNU General Public License for more details.
00015 
00016  You should have received a copy of the GNU General Public License
00017  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018  */
00019 #ifndef MEMPOOL_H
00020 #define MEMPOOL_H
00021 
00022 #include <inttypes.h>
00023 
00024 #define POOLSTART   0
00025 #define NOBLOCK     0
00026 
00027 #include "mempool_conf.h"
00028 
00029 struct memblock
00030 {
00031     memaddress  begin;
00032     memaddress  size;
00033     memhandle   nextblock;
00034 };
00035 
00036 class   myMemoryPool
00037 {
00038 #ifdef MEMPOOLTEST_H
00039     friend class    MemoryPoolTest;
00040 #endif
00041 protected:
00042     static struct memblock  blocks[MEMPOOL_NUM_MEMBLOCKS + 1];
00043 public:
00044     static void         init(void);
00045     static memhandle    allocBlock(memaddress);
00046     static void         freeBlock(memhandle);
00047     static void         resizeBlock(memhandle handle, memaddress position);
00048     static void         resizeBlock(memhandle handle, memaddress position, memaddress size);
00049     static memaddress   blockSize(memhandle);
00050 };
00051 #endif