Move ItemPool compatiblity into the header and rename

This commit is contained in:
Chris Young 2016-11-20 16:30:33 +00:00
parent b3042f6c1f
commit 17128fd0ad
5 changed files with 39 additions and 76 deletions

View File

@ -3829,7 +3829,7 @@ gui_window_create(struct browser_window *bw,
NewList(&g->dllist);
g->deferred_rects = NewObjList();
g->deferred_rects_pool = ami_misc_itempool_create(sizeof(struct rect));
g->deferred_rects_pool = ami_memory_itempool_create(sizeof(struct rect));
g->bw = bw;
g->scale = browser_window_get_scale(bw);
@ -4492,7 +4492,7 @@ static void gui_window_destroy(struct gui_window *g)
ami_free_download_list(&g->dllist);
FreeObjList(g->deferred_rects);
ami_misc_itempool_delete(g->deferred_rects_pool);
ami_memory_itempool_delete(g->deferred_rects_pool);
gui_window_stop_throbber(g);
cur_gw = NULL;
@ -4705,7 +4705,7 @@ static void ami_gui_window_update_box_deferred(struct gui_window *g, bool draw)
rect->x0, rect->y0, rect->x1, rect->y1);
}
nnode=(struct nsObject *)GetSucc((struct Node *)node);
ami_misc_itempool_free(g->deferred_rects_pool, node->objstruct, sizeof(struct rect));
ami_memory_itempool_free(g->deferred_rects_pool, node->objstruct, sizeof(struct rect));
DelObjectNoFree(node);
} while((node = nnode));
@ -4739,7 +4739,7 @@ static bool ami_gui_window_update_box_deferred_check(struct MinList *deferred_re
(new_rect->x1 >= rect->x1) &&
(new_rect->y1 >= rect->y1)) {
LOG("Removing queued redraw that is a subset of new box redraw");
ami_misc_itempool_free(mempool, node->objstruct, sizeof(struct rect));
ami_memory_itempool_free(mempool, node->objstruct, sizeof(struct rect));
DelObjectNoFree(node);
/* Don't return - we might find more */
}
@ -4756,7 +4756,7 @@ static void gui_window_update_box(struct gui_window *g, const struct rect *restr
if(ami_gui_window_update_box_deferred_check(g->deferred_rects, rect,
g->deferred_rects_pool)) {
deferred_rect = ami_misc_itempool_alloc(g->deferred_rects_pool, sizeof(struct rect));
deferred_rect = ami_memory_itempool_alloc(g->deferred_rects_pool, sizeof(struct rect));
CopyMem(rect, deferred_rect, sizeof(struct rect));
nsobj = AddObject(g->deferred_rects, AMINS_RECT);
nsobj->objstruct = deferred_rect;

View File

@ -23,68 +23,13 @@
#ifndef __amigaos4__
ULONG __slab_max_size = 8192; /* Enable clib2's slab allocator */
#endif
/* Special clear (ie. non-zero), which is different on OS3 and 4 */
/* Special clear (ie. non-zero) */
void *ami_memory_clear_alloc(size_t size, UBYTE value)
{
#ifdef __amigaos4__
return AllocVecTags(size, AVT_ClearWithValue, value, TAG_DONE);
#else
void *mem = malloc(size);
if (mem) memset(mem, value, size);
return mem;
#endif
}
/* Free special clear (ie. non-zero) area, which is different on OS3 and 4 */
void ami_memory_clear_free(void *p)
{
#ifdef __amigaos4__
FreeVec(p);
#else
free(p);
#endif
}
APTR ami_misc_itempool_create(int size)
{
#ifdef __amigaos4__
return AllocSysObjectTags(ASOT_ITEMPOOL,
ASOITEM_MFlags, MEMF_PRIVATE,
ASOITEM_ItemSize, size,
ASOITEM_GCPolicy, ITEMGC_AFTERCOUNT,
ASOITEM_GCParameter, 100,
TAG_DONE);
#else
return CreatePool(MEMF_ANY, 20 * size, size);
#endif
}
void ami_misc_itempool_delete(APTR pool)
{
#ifdef __amigaos4__
FreeSysObject(ASOT_ITEMPOOL, pool);
#else
DeletePool(pool);
#endif
}
APTR ami_misc_itempool_alloc(APTR pool, int size)
{
#ifdef __amigaos4__
return ItemPoolAlloc(pool);
#else
return AllocPooled(pool, size);
#endif
}
void ami_misc_itempool_free(APTR restrict pool, APTR restrict item, int size)
{
#ifdef __amigaos4__
ItemPoolFree(pool, item);
#else
FreePooled(pool, item, size);
#endif
}

View File

@ -31,13 +31,31 @@
#endif
/* Alloc/free a block cleared to non-zero */
#ifdef __amigaos4__
#define ami_memory_clear_alloc(s,v) AllocVecTags(s, AVT_ClearWithValue, v, TAG_DONE)
#define ami_memory_clear_free(p) FreeVec(p)
#else
void *ami_memory_clear_alloc(size_t size, UBYTE value);
void ami_memory_clear_free(void *p);
/* Itempool cross-compatibility */
APTR ami_misc_itempool_create(int size);
void ami_misc_itempool_delete(APTR pool);
APTR ami_misc_itempool_alloc(APTR pool, int size);
void ami_misc_itempool_free(APTR pool, APTR item, int size);
#define ami_memory_clear_free(p) free(p)
#endif
/* Itempool cross-compatibility */
#ifdef __amigaos4__
#define ami_memory_itempool_create(s) AllocSysObjectTags(ASOT_ITEMPOOL, \
ASOITEM_MFlags, MEMF_PRIVATE, \
ASOITEM_ItemSize, s, \
ASOITEM_GCPolicy, ITEMGC_AFTERCOUNT, \
ASOITEM_GCParameter, 100, \
TAG_DONE)
#define ami_memory_itempool_delete(p) FreeSysObject(ASOT_ITEMPOOL, p)
#define ami_memory_itempool_alloc(p,s) ItemPoolAlloc(p)
#define ami_memory_itempool_free(p,i,s) ItemPoolFree(p,i)
#else
#define ami_memory_itempool_create(s) CreatePool(MEMF_ANY, 20 * s, s)
#define ami_memory_itempool_delete(p) DeletePool(p)
#define ami_memory_itempool_alloc(p,s) AllocPooled(p, s)
#define ami_memory_itempool_free(p,i,s) FreePooled(p,i,s)
#endif
#endif //AMIGA_MEMORY_H

View File

@ -41,7 +41,7 @@ static APTR pool_nsobj = NULL;
bool ami_object_init(void)
{
pool_nsobj = ami_misc_itempool_create(sizeof(struct nsObject));
pool_nsobj = ami_memory_itempool_create(sizeof(struct nsObject));
if(pool_nsobj == NULL) return false;
else return true;
@ -49,7 +49,7 @@ bool ami_object_init(void)
void ami_object_fini(void)
{
ami_misc_itempool_delete(pool_nsobj);
ami_memory_itempool_delete(pool_nsobj);
}
/* Slightly abstract MinList initialisation */
@ -78,7 +78,7 @@ struct nsObject *AddObject(struct MinList *objlist, ULONG otype)
{
struct nsObject *dtzo;
dtzo = (struct nsObject *)ami_misc_itempool_alloc(pool_nsobj, sizeof(struct nsObject));
dtzo = (struct nsObject *)ami_memory_itempool_alloc(pool_nsobj, sizeof(struct nsObject));
if(dtzo == NULL) return NULL;
memset(dtzo, 0, sizeof(struct nsObject));
@ -100,7 +100,7 @@ static void DelObjectInternal(struct nsObject *dtzo, BOOL free_obj)
if(dtzo->callback != NULL) dtzo->callback(dtzo->objstruct);
if(dtzo->objstruct && free_obj) free(dtzo->objstruct);
if(dtzo->dtz_Node.ln_Name) free(dtzo->dtz_Node.ln_Name);
ami_misc_itempool_free(pool_nsobj, dtzo, sizeof(struct nsObject));
ami_memory_itempool_free(pool_nsobj, dtzo, sizeof(struct nsObject));
dtzo = NULL;
}

View File

@ -193,7 +193,7 @@ void ami_init_layers(struct gui_globals *gg, ULONG width, ULONG height, bool for
InitTmpRas(gg->rp->TmpRas, gg->tmprasbuf, width*height);
if((gg->palette_mapped == true) && (pool_pens == NULL)) {
pool_pens = ami_misc_itempool_create(sizeof(struct ami_plot_pen));
pool_pens = ami_memory_itempool_create(sizeof(struct ami_plot_pen));
}
gg->apen = 0x00000000;
@ -210,7 +210,7 @@ void ami_free_layers(struct gui_globals *gg)
init_layers_count--;
if((init_layers_count == 0) && (pool_pens != NULL)) {
ami_misc_itempool_delete(pool_pens);
ami_memory_itempool_delete(pool_pens);
pool_pens = NULL;
}
@ -256,7 +256,7 @@ static ULONG ami_plot_obtain_pen(struct MinList *shared_pens, ULONG colr)
if(pen == -1) LOG("WARNING: Cannot allocate pen for ABGR:%lx", colr);
if((shared_pens != NULL) && (pool_pens != NULL)) {
if((node = (struct ami_plot_pen *)ami_misc_itempool_alloc(pool_pens, sizeof(struct ami_plot_pen)))) {
if((node = (struct ami_plot_pen *)ami_memory_itempool_alloc(pool_pens, sizeof(struct ami_plot_pen)))) {
node->pen = pen;
AddTail((struct List *)shared_pens, (struct Node *)node);
}
@ -280,7 +280,7 @@ void ami_plot_release_pens(struct MinList *shared_pens)
nnode = (struct ami_plot_pen *)GetSucc((struct Node *)node);
ReleasePen(scrn->ViewPort.ColorMap, node->pen);
Remove((struct Node *)node);
ami_misc_itempool_free(pool_pens, node, sizeof(struct ami_plot_pen));
ami_memory_itempool_free(pool_pens, node, sizeof(struct ami_plot_pen));
} while((node = nnode));
glob->apen = 0x00000000;