devicesbus stage
This commit is contained in:
@@ -59,7 +59,35 @@ public:
|
||||
this->release(*b);
|
||||
delete b;
|
||||
});
|
||||
}
|
||||
BlockPtr allocate(std::size_t requiredSize)
|
||||
{
|
||||
if (requiredSize > m_blockSize) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::size_t slot = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(m_mutex);
|
||||
if (m_freeSlots.empty()) {
|
||||
return {};
|
||||
}
|
||||
slot = m_freeSlots.front();
|
||||
m_freeSlots.pop();
|
||||
m_inUse[slot] = true;
|
||||
}
|
||||
|
||||
auto* raw = new PoolBlock{
|
||||
m_storage.data() + slot * m_blockSize,
|
||||
m_blockSize,
|
||||
requiredSize,
|
||||
slot,
|
||||
};
|
||||
return BlockPtr(raw, [this](PoolBlock* b) {
|
||||
if (!b) return;
|
||||
this->release(*b);
|
||||
delete b;
|
||||
});
|
||||
|
||||
|
||||
void release(const PoolBlock& block)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user