diff options
author | lloyd <[email protected]> | 2010-08-13 15:13:21 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-08-13 15:13:21 +0000 |
commit | 3da3b04e1ba1577b3d0e1b4b9b3f4b24381fc433 (patch) | |
tree | 8a4b3a3b8e830ffcbd41f41859db4ab4fd972fb2 /src/alloc/mem_pool | |
parent | 2cae6ec17984ad016f973d5925860278e575b3f4 (diff) | |
parent | 789cee0888bbede838a2a3cf6221677c9f172872 (diff) |
propagate from branch 'net.randombit.botan' (head 0a3348f52bf558bc2282e1066c2913a72a1aeda5)
to branch 'net.randombit.botan.c++0x' (head 552c20ae8874f12da779fc25ea368e36e71cbfe8)
Diffstat (limited to 'src/alloc/mem_pool')
-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 |
3 files changed, 10 insertions, 18 deletions
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 4180d2602..ba82fefdc 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, u32bit 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(u32bit n) const u32bit BITMAP_SIZE = Memory_Block::bitmap_size(); const u32bit 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, u32bit 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, u32bit n) { const u32bit 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(u32bit 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 a67e641e2..f2b57a73b 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(u32bit); @@ -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*, u32bit> > allocated; - Mutex* mutex; + std::mutex mutex; }; } |