// We divide the receivers_ vector into three regions: from right to left, the // "keep" region, the "todo" region, and the "remove" region. The "todo" // region initially covers the whole vector.
size_t first_todo = 0; // First element of the "todo" // region.
size_t first_remove = receivers_.size(); // First element of the "remove" // region.
// Loop until the "todo" region is empty. while (first_todo != first_remove) {
if (receivers_[first_todo].removal_tag != removal_tag) { // The first element of the "todo" region should be kept. Move the // "keep"/"todo" boundary.
++first_todo;
} else if (receivers_[first_remove - 1].removal_tag == removal_tag) { // The last element of the "todo" region should be removed. Move the // "todo"/"remove" boundary.
if (send_in_progress_) { // Tag this receiver for removal, which will be done when `ForEach` // has completed.
receivers_[first_remove - 1].removal_tag = pending_removal_tag();
}
--first_remove;
} else if (!send_in_progress_) { // The first element of the "todo" region should be removed, and the last // element of the "todo" region should be kept. Swap them, and then shrink // the "todo" region from both ends.
RTC_DCHECK_NE(first_todo, first_remove - 1); using std::swap;
swap(receivers_[first_todo], receivers_[first_remove - 1]);
RTC_DCHECK_NE(receivers_[first_todo].removal_tag, removal_tag);
++first_todo;
RTC_DCHECK_EQ(receivers_[first_remove - 1].removal_tag, removal_tag);
--first_remove;
} else { // When send_in_progress_ we really only iterate the list and // mark elements with pending_removal_tag().
RTC_DCHECK(send_in_progress_);
RTC_DCHECK_EQ(receivers_[first_todo].removal_tag, removal_tag);
receivers_[first_todo++].removal_tag = pending_removal_tag();
}
}
if (!send_in_progress_) { // Discard the remove region.
receivers_.resize(first_remove);
}
}
void CallbackListReceivers::Foreach(FunctionView<void(UntypedFunction&)> fv) {
RTC_CHECK(!send_in_progress_); bool removals_detected = false;
send_in_progress_ = true;
for (auto& r : receivers_) {
RTC_DCHECK_NE(r.removal_tag, pending_removal_tag());
fv(r.function);
if (r.removal_tag == pending_removal_tag()) {
removals_detected = true;
}
}
send_in_progress_ = false;
if (removals_detected) {
RemoveReceivers(pending_removal_tag());
}
}
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.18Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-08-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.