}
} // namespace
+AllocatedResource::Token::~Token() {
+ release_cb_.RunAndReset();
+ // For resources that self-manage their managers, we're sure at this point
+ // it holds no more resources. To avoid deadlock with recursive mutex
+ // locking, we can post destruction to some other thread using thread pool.
+ if (owner_) {
+ base::ThreadPool::PostTask(
+ FROM_HERE, {base::TaskPriority::BEST_EFFORT},
+ base::BindOnce([](std::unique_ptr<ResourceManager>) {},
+ std::move(owner_)));
+ }
+}
+
void ResourceManagerEntry::Register(int handle, ResourceManager* instance) {
AutoLock auto_lock(lock_);
managers_.emplace(handle, instance);
if (maybe_token.has_value()) {
AutoLock auto_lock(lock_);
ReleaseResourceLocked(maybe_token->Leak());
- // For resources that self-manage their managers, we're sure at this point
- // it holds no more resources. To avoid deadlock with recursive mutex
- // locking, we can post destruction to some other thread using thread pool.
- if (maybe_token->owner_) {
- base::ThreadPool::PostTask(
- FROM_HERE, {base::TaskPriority::BEST_EFFORT},
- base::BindOnce([](std::unique_ptr<ResourceManager>) {},
- std::move(maybe_token->owner_)));
- }
}
}