diff options
author | Chris Young <chris@unsatisfactorysoftware.co.uk> | 2013-02-26 20:50:02 +0000 |
---|---|---|
committer | Chris Young <chris@unsatisfactorysoftware.co.uk> | 2013-02-26 20:50:02 +0000 |
commit | 92055076997294c7f360eaec53452a5468785489 (patch) | |
tree | b42f434adc158f49a13251da635dc0c48360e319 | |
parent | 439f14b83969a5bdbce21a3f0143a5d0fbffc8f2 (diff) | |
download | libwapcaplet-92055076997294c7f360eaec53452a5468785489.tar.gz libwapcaplet-92055076997294c7f360eaec53452a5468785489.tar.bz2 |
Keep track of whether the pool allocation is on-chip or not. #ifdef the Amiga-specific parts.
-rwxr-xr-x | src/mempool.c | 44 | ||||
-rwxr-xr-x | src/mempool.h | 45 |
2 files changed, 47 insertions, 42 deletions
diff --git a/src/mempool.c b/src/mempool.c index 5dc5498..4abc772 100755 --- a/src/mempool.c +++ b/src/mempool.c @@ -16,46 +16,50 @@ struct OCMIFace *IOCM = NULL; memory_pool_t * memory_pool_create(size_t bs, size_t c) { - memory_pool_t *mp = malloc(sizeof(memory_pool_t)); - if (!mp) - return NULL; + memory_pool_t *mp = malloc(sizeof(memory_pool_t)); + if (!mp) return NULL; - mp->block_size = bs; - mp->count = c; + mp->block_size = bs; + mp->count = c; mp->pool = NULL; +#ifdef __amigaos4__ + /* NB: This *always* allocates 64K, requests for more than 64K *must not* + * be passed to this function. */ if((ocmb = IExec->OpenResource("onchipmem.resource"))) { if((IOCM = (struct OCMIFace *)IExec->GetInterface((struct Library *)ocmb, "main", 1, NULL))) { mp->pool = IOCM->ObtainOnChipMem(); + mp->ocm = true; } } +#endif if(mp->pool == NULL) { mp->pool = malloc((mp->block_size + sizeof(void *)) * mp->count); + mp->ocm = false; } - memory_pool_clear(mp); - - mp->empty_blocks = mp->pool; + memory_pool_clear(mp); + mp->empty_blocks = mp->pool; - return mp; + return mp; } void memory_pool_destroy(memory_pool_t *mp) { - if (!mp) - return; + if (!mp) return; - memory_pool_clear(mp); + memory_pool_clear(mp); -/**TODO: Track if this is an OCM or standard memory pool. - * At the moment we have no way of freeing on exit so it doesn't matter. - - IOCM->ReleaseOnChipMem(); - IExec->DropInterface((struct Interface *)IOCM); - free(mp->pool); -*/ - free(mp); + if(mp->ocm == true) { +#ifdef __amigaos4__ + IOCM->ReleaseOnChipMem(); + IExec->DropInterface((struct Interface *)IOCM); +#endif + } else { + free(mp->pool); + } + free(mp); } void memory_pool_clear(memory_pool_t *mp) diff --git a/src/mempool.h b/src/mempool.h index c99f239..0d55a1b 100755 --- a/src/mempool.h +++ b/src/mempool.h @@ -1,22 +1,23 @@ -#ifndef MEMPOOL_H
-#define MEMPOOL_H 1
-
-#include <stdlib.h>
-#include <stdint.h>
-#include <stdbool.h>
-
-typedef struct memory_pool_s
-{
- void *pool;
- void *empty_blocks;
- size_t block_size;
- size_t count;
-} __attribute__ ((__aligned__)) memory_pool_t;
-
-memory_pool_t * memory_pool_create(size_t bs, size_t c);
-void memory_pool_destroy(memory_pool_t *mp);
-void memory_pool_clear(memory_pool_t *mp);
-void memory_pool_dump(memory_pool_t *mp, void (* print_func) (void *value));
-void *memory_pool_alloc(memory_pool_t *mp);
-bool memory_pool_free(memory_pool_t *mp, void *p);
-#endif /* MEMPOOL_H */
+#ifndef MEMPOOL_H +#define MEMPOOL_H 1 + +#include <stdlib.h> +#include <stdint.h> +#include <stdbool.h> + +typedef struct memory_pool_s +{ + void *pool; + void *empty_blocks; + size_t block_size; + size_t count; + bool ocm; +} __attribute__ ((__aligned__)) memory_pool_t; + +memory_pool_t * memory_pool_create(size_t bs, size_t c); +void memory_pool_destroy(memory_pool_t *mp); +void memory_pool_clear(memory_pool_t *mp); +void memory_pool_dump(memory_pool_t *mp, void (* print_func) (void *value)); +void *memory_pool_alloc(memory_pool_t *mp); +bool memory_pool_free(memory_pool_t *mp, void *p); +#endif /* MEMPOOL_H */ |