aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc/mem_pool
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-09-03 13:55:19 +0000
committerlloyd <[email protected]>2010-09-03 13:55:19 +0000
commit7e54763ea43c8b34729387c7429922dd981c4f5b (patch)
tree33a1bd0f32e4ab7958a484e468316291c527dd24 /src/alloc/mem_pool
parentfb68795162b8d107cbd284c4a75d8e13ce589829 (diff)
parentec8c59af3db02ff159908f9a446e53c4ea20d474 (diff)
propagate from branch 'net.randombit.botan' (head a29c41b4a949207b1544096c3afab668f8b5179e)
to branch 'net.randombit.botan.c++0x' (head a9d0c2f805b3c20a4c648575d7256959db8329fe)
Diffstat (limited to 'src/alloc/mem_pool')
-rw-r--r--src/alloc/mem_pool/info.txt4
-rw-r--r--src/alloc/mem_pool/mem_pool.cpp15
-rw-r--r--src/alloc/mem_pool/mem_pool.h9
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;
};
}