Skip to content

Commit 52cfe5b

Browse files
chkuang-ga-maurice
authored andcommitted
Remove the check for externally owned Future in IsSafeToDelete()
It is safe to delete ReferenceCountedFutureImpl even if there is any externally owned Future because the future will be invalidated by CleanupNotifier in ~ReferenceCountedFutureImpl(). PiperOrigin-RevId: 261033497
1 parent 238d071 commit 52cfe5b

File tree

2 files changed

+2
-17
lines changed

2 files changed

+2
-17
lines changed

app/src/reference_counted_future_impl.cc

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -490,25 +490,11 @@ void ReferenceCountedFutureImpl::SetCompletionCallbackLambda(
490490
bool ReferenceCountedFutureImpl::IsSafeToDelete() const {
491491
MutexLock lock(mutex_);
492492
// Check if any Futures we have are still pending.
493-
int total_references = 0;
494-
int internal_references = 0;
495493
for (auto i = backings_.begin(); i != backings_.end(); ++i) {
496494
// If any Future is still pending, not safe to delete.
497495
if (i->second->status == kFutureStatusPending) return false;
498-
// Count the total number of references to all valid Futures.
499-
total_references += i->second->reference_count;
500496
}
501-
for (int i = 0; i < last_results_.size(); i++) {
502-
if (last_results_[i].status() != kFutureStatusInvalid) {
503-
// If the status is not invalid, this entry is using up a reference.
504-
// Count up the internal references.
505-
internal_references++;
506-
}
507-
}
508-
// If the only references are internal references, we're safe to delete.
509-
// Otherwise, someone somewhere is holding onto a Future, and it's not
510-
// yet safe to delete.
511-
return total_references == internal_references;
497+
return true;
512498
}
513499

514500
void ReferenceCountedFutureImpl::SetContextData(

app/src/reference_counted_future_impl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,7 @@ class ReferenceCountedFutureImpl : public detail::FutureApiInterface {
366366
size_t GetLastResultCount() { return last_results_.size(); }
367367

368368
/// Check if it's safe to delete this API. It's only safe to delete this if
369-
/// no futures are Pending, and if there are no references to Futures other
370-
/// than in last_results_.
369+
/// no futures are Pending.
371370
bool IsSafeToDelete() const;
372371

373372
/// Sets temporary context data associated with a FutureHandle that will be

0 commit comments

Comments
 (0)