diff options
Diffstat (limited to 'src/alloc')
-rw-r--r-- | src/alloc/alloc_mmap/mmap_mem.cpp | 2 | ||||
-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 | 27 | ||||
-rw-r--r-- | src/alloc/mem_pool/mem_pool.h | 9 | ||||
-rw-r--r-- | src/alloc/system_alloc/defalloc.h | 5 |
6 files changed, 17 insertions, 34 deletions
diff --git a/src/alloc/alloc_mmap/mmap_mem.cpp b/src/alloc/alloc_mmap/mmap_mem.cpp index e4b602764..bdc3fcab9 100644 --- a/src/alloc/alloc_mmap/mmap_mem.cpp +++ b/src/alloc/alloc_mmap/mmap_mem.cpp @@ -123,7 +123,7 @@ void* MemoryMapping_Allocator::alloc_block(size_t n) */ void MemoryMapping_Allocator::dealloc_block(void* ptr, size_t n) { - if(ptr == 0) + if(ptr == nullptr) return; const byte PATTERNS[] = { 0x00, 0xF5, 0x5A, 0xAF, 0x00 }; 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..770622149 100644 --- a/src/alloc/mem_pool/mem_pool.cpp +++ b/src/alloc/mem_pool/mem_pool.cpp @@ -46,7 +46,7 @@ byte* Pooling_Allocator::Memory_Block::alloc(size_t n) if(n == BITMAP_SIZE) { if(bitmap) - return 0; + return nullptr; else { bitmap = ~bitmap; @@ -69,7 +69,7 @@ byte* Pooling_Allocator::Memory_Block::alloc(size_t n) } if(bitmap & mask) - return 0; + return nullptr; bitmap |= mask; return buffer + offset * BLOCK_SIZE; @@ -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) { @@ -167,10 +166,10 @@ void Pooling_Allocator::deallocate(void* ptr, size_t n) const size_t BITMAP_SIZE = Memory_Block::bitmap_size(); const size_t BLOCK_SIZE = Memory_Block::block_size(); - if(ptr == 0 && n == 0) + if(ptr == nullptr && 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"); @@ -194,9 +193,9 @@ void Pooling_Allocator::deallocate(void* ptr, size_t n) byte* Pooling_Allocator::allocate_blocks(size_t n) { if(blocks.empty()) - return 0; + return nullptr; - std::vector<Memory_Block>::iterator i = last_used; + auto i = last_used; do { @@ -213,7 +212,7 @@ byte* Pooling_Allocator::allocate_blocks(size_t n) } while(i != last_used); - return 0; + return nullptr; } /* @@ -233,7 +232,7 @@ void Pooling_Allocator::get_more_core(size_t in_bytes) const size_t to_allocate = in_blocks * TOTAL_BLOCK_SIZE; void* ptr = alloc_block(to_allocate); - if(ptr == 0) + if(ptr == nullptr) throw Memory_Exhaustion(); allocated.push_back(std::make_pair(ptr, to_allocate)); 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); |