diff options
author | lloyd <[email protected]> | 2010-11-04 20:46:52 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-11-04 20:46:52 +0000 |
commit | e19a323006287c4dba58c6b530fbcafa47a8c8c5 (patch) | |
tree | c9da529f446e9a8b0119dfbb79dcd9787219deb4 /src/alloc | |
parent | 5c1ca36f06ba06e2ba2e22efd7742571c8a7dcd3 (diff) | |
parent | edf4cd93eedf8e6972edaccaea4b7b7ab45faded (diff) |
propagate from branch 'net.randombit.botan' (head 303b2518a80553214b1e5ab4d9b96ef54629cbc7)
to branch 'net.randombit.botan.c++0x' (head d734eefabe4816be4dd3e3e6e7bb13b7ab5be148)
Diffstat (limited to 'src/alloc')
-rw-r--r-- | src/alloc/alloc_mmap/mmap_mem.h | 4 | ||||
-rw-r--r-- | src/alloc/mem_pool/info.txt | 4 | ||||
-rw-r--r-- | src/alloc/mem_pool/mem_pool.cpp | 15 | ||||
-rw-r--r-- | src/alloc/mem_pool/mem_pool.h | 9 | ||||
-rw-r--r-- | src/alloc/system_alloc/defalloc.h | 5 |
5 files changed, 10 insertions, 27 deletions
diff --git a/src/alloc/alloc_mmap/mmap_mem.h b/src/alloc/alloc_mmap/mmap_mem.h index fa4e5e715..c9983ed23 100644 --- a/src/alloc/alloc_mmap/mmap_mem.h +++ b/src/alloc/alloc_mmap/mmap_mem.h @@ -21,10 +21,6 @@ namespace Botan { class MemoryMapping_Allocator : public Pooling_Allocator { public: - /** - * @param mutex used for internal locking - */ - MemoryMapping_Allocator(Mutex* mutex) : Pooling_Allocator(mutex) {} std::string type() const { return "mmap"; } private: void* alloc_block(size_t); diff --git a/src/alloc/mem_pool/info.txt b/src/alloc/mem_pool/info.txt index 5097c325f..f87ea4c4c 100644 --- a/src/alloc/mem_pool/info.txt +++ b/src/alloc/mem_pool/info.txt @@ -6,7 +6,3 @@ mem_pool.cpp <header:internal> mem_pool.h </header:internal> - -<requires> -mutex -</requires> diff --git a/src/alloc/mem_pool/mem_pool.cpp b/src/alloc/mem_pool/mem_pool.cpp index f32eb9604..92515e5b2 100644 --- a/src/alloc/mem_pool/mem_pool.cpp +++ b/src/alloc/mem_pool/mem_pool.cpp @@ -96,7 +96,7 @@ void Pooling_Allocator::Memory_Block::free(void* ptr, size_t blocks) /* * Pooling_Allocator Constructor */ -Pooling_Allocator::Pooling_Allocator(Mutex* m) : mutex(m) +Pooling_Allocator::Pooling_Allocator() { last_used = blocks.begin(); } @@ -106,7 +106,6 @@ Pooling_Allocator::Pooling_Allocator(Mutex* m) : mutex(m) */ Pooling_Allocator::~Pooling_Allocator() { - delete mutex; if(blocks.size()) throw Invalid_State("Pooling_Allocator: Never released memory"); } @@ -116,7 +115,7 @@ Pooling_Allocator::~Pooling_Allocator() */ void Pooling_Allocator::destroy() { - Mutex_Holder lock(mutex); + std::lock_guard<std::mutex> lock(mutex); blocks.clear(); @@ -133,7 +132,7 @@ void* Pooling_Allocator::allocate(size_t n) const size_t BITMAP_SIZE = Memory_Block::bitmap_size(); const size_t BLOCK_SIZE = Memory_Block::block_size(); - Mutex_Holder lock(mutex); + std::lock_guard<std::mutex> lock(mutex); if(n <= BITMAP_SIZE * BLOCK_SIZE) { @@ -170,7 +169,7 @@ void Pooling_Allocator::deallocate(void* ptr, size_t n) if(ptr == 0 && n == 0) return; - Mutex_Holder lock(mutex); + std::lock_guard<std::mutex> lock(mutex); if(n > BITMAP_SIZE * BLOCK_SIZE) dealloc_block(ptr, n); @@ -178,8 +177,8 @@ void Pooling_Allocator::deallocate(void* ptr, size_t n) { const size_t block_no = round_up(n, BLOCK_SIZE) / BLOCK_SIZE; - std::vector<Memory_Block>::iterator i = - std::lower_bound(blocks.begin(), blocks.end(), Memory_Block(ptr)); + auto i = std::lower_bound(blocks.begin(), blocks.end(), + Memory_Block(ptr)); if(i == blocks.end() || !i->contains(ptr, block_no)) throw Invalid_State("Pointer released to the wrong allocator"); @@ -196,7 +195,7 @@ byte* Pooling_Allocator::allocate_blocks(size_t n) if(blocks.empty()) return 0; - std::vector<Memory_Block>::iterator i = last_used; + auto i = last_used; do { diff --git a/src/alloc/mem_pool/mem_pool.h b/src/alloc/mem_pool/mem_pool.h index 28d4dd903..f2225e573 100644 --- a/src/alloc/mem_pool/mem_pool.h +++ b/src/alloc/mem_pool/mem_pool.h @@ -10,7 +10,7 @@ #include <botan/allocate.h> #include <botan/exceptn.h> -#include <botan/internal/mutex.h> +#include <mutex> #include <utility> #include <vector> @@ -27,10 +27,7 @@ class Pooling_Allocator : public Allocator void destroy(); - /** - * @param mutex used for internal locking - */ - Pooling_Allocator(Mutex* mutex); + Pooling_Allocator(); ~Pooling_Allocator(); private: void get_more_core(size_t); @@ -69,7 +66,7 @@ class Pooling_Allocator : public Allocator std::vector<Memory_Block> blocks; std::vector<Memory_Block>::iterator last_used; std::vector<std::pair<void*, size_t> > allocated; - Mutex* mutex; + std::mutex mutex; }; } diff --git a/src/alloc/system_alloc/defalloc.h b/src/alloc/system_alloc/defalloc.h index 6fba0e511..c4b90d081 100644 --- a/src/alloc/system_alloc/defalloc.h +++ b/src/alloc/system_alloc/defalloc.h @@ -30,11 +30,6 @@ class Malloc_Allocator : public Allocator class Locking_Allocator : public Pooling_Allocator { public: - /** - * @param mutex used for internal locking - */ - Locking_Allocator(Mutex* mutex) : Pooling_Allocator(mutex) {} - std::string type() const { return "locking"; } private: void* alloc_block(size_t); |