Get rid of explicit resource tracking for state saving. Now we just use

the auto_ allocators, since registration is restricted to initialization.
This commit is contained in:
Aaron Giles 2009-12-23 16:44:55 +00:00
parent 680184085a
commit 201ea424db
4 changed files with 4 additions and 94 deletions

View File

@ -144,7 +144,6 @@ void begin_resource_tracking(void)
pool_type_register(new_pool, OBJTYPE_ASTRING, "String", astring_destructor);
pool_type_register(new_pool, OBJTYPE_BITMAP, "Bitmap", bitmap_destructor);
pool_type_register(new_pool, OBJTYPE_TIMER, "Timer", timer_destructor);
pool_type_register(new_pool, OBJTYPE_STATEREG, "Save State Registration", state_destructor);
/* increment the tag counter */
resource_tracking_tag++;

View File

@ -24,7 +24,6 @@
#define OBJTYPE_ASTRING OBJECT_TYPE('a','s','t','r')
#define OBJTYPE_BITMAP OBJECT_TYPE('b','i','t','m')
#define OBJTYPE_TIMER OBJECT_TYPE('t','i','m','r')
#define OBJTYPE_STATEREG OBJECT_TYPE('s','t','a','t')

View File

@ -242,7 +242,7 @@ void state_save_register_memory(running_machine *machine, const char *module, co
}
/* create the full name */
totalname = astring_alloc();
totalname = auto_astring_alloc(machine);
if (tag != NULL)
astring_printf(totalname, "%s/%s/%X/%s", module, tag, index, name);
else
@ -263,7 +263,7 @@ void state_save_register_memory(running_machine *machine, const char *module, co
/* didn't find one; allocate a new one */
next = *entryptr;
*entryptr = alloc_clear_or_die(state_entry);
*entryptr = auto_alloc_clear(machine, state_entry);
/* fill in the rest */
(*entryptr)->next = next;
@ -272,7 +272,6 @@ void state_save_register_memory(running_machine *machine, const char *module, co
(*entryptr)->name = totalname;
(*entryptr)->typesize = valsize;
(*entryptr)->typecount = valcount;
restrack_register_object(OBJTYPE_STATEREG, *entryptr, 0, file, line);
}
@ -312,14 +311,13 @@ void state_save_register_presave(running_machine *machine, state_presave_func fu
fatalerror("Duplicate save state function (%p, %p)", param, func);
/* allocate a new entry */
*cbptr = alloc_or_die(state_callback);
*cbptr = auto_alloc(machine, state_callback);
/* fill it in */
(*cbptr)->next = NULL;
(*cbptr)->machine = machine;
(*cbptr)->func.presave = func;
(*cbptr)->param = param;
restrack_register_object(OBJTYPE_STATEREG, *cbptr, 1, __FILE__, __LINE__);
}
@ -343,92 +341,13 @@ void state_save_register_postload(running_machine *machine, state_postload_func
fatalerror("Duplicate save state function (%p, %p)", param, func);
/* allocate a new entry */
*cbptr = alloc_or_die(state_callback);
*cbptr = auto_alloc(machine, state_callback);
/* fill it in */
(*cbptr)->next = NULL;
(*cbptr)->machine = machine;
(*cbptr)->func.postload = func;
(*cbptr)->param = param;
restrack_register_object(OBJTYPE_STATEREG, *cbptr, 2, __FILE__, __LINE__);
}
/***************************************************************************
REGISTRATION FREEING
***************************************************************************/
/*-------------------------------------------------
func_free - free registered functions attached
to the current resource tag
-------------------------------------------------*/
static void func_free(state_callback **rootptr, void *ptr)
{
state_callback **cbptr;
/* iterate over the function list */
for (cbptr = rootptr; *cbptr != NULL; cbptr = &(*cbptr)->next)
if (*cbptr == ptr)
{
state_callback *cb = *cbptr;
/* de-link us from the list and free our memory */
*cbptr = (*cbptr)->next;
free(cb);
break;
}
}
/*-------------------------------------------------
state_save_free - free all registrations that
have been tagged with the current resource
tag
-------------------------------------------------*/
void state_destructor(void *ptr, size_t size)
{
state_private *global = NULL;
/* size of 0 means an entry */
if (size == 0)
{
state_entry **entryptr;
/* iterate over entries */
global = ((state_entry *)ptr)->machine->state_data;
for (entryptr = &global->entrylist; *entryptr != NULL; entryptr = &(*entryptr)->next)
if (*entryptr == ptr)
{
state_entry *entry = *entryptr;
/* de-link us from the list and free our memory */
*entryptr = (*entryptr)->next;
astring_free(entry->name);
free(entry);
break;
}
}
/* size of 1 means a pre function */
else if (size == 1)
{
global = ((state_callback *)ptr)->machine->state_data;
func_free(&global->prefunclist, ptr);
}
/* size of 2 means a post function */
else if (size == 2)
{
global = ((state_callback *)ptr)->machine->state_data;
func_free(&global->postfunclist, ptr);
}
/* if we're clear of all registrations, reset the invalid counter */
if (global != NULL && global->entrylist == NULL && global->prefunclist == NULL && global->postfunclist == NULL)
global->illegal_regs = 0;
}

View File

@ -166,13 +166,6 @@ void state_save_register_postload(running_machine *machine, state_postload_func
/* ----- registration freeing ----- */
/* free all registrations that have been tagged with the current resource tag */
void state_destructor(void *ptr, size_t size);
/* ----- save state file processing ----- */
/* check if a file is a valid save state */