Skip to content

Commit

Permalink
Revert the synchronization/cancellation changes in MultiModelLoader a…
Browse files Browse the repository at this point in the history
…dded to fix bumptech#2879

This wasn't well throught through. Avoiding calling callbacks can lead
to resource leaks.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=185931910
  • Loading branch information
sjudd committed Feb 21, 2018
1 parent 7d1898e commit cd08c4b
Showing 1 changed file with 5 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ static class MultiFetcher<Data> implements DataFetcher<Data>, DataCallback<Data>
private DataCallback<? super Data> callback;
@Nullable
private List<Throwable> exceptions;
private boolean isCancelled;

MultiFetcher(
@NonNull List<DataFetcher<Data>> fetchers,
Expand All @@ -92,7 +91,7 @@ static class MultiFetcher<Data> implements DataFetcher<Data>, DataCallback<Data>
}

@Override
public synchronized void loadData(
public void loadData(
@NonNull Priority priority, @NonNull DataCallback<? super Data> callback) {
this.priority = priority;
this.callback = callback;
Expand All @@ -101,7 +100,7 @@ public synchronized void loadData(
}

@Override
public synchronized void cleanup() {
public void cleanup() {
if (exceptions != null) {
throwableListPool.release(exceptions);
}
Expand All @@ -112,8 +111,7 @@ public synchronized void cleanup() {
}

@Override
public synchronized void cancel() {
isCancelled = true;
public void cancel() {
for (DataFetcher<Data> fetcher : fetchers) {
fetcher.cancel();
}
Expand All @@ -132,11 +130,7 @@ public DataSource getDataSource() {
}

@Override
public synchronized void onDataReady(@Nullable Data data) {
if (isCancelled) {
return;
}

public void onDataReady(@Nullable Data data) {
if (data != null) {
callback.onDataReady(data);
} else {
Expand All @@ -145,20 +139,12 @@ public synchronized void onDataReady(@Nullable Data data) {
}

@Override
public synchronized void onLoadFailed(@NonNull Exception e) {
if (isCancelled) {
return;
}

public void onLoadFailed(@NonNull Exception e) {
Preconditions.checkNotNull(exceptions).add(e);
startNextOrFail();
}

private void startNextOrFail() {
if (isCancelled) {
return;
}

if (currentIndex < fetchers.size() - 1) {
currentIndex++;
loadData(priority, callback);
Expand Down

0 comments on commit cd08c4b

Please sign in to comment.