devicesbus stage

This commit is contained in:
flower_linux
2026-03-30 11:11:05 +08:00
parent 35fb913957
commit 1ab3523ea9
6 changed files with 53 additions and 3 deletions

View File

@@ -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)
{