From eb79c00418108690670219fc1e2231c6bab5b9d4 Mon Sep 17 00:00:00 2001 From: Aaron Giles Date: Thu, 26 Jan 2012 20:35:51 +0000 Subject: [PATCH] Wrapped the global_resource_pool into a function in an attempt to ensure it is initialized before anyone that references it. --- src/emu/emualloc.c | 9 ++++++--- src/emu/emualloc.h | 18 +++++++++--------- src/emu/emutempl.h | 16 ++++++++-------- src/emu/render.h | 2 +- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/emu/emualloc.c b/src/emu/emualloc.c index a091add4b67..c46b64e89e6 100644 --- a/src/emu/emualloc.c +++ b/src/emu/emualloc.c @@ -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; +}; //************************************************************************** diff --git a/src/emu/emualloc.h b/src/emu/emualloc.h index f13deeb906c..48f2897a1d5 100644 --- a/src/emu/emualloc.h +++ b/src/emu/emualloc.h @@ -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 diff --git a/src/emu/emutempl.h b/src/emu/emutempl.h index fcd89c03eb7..413e2cacbbb 100644 --- a/src/emu/emutempl.h +++ b/src/emu/emutempl.h @@ -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(); } diff --git a/src/emu/render.h b/src/emu/render.h index d5444b57b2c..980816300fe 100644 --- a/src/emu/render.h +++ b/src/emu/render.h @@ -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