mirror of https://github.com/PentHertz/srsLTE.git
adt pool - replace uint8_t* for void* to represent memory blocks
This commit is contained in:
parent
a79ca92020
commit
2fc2280c3b
|
@ -48,7 +48,7 @@ public:
|
||||||
{
|
{
|
||||||
assert(sz == sizeof(T));
|
assert(sz == sizeof(T));
|
||||||
static const size_t blocksize = std::max(sizeof(T), memblock_cache::min_memblock_size());
|
static const size_t blocksize = std::max(sizeof(T), memblock_cache::min_memblock_size());
|
||||||
uint8_t* block = stack.try_pop();
|
void* block = stack.try_pop();
|
||||||
if (block == nullptr) {
|
if (block == nullptr) {
|
||||||
block = new uint8_t[blocksize];
|
block = new uint8_t[blocksize];
|
||||||
}
|
}
|
||||||
|
@ -75,10 +75,10 @@ public:
|
||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
uint8_t* block = stack.try_pop();
|
uint8_t* block = static_cast<uint8_t*>(stack.try_pop());
|
||||||
while (block != nullptr) {
|
while (block != nullptr) {
|
||||||
delete[] block;
|
delete[] block;
|
||||||
block = stack.try_pop();
|
block = static_cast<uint8_t*>(stack.try_pop());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -119,7 +119,7 @@ public:
|
||||||
{
|
{
|
||||||
assert(sz == sizeof(T));
|
assert(sz == sizeof(T));
|
||||||
std::lock_guard<std::mutex> lock(mutex);
|
std::lock_guard<std::mutex> lock(mutex);
|
||||||
uint8_t* block = obj_cache.try_pop();
|
void* block = obj_cache.try_pop();
|
||||||
|
|
||||||
if (block != nullptr) {
|
if (block != nullptr) {
|
||||||
// allocation successful
|
// allocation successful
|
||||||
|
|
|
@ -50,7 +50,7 @@ public:
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* try_pop() noexcept
|
void* try_pop() noexcept
|
||||||
{
|
{
|
||||||
if (is_empty()) {
|
if (is_empty()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -58,7 +58,7 @@ public:
|
||||||
node* last_head = head;
|
node* last_head = head;
|
||||||
head = head->prev;
|
head = head->prev;
|
||||||
count--;
|
count--;
|
||||||
return (uint8_t*)last_head;
|
return static_cast<void*>(last_head);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_empty() const { return head == nullptr; }
|
bool is_empty() const { return head == nullptr; }
|
||||||
|
@ -113,10 +113,10 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* try_pop() noexcept
|
void* try_pop() noexcept
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mutex);
|
std::lock_guard<std::mutex> lock(mutex);
|
||||||
uint8_t* block = stack.try_pop();
|
void* block = stack.try_pop();
|
||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue