Wrapped the global_resource_pool into a function in an attempt to

ensure it is initialized before anyone that references it.
This commit is contained in:
Aaron Giles 2012-01-26 20:35:51 +00:00
parent bc6f400f27
commit eb79c00418
4 changed files with 24 additions and 21 deletions

View File

@ -112,9 +112,6 @@ private:
// GLOBALS
//**************************************************************************
// global resource pool to handle allocations outside of the emulator context
resource_pool global_resource_pool(6151);
// dummy zeromem object
const zeromem_t zeromem = { };
@ -126,6 +123,12 @@ bool memory_entry::s_tracking = false;
memory_entry *memory_entry::s_hash[memory_entry::k_hash_prime] = { NULL };
memory_entry *memory_entry::s_freehead = NULL;
// wrapper for the global resource pool to help ensure construction order
resource_pool &global_resource_pool()
{
static resource_pool s_pool(6151);
return s_pool;
};
//**************************************************************************

View File

@ -74,11 +74,11 @@
#define pool_free(_pool, v) (_pool).remove(v)
// global allocation helpers
#define global_alloc(_type) pool_alloc(global_resource_pool, _type)
#define global_alloc_clear(_type) pool_alloc_clear(global_resource_pool, _type)
#define global_alloc_array(_type, _num) pool_alloc_array(global_resource_pool, _type, _num)
#define global_alloc_array_clear(_type, _num) pool_alloc_array_clear(global_resource_pool, _type, _num)
#define global_free(v) pool_free(global_resource_pool, v)
#define global_alloc(_type) pool_alloc(global_resource_pool(), _type)
#define global_alloc_clear(_type) pool_alloc_clear(global_resource_pool(), _type)
#define global_alloc_array(_type, _num) pool_alloc_array(global_resource_pool(), _type, _num)
#define global_alloc_array_clear(_type, _num) pool_alloc_array_clear(global_resource_pool(), _type, _num)
#define global_free(v) pool_free(global_resource_pool(), v)
@ -281,7 +281,7 @@ private:
public:
resource_pool(int hash_size = 193);
~resource_pool();
virtual ~resource_pool();
void add(resource_pool_item &item);
void remove(resource_pool_item &item) { remove(item.m_ptr); }
@ -308,13 +308,13 @@ private:
// GLOBAL VARIABLES
//**************************************************************************
// global resource pool
extern resource_pool global_resource_pool;
// dummy objects to pass to the specialized new variants
extern const zeromem_t zeromem;
resource_pool &global_resource_pool();
//**************************************************************************
// ADDDITIONAL MACROS

View File

@ -59,11 +59,11 @@ class simple_list
public:
// construction/destruction
simple_list(resource_pool &pool = global_resource_pool) :
m_head(NULL),
m_tail(NULL),
m_pool(pool),
m_count(0) { }
simple_list(resource_pool &pool = global_resource_pool())
: m_head(NULL),
m_tail(NULL),
m_pool(pool),
m_count(0) { }
virtual ~simple_list() { reset(); }
@ -307,7 +307,7 @@ class fixed_allocator
public:
// construction/destruction
fixed_allocator(resource_pool &pool = global_resource_pool)
fixed_allocator(resource_pool &pool = global_resource_pool())
: m_freelist(pool) { }
// allocate a new item, either by recycling an old one, or by allocating a new one
@ -343,8 +343,8 @@ class tagged_list
public:
// construction/destruction
tagged_list(resource_pool &pool = global_resource_pool) :
m_list(pool) { }
tagged_list(resource_pool &pool = global_resource_pool())
: m_list(pool) { }
// simple getters
resource_pool &pool() const { return m_list.pool(); }

View File

@ -260,7 +260,7 @@ class render_screen_list
public:
// construction/destruction
render_screen_list(resource_pool &pool = global_resource_pool)
render_screen_list(resource_pool &pool = global_resource_pool())
: m_list(pool) { }
// getters