1d2e6c4b7SMatthias Ringwald /* 2d2e6c4b7SMatthias Ringwald * Copyright (C) 2014 BlueKitchen GmbH 3d2e6c4b7SMatthias Ringwald * 4d2e6c4b7SMatthias Ringwald * Redistribution and use in source and binary forms, with or without 5d2e6c4b7SMatthias Ringwald * modification, are permitted provided that the following conditions 6d2e6c4b7SMatthias Ringwald * are met: 7d2e6c4b7SMatthias Ringwald * 8d2e6c4b7SMatthias Ringwald * 1. Redistributions of source code must retain the above copyright 9d2e6c4b7SMatthias Ringwald * notice, this list of conditions and the following disclaimer. 10d2e6c4b7SMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright 11d2e6c4b7SMatthias Ringwald * notice, this list of conditions and the following disclaimer in the 12d2e6c4b7SMatthias Ringwald * documentation and/or other materials provided with the distribution. 13d2e6c4b7SMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of 14d2e6c4b7SMatthias Ringwald * contributors may be used to endorse or promote products derived 15d2e6c4b7SMatthias Ringwald * from this software without specific prior written permission. 16d2e6c4b7SMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for 17d2e6c4b7SMatthias Ringwald * personal benefit and not for any commercial purpose or for 18d2e6c4b7SMatthias Ringwald * monetary gain. 19d2e6c4b7SMatthias Ringwald * 20d2e6c4b7SMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21d2e6c4b7SMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22d2e6c4b7SMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23*2fca4dadSMilanka Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN 24*2fca4dadSMilanka Ringwald * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25d2e6c4b7SMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26d2e6c4b7SMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27d2e6c4b7SMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28d2e6c4b7SMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29d2e6c4b7SMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30d2e6c4b7SMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31d2e6c4b7SMatthias Ringwald * SUCH DAMAGE. 32d2e6c4b7SMatthias Ringwald * 33d2e6c4b7SMatthias Ringwald * Please inquire about commercial licensing options at 34d2e6c4b7SMatthias Ringwald * [email protected] 35d2e6c4b7SMatthias Ringwald * 36d2e6c4b7SMatthias Ringwald */ 37d2e6c4b7SMatthias Ringwald 38d2e6c4b7SMatthias Ringwald /* 39d2e6c4b7SMatthias Ringwald * btstack_memory_pool.h 40d2e6c4b7SMatthias Ringwald * 41d2e6c4b7SMatthias Ringwald * @Brief Fixed-size block allocation 42d2e6c4b7SMatthias Ringwald * 43d2e6c4b7SMatthias Ringwald * @Assumption block_size >= sizeof(void *) 44d2e6c4b7SMatthias Ringwald * @Assumption size of storage >= count * block_size 45d2e6c4b7SMatthias Ringwald * 46d2e6c4b7SMatthias Ringwald * @Note minimal implementation, no error checking/handling 47d2e6c4b7SMatthias Ringwald */ 48d2e6c4b7SMatthias Ringwald 4980e33422SMatthias Ringwald #ifndef btstack_memory_pool_H 5080e33422SMatthias Ringwald #define btstack_memory_pool_H 51d2e6c4b7SMatthias Ringwald 52d2e6c4b7SMatthias Ringwald #if defined __cplusplus 53d2e6c4b7SMatthias Ringwald extern "C" { 54d2e6c4b7SMatthias Ringwald #endif 55d2e6c4b7SMatthias Ringwald 5629d0c4f7SMatthias Ringwald typedef void * btstack_memory_pool_t; 57d2e6c4b7SMatthias Ringwald 58d2e6c4b7SMatthias Ringwald // initialize memory pool with with given storage, block size and count 5929d0c4f7SMatthias Ringwald void btstack_memory_pool_create(btstack_memory_pool_t *pool, void * storage, int count, int block_size); 60d2e6c4b7SMatthias Ringwald 616b65794dSMilanka Ringwald // get free block from pool, @return NULL or pointer to block 6229d0c4f7SMatthias Ringwald void * btstack_memory_pool_get(btstack_memory_pool_t *pool); 63d2e6c4b7SMatthias Ringwald 64d2e6c4b7SMatthias Ringwald // return previously reserved block to memory pool 6529d0c4f7SMatthias Ringwald void btstack_memory_pool_free(btstack_memory_pool_t *pool, void * block); 66d2e6c4b7SMatthias Ringwald 67d2e6c4b7SMatthias Ringwald #if defined __cplusplus 68d2e6c4b7SMatthias Ringwald } 69d2e6c4b7SMatthias Ringwald #endif 70d2e6c4b7SMatthias Ringwald 7180e33422SMatthias Ringwald #endif // btstack_memory_pool_H 72