aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-11-17 07:20:51 +0000
committerlloyd <[email protected]>2009-11-17 07:20:51 +0000
commit7a24783fd58b21e1ea59615025806663e5f231eb (patch)
treeb77c685e0b54f82890947009631461bcfe5b6880 /src/alloc
parente00b46cf9c1dcb364ebb7d5968d6ff9dcd600c4e (diff)
parent471847e2148776e62e4f580ade95572fc525c751 (diff)
propagate from branch 'net.randombit.botan' (head 0ac5a29496b4e50775827d9655c064f6d1c98813)
to branch 'net.randombit.botan.c++0x' (head 3232da044d41756582b53da9d14c3ac07e9b2916)
Diffstat (limited to 'src/alloc')
-rw-r--r--src/alloc/alloc_mmap/mmap_mem.h1
-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.h6
-rw-r--r--src/alloc/system_alloc/defalloc.h2
5 files changed, 10 insertions, 18 deletions
diff --git a/src/alloc/alloc_mmap/mmap_mem.h b/src/alloc/alloc_mmap/mmap_mem.h
index bef166a16..30e6d9ebb 100644
--- a/src/alloc/alloc_mmap/mmap_mem.h
+++ b/src/alloc/alloc_mmap/mmap_mem.h
@@ -18,7 +18,6 @@ namespace Botan {
class BOTAN_DLL 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/alloc/mem_pool/info.txt b/src/alloc/mem_pool/info.txt
index 73a548292..b57a8b647 100644
--- a/src/alloc/mem_pool/info.txt
+++ b/src/alloc/mem_pool/info.txt
@@ -4,7 +4,3 @@ load_on auto
mem_pool.cpp
mem_pool.h
</add>
-
-<requires>
-mutex
-</requires>
diff --git a/src/alloc/mem_pool/mem_pool.cpp b/src/alloc/mem_pool/mem_pool.cpp
index e30a7b98a..820355678 100644
--- a/src/alloc/mem_pool/mem_pool.cpp
+++ b/src/alloc/mem_pool/mem_pool.cpp
@@ -109,7 +109,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();
}
@@ -119,7 +119,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");
}
@@ -129,7 +128,7 @@ Pooling_Allocator::~Pooling_Allocator()
*/
void Pooling_Allocator::destroy()
{
- Mutex_Holder lock(mutex);
+ std::lock_guard<std::mutex> lock(mutex);
blocks.clear();
@@ -146,7 +145,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)
{
@@ -183,7 +182,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);
@@ -191,8 +190,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");
@@ -209,7 +208,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 51571405e..dd463d908 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/mutex.h>
+#include <mutex>
#include <utility>
#include <vector>
@@ -27,7 +27,7 @@ class BOTAN_DLL Pooling_Allocator : public Allocator
void destroy();
- Pooling_Allocator(Mutex*);
+ Pooling_Allocator();
~Pooling_Allocator();
private:
void get_more_core(u32bit);
@@ -66,7 +66,7 @@ class BOTAN_DLL 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;
};
}
diff --git a/src/alloc/system_alloc/defalloc.h b/src/alloc/system_alloc/defalloc.h
index 627e8df70..ed2682ec0 100644
--- a/src/alloc/system_alloc/defalloc.h
+++ b/src/alloc/system_alloc/defalloc.h
@@ -30,8 +30,6 @@ 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);