diff options
author | lloyd <[email protected]> | 2006-09-11 00:44:28 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-09-11 00:44:28 +0000 |
commit | 31170c2210d98c2ea8f3fac56ff5f31e27f741af (patch) | |
tree | b43349234dfb36ae0b6e3ea97923e7f5f52eb06e /src/libstate.cpp | |
parent | a563159b999eea2fee0ea94d0baaea06df0ca1df (diff) |
Correctly deal with allocators added post-initialization. In particular,
handle the case where an allocator is added that has the same name as one
already registered.
Flush the cached allocator pointer when the default is changed.
Mark comparison operations in Pooling_Allocator::Memory_Block as inline;
this seems to help the STL sort and binary search algorithms tremendously.
Diffstat (limited to 'src/libstate.cpp')
-rw-r--r-- | src/libstate.cpp | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/src/libstate.cpp b/src/libstate.cpp index 1bb27e74a..a782f4c60 100644 --- a/src/libstate.cpp +++ b/src/libstate.cpp @@ -110,21 +110,28 @@ Allocator* Library_State::get_allocator(const std::string& type) const /************************************************* * Create a new name to object mapping * *************************************************/ -void Library_State::add_allocator(Allocator* allocator, - bool set_as_default) +void Library_State::add_allocator(Allocator* allocator) { Named_Mutex_Holder lock("allocator"); allocator->init(); - const std::string type = allocator->type(); - if(alloc_factory[type]) - delete alloc_factory[type]; + allocators.push_back(allocator); + alloc_factory[allocator->type()] = allocator; + } - alloc_factory[type] = allocator; +/************************************************* +* Set the default allocator type * +*************************************************/ +void Library_State::set_default_allocator(const std::string& type) const + { + Named_Mutex_Holder lock("allocator"); - if(set_as_default) - config().set("conf", "base/default_allocator", type); + if(type == "") + return; + + config().set("conf", "base/default_allocator", type); + cached_default_allocator = 0; } /************************************************* @@ -307,11 +314,11 @@ void Library_State::load(Modules& modules) set_timer(modules.timer()); set_transcoder(modules.transcoder()); - std::vector<Allocator*> allocators = modules.allocators(); + std::vector<Allocator*> mod_allocs = modules.allocators(); + for(u32bit j = 0; j != mod_allocs.size(); j++) + add_allocator(mod_allocs[j]); - for(u32bit j = 0; j != allocators.size(); j++) - add_allocator(allocators[j], - allocators[j]->type() == modules.default_allocator()); + set_default_allocator(modules.default_allocator()); std::vector<Engine*> engines = modules.engines(); for(u32bit j = 0; j != engines.size(); ++j) @@ -361,11 +368,10 @@ Library_State::~Library_State() cached_default_allocator = 0; - for(std::map<std::string, Allocator*>::iterator j = alloc_factory.begin(); - j != alloc_factory.end(); ++j) + for(u32bit j = 0; j != allocators.size(); j++) { - j->second->destroy(); - delete j->second; + allocators[j]->destroy(); + delete allocators[j]; } std::for_each(locks.begin(), locks.end(), |