annotate projects/heavy/samphold/MessagePool.h @ 160:5bcf04234f80 heavy-updated

- added -std=c99 to Makefile for user-supplied C files (required for heavy files) - changed heavy core render.cpp file to use latest API and removed all redundant functions (e.g. foleyDesigner/touchkey stuff) - use build_pd.sh to compile and run pd files (-h for usage instructions)
author chnrx <chris.heinrichs@gmail.com>
date Thu, 05 Nov 2015 18:58:26 +0000
parents
children
rev   line source
chris@160 1 /**
chris@160 2 * Copyright (c) 2014, 2015, Enzien Audio Ltd.
chris@160 3 *
chris@160 4 * Permission to use, copy, modify, and/or distribute this software for any
chris@160 5 * purpose with or without fee is hereby granted, provided that the above
chris@160 6 * copyright notice and this permission notice appear in all copies.
chris@160 7 *
chris@160 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
chris@160 9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
chris@160 10 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
chris@160 11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
chris@160 12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
chris@160 13 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
chris@160 14 * PERFORMANCE OF THIS SOFTWARE.
chris@160 15 */
chris@160 16
chris@160 17 #ifndef _MESSAGE_POOL_H_
chris@160 18 #define _MESSAGE_POOL_H_
chris@160 19
chris@160 20 #include "Utils.h"
chris@160 21
chris@160 22 struct HvMessage;
chris@160 23
chris@160 24 #define MP_NUM_MESSAGE_LISTS 4
chris@160 25
chris@160 26 typedef struct MessagePoolList {
chris@160 27 struct MessageListNode *head; // list of currently available blocks
chris@160 28 struct MessageListNode *pool; // list of currently used blocks
chris@160 29 } MessagePoolList;
chris@160 30
chris@160 31 typedef struct MessagePool {
chris@160 32 char *buffer; // the buffer of all messages
chris@160 33 hv_size_t bufferSize; // in bytes
chris@160 34 hv_size_t bufferIndex; // the number of total reserved bytes
chris@160 35
chris@160 36 MessagePoolList lists[MP_NUM_MESSAGE_LISTS];
chris@160 37 } MessagePool;
chris@160 38
chris@160 39 /**
chris@160 40 * The MessagePool is a basic memory management system. It reserves a large block of memory at initialisation
chris@160 41 * and proceeds to divide this block into smaller chunks (usually 512 bytes) as they are needed. These chunks are
chris@160 42 * further divided into 32, 64, 128, or 256 sections. Each of these sections is managed by a MessagePoolList (MPL).
chris@160 43 * An MPL is a linked-list data structure which is initialised such that its own pool of listnodes is filled with nodes
chris@160 44 * that point at each subblock (e.g. each 32-byte block of a 512-block chunk).
chris@160 45 *
chris@160 46 * MessagePool is loosely inspired by TCMalloc. http://goog-perftools.sourceforge.net/doc/tcmalloc.html
chris@160 47 */
chris@160 48
chris@160 49 hv_size_t mp_init(struct MessagePool *mp, hv_size_t numKB);
chris@160 50
chris@160 51 void mp_free(struct MessagePool *mp);
chris@160 52
chris@160 53 /**
chris@160 54 * Adds a message to the pool and returns a pointer to the copy. Returns NULL
chris@160 55 * if no space was available in the pool.
chris@160 56 */
chris@160 57 struct HvMessage *mp_addMessage(struct MessagePool *mp, const struct HvMessage *m);
chris@160 58
chris@160 59 void mp_freeMessage(struct MessagePool *mp, struct HvMessage *m);
chris@160 60
chris@160 61 #endif // _MESSAGE_POOL_H_