@@ -30,15 +30,13 @@ void BackpressureController::Resume() {
3030}
3131
3232BackpressureCombiner::BackpressureCombiner (
33- std::unique_ptr<BackpressureControl> backpressure_control)
34- : backpressure_control_(std::move(backpressure_control)) {}
33+ std::unique_ptr<BackpressureControl> backpressure_control, bool pause_on_any)
34+ : pause_on_any_(pause_on_any),
35+ backpressure_control_ (std::move(backpressure_control)) {}
3536
3637// Called from Source nodes
37- void BackpressureCombiner::Pause (Source* output, bool strong_connection ) {
38+ void BackpressureCombiner::Pause (Source* output) {
3839 std::lock_guard<std::mutex> lg (mutex_);
39- auto & paused_ = strong_connection ? strong_paused_ : weak_paused_;
40- auto & paused_count_ = strong_connection ? strong_paused_count_ : weak_paused_count_;
41-
4240 if (!paused_[output]) {
4341 paused_[output] = true ;
4442 paused_count_++;
@@ -47,25 +45,23 @@ void BackpressureCombiner::Pause(Source* output, bool strong_connection) {
4745}
4846
4947// Called from Source nodes
50- void BackpressureCombiner::Resume (Source* output, bool strong_connection ) {
48+ void BackpressureCombiner::Resume (Source* output) {
5149 std::lock_guard<std::mutex> lg (mutex_);
52- auto & paused_ = strong_connection ? strong_paused_ : weak_paused_;
53- auto & paused_count_ = strong_connection ? strong_paused_count_ : weak_paused_count_;
5450 if (paused_.find (output) == paused_.end ()) {
5551 paused_[output] = false ;
5652 UpdatePauseStateUnlocked ();
57- }
58- if (paused_[output]) {
53+ } else if (paused_[output]) {
5954 paused_[output] = false ;
6055 paused_count_--;
6156 UpdatePauseStateUnlocked ();
6257 }
6358}
6459
6560void BackpressureCombiner::UpdatePauseStateUnlocked () {
66- bool should_be_paused =
67- strong_paused_count_ > 0 ||
68- (weak_paused_count_ > 0 && weak_paused_count_ == weak_paused_.size ());
61+ bool should_be_paused = (paused_count_ > 0 );
62+ if (!pause_on_any_) {
63+ should_be_paused = should_be_paused && (paused_count_ == paused_.size ());
64+ }
6965 if (should_be_paused) {
7066 if (!paused) {
7167 backpressure_control_->Pause ();
@@ -79,25 +75,24 @@ void BackpressureCombiner::UpdatePauseStateUnlocked() {
7975 }
8076}
8177
82- BackpressureCombiner::Source::Source (BackpressureCombiner* ctrl, bool strong_connection ) {
78+ BackpressureCombiner::Source::Source (BackpressureCombiner* ctrl) {
8379 if (ctrl) {
84- AddController (ctrl, strong_connection );
80+ AddController (ctrl);
8581 }
8682}
8783
88- void BackpressureCombiner::Source::AddController (BackpressureCombiner* ctrl,
89- bool strong_connection) {
90- ctrl->Resume (this , strong_connection); // populate map in controller
91- connections_.push_back (Connection{ctrl, strong_connection});
84+ void BackpressureCombiner::Source::AddController (BackpressureCombiner* ctrl) {
85+ ctrl->Resume (this ); // populate map in controller
86+ connections_.push_back (ctrl);
9287}
9388void BackpressureCombiner::Source::Pause () {
9489 for (auto & conn_ : connections_) {
95- conn_. ctrl ->Pause (this , conn_. strong );
90+ conn_->Pause (this );
9691 }
9792}
9893void BackpressureCombiner::Source::Resume () {
9994 for (auto & conn_ : connections_) {
100- conn_. ctrl ->Resume (this , conn_. strong );
95+ conn_->Resume (this );
10196 }
10297}
10398
0 commit comments