Botan
1.11.15
|
00001 /* 00002 * Mlock Allocator 00003 * (C) 2012 Jack Lloyd 00004 * 00005 * Botan is released under the Simplified BSD License (see license.txt) 00006 */ 00007 00008 #ifndef BOTAN_MLOCK_ALLOCATOR_H__ 00009 #define BOTAN_MLOCK_ALLOCATOR_H__ 00010 00011 #include <botan/types.h> 00012 #include <vector> 00013 #include <mutex> 00014 00015 namespace Botan { 00016 00017 class BOTAN_DLL mlock_allocator 00018 { 00019 public: 00020 static mlock_allocator& instance(); 00021 00022 void* allocate(size_t num_elems, size_t elem_size); 00023 00024 bool deallocate(void* p, size_t num_elems, size_t elem_size); 00025 00026 mlock_allocator(const mlock_allocator&) = delete; 00027 00028 mlock_allocator& operator=(const mlock_allocator&) = delete; 00029 00030 private: 00031 mlock_allocator(); 00032 00033 ~mlock_allocator(); 00034 00035 const size_t m_poolsize; 00036 00037 std::mutex m_mutex; 00038 std::vector<std::pair<size_t, size_t>> m_freelist; 00039 byte* m_pool; 00040 }; 00041 00042 } 00043 00044 #endif