46 lines
1.1 KiB
C++
46 lines
1.1 KiB
C++
#include "capability/capability_table.h"
|
|
|
|
#include "debug/debug.h"
|
|
|
|
CapabilityTable::CapabilityTable() {}
|
|
|
|
uint64_t CapabilityTable::AddExistingCapability(
|
|
const glcr::RefPtr<Capability>& cap) {
|
|
MutexHolder h(lock_);
|
|
uint64_t id = next_cap_id_++;
|
|
if (capabilities_.Insert(id, cap) != glcr::OK) {
|
|
panic("Reusing capability id.");
|
|
}
|
|
return id;
|
|
}
|
|
|
|
glcr::RefPtr<Capability> CapabilityTable::GetCapability(uint64_t id) {
|
|
MutexHolder h(lock_);
|
|
if (!capabilities_.Contains(id)) {
|
|
dbgln("Bad cap access {}", id);
|
|
return {};
|
|
}
|
|
return capabilities_.at(id);
|
|
}
|
|
|
|
glcr::RefPtr<Capability> CapabilityTable::ReleaseCapability(uint64_t id) {
|
|
MutexHolder h(lock_);
|
|
if (!capabilities_.Contains(id)) {
|
|
dbgln("Bad cap release {}", id);
|
|
return {};
|
|
}
|
|
auto cap = capabilities_.at(id);
|
|
(void)capabilities_.Delete(id);
|
|
return cap;
|
|
}
|
|
|
|
void CapabilityTable::ReleaseAll() {
|
|
for (uint64_t i = 0; i < next_cap_id_; i++) {
|
|
(void)capabilities_.Delete(i);
|
|
}
|
|
if (capabilities_.size() != 0) {
|
|
dbgln("Capabilities still remaining after clear: {x}",
|
|
capabilities_.size());
|
|
}
|
|
}
|