annotate projects/heavy/envelopeTrigger/MessagePool.h @ 162:c3e8226a5651 heavy-updated

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