aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-29 02:25:45 +0000
committerlloyd <[email protected]>2008-09-29 02:25:45 +0000
commitbd27a130b13667feb26f3157d67d21f8ddb5986e (patch)
treeb01a547f8faf911632a90701079bd1c4f41385d6 /src
parent45bde591db0feeb274e137aa021495f823409fd4 (diff)
Pass a Mutex* as an argument to Pooling_Allocator instead of it grabbing
one via a reference to the global state.
Diffstat (limited to 'src')
-rw-r--r--src/core/libstate.cpp2
-rw-r--r--src/core/modules.cpp6
-rw-r--r--src/core/modules.h7
-rw-r--r--src/secalloc/alloc_mmap/mmap_mem.h1
-rw-r--r--src/secalloc/allocators/defalloc.h2
-rw-r--r--src/secalloc/allocators/mem_pool.cpp5
-rw-r--r--src/secalloc/allocators/mem_pool.h2
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<Allocator*> mod_allocs = modules.allocators();
+ std::vector<Allocator*> 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<Allocator*> Builtin_Modules::allocators() const
+std::vector<Allocator*> Builtin_Modules::allocators(Mutex_Factory* mf) const
{
std::vector<Allocator*> 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 <botan/init.h>
+#include <botan/mutex.h>
#include <string>
#include <vector>
@@ -22,7 +23,9 @@ class BOTAN_DLL Modules
virtual std::string default_allocator() const = 0;
- virtual std::vector<class Allocator*> allocators() const = 0;
+ virtual std::vector<class Allocator*>
+ allocators(Mutex_Factory*) const = 0;
+
virtual std::vector<class Engine*> engines() const = 0;
virtual ~Modules() {}
@@ -38,7 +41,7 @@ class BOTAN_DLL Builtin_Modules : public Modules
std::string default_allocator() const;
- std::vector<class Allocator*> allocators() const;
+ std::vector<class Allocator*> allocators(Mutex_Factory*) const;
std::vector<class Engine*> 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 <botan/mem_pool.h>
-#include <botan/libstate.h>
#include <botan/util.h>
+#include <botan/mem_ops.h>
#include <algorithm>
#include <exception>
@@ -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);