From bd27a130b13667feb26f3157d67d21f8ddb5986e Mon Sep 17 00:00:00 2001 From: lloyd Date: Mon, 29 Sep 2008 02:25:45 +0000 Subject: Pass a Mutex* as an argument to Pooling_Allocator instead of it grabbing one via a reference to the global state. --- src/core/libstate.cpp | 2 +- src/core/modules.cpp | 6 +++--- src/core/modules.h | 7 +++++-- src/secalloc/alloc_mmap/mmap_mem.h | 1 + src/secalloc/allocators/defalloc.h | 2 ++ src/secalloc/allocators/mem_pool.cpp | 5 ++--- src/secalloc/allocators/mem_pool.h | 2 +- 7 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/core/libstate.cpp b/src/core/libstate.cpp index df9d2b519..60bb24fee 100644 --- a/src/core/libstate.cpp +++ b/src/core/libstate.cpp @@ -239,7 +239,7 @@ void Library_State::initialize(const InitializerOptions& args, cached_default_allocator = 0; - std::vector mod_allocs = modules.allocators(); + std::vector mod_allocs = modules.allocators(mutex_factory); for(u32bit j = 0; j != mod_allocs.size(); ++j) add_allocator(mod_allocs[j]); diff --git a/src/core/modules.cpp b/src/core/modules.cpp index 08ab0cdbb..08553bf00 100644 --- a/src/core/modules.cpp +++ b/src/core/modules.cpp @@ -61,15 +61,15 @@ Mutex_Factory* Builtin_Modules::mutex_factory(bool thread_safe) const /************************************************* * Find any usable allocators * *************************************************/ -std::vector Builtin_Modules::allocators() const +std::vector Builtin_Modules::allocators(Mutex_Factory* mf) const { std::vector allocators; #if defined(BOTAN_HAS_ALLOC_MMAP) - allocators.push_back(new MemoryMapping_Allocator); + allocators.push_back(new MemoryMapping_Allocator(mf->make())); #endif - allocators.push_back(new Locking_Allocator); + allocators.push_back(new Locking_Allocator(mf->make())); allocators.push_back(new Malloc_Allocator); return allocators; diff --git a/src/core/modules.h b/src/core/modules.h index 69a6e1ffb..abbfbb2c6 100644 --- a/src/core/modules.h +++ b/src/core/modules.h @@ -7,6 +7,7 @@ #define BOTAN_MODULE_FACTORIES_H__ #include +#include #include #include @@ -22,7 +23,9 @@ class BOTAN_DLL Modules virtual std::string default_allocator() const = 0; - virtual std::vector allocators() const = 0; + virtual std::vector + allocators(Mutex_Factory*) const = 0; + virtual std::vector engines() const = 0; virtual ~Modules() {} @@ -38,7 +41,7 @@ class BOTAN_DLL Builtin_Modules : public Modules std::string default_allocator() const; - std::vector allocators() const; + std::vector allocators(Mutex_Factory*) const; std::vector engines() const; Builtin_Modules(const InitializerOptions&); diff --git a/src/secalloc/alloc_mmap/mmap_mem.h b/src/secalloc/alloc_mmap/mmap_mem.h index a6f68d039..740aa9ec6 100644 --- a/src/secalloc/alloc_mmap/mmap_mem.h +++ b/src/secalloc/alloc_mmap/mmap_mem.h @@ -16,6 +16,7 @@ namespace Botan { class MemoryMapping_Allocator : public Pooling_Allocator { public: + MemoryMapping_Allocator(Mutex* m) : Pooling_Allocator(m) {} std::string type() const { return "mmap"; } private: void* alloc_block(u32bit); diff --git a/src/secalloc/allocators/defalloc.h b/src/secalloc/allocators/defalloc.h index f162f5c71..dc01ee47f 100644 --- a/src/secalloc/allocators/defalloc.h +++ b/src/secalloc/allocators/defalloc.h @@ -28,6 +28,8 @@ class BOTAN_DLL Malloc_Allocator : public Allocator class BOTAN_DLL Locking_Allocator : public Pooling_Allocator { public: + Locking_Allocator(Mutex* m) : Pooling_Allocator(m) {} + std::string type() const { return "locking"; } private: void* alloc_block(u32bit); diff --git a/src/secalloc/allocators/mem_pool.cpp b/src/secalloc/allocators/mem_pool.cpp index 74d09d5df..0a92997bf 100644 --- a/src/secalloc/allocators/mem_pool.cpp +++ b/src/secalloc/allocators/mem_pool.cpp @@ -6,8 +6,8 @@ *************************************************/ #include -#include #include +#include #include #include @@ -107,9 +107,8 @@ void Pooling_Allocator::Memory_Block::free(void* ptr, u32bit blocks) throw() /************************************************* * Pooling_Allocator Constructor * *************************************************/ -Pooling_Allocator::Pooling_Allocator() +Pooling_Allocator::Pooling_Allocator(Mutex* m) : mutex(m) { - mutex = global_state().get_mutex(); last_used = blocks.begin(); } diff --git a/src/secalloc/allocators/mem_pool.h b/src/secalloc/allocators/mem_pool.h index 3d28034e7..b74e08a8d 100644 --- a/src/secalloc/allocators/mem_pool.h +++ b/src/secalloc/allocators/mem_pool.h @@ -25,7 +25,7 @@ class BOTAN_DLL Pooling_Allocator : public Allocator void destroy(); - Pooling_Allocator(); + Pooling_Allocator(Mutex*); ~Pooling_Allocator(); private: void get_more_core(u32bit); -- cgit v1.2.3