Boundary: use atomic int

pull/210/head
M66B 2 years ago
parent 179781956d
commit 7745ce3499

@ -60,6 +60,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.mail.Address; import javax.mail.Address;
@ -160,12 +161,12 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
} }
private void queue_load(final State state) { private void queue_load(final State state) {
if (state.queued > 1) { if (state.queued.get() > 1) {
Log.i("Boundary queued =" + state.queued); Log.i("Boundary queued =" + state.queued.get());
return; return;
} }
state.queued++; state.queued.incrementAndGet();
Log.i("Boundary queued +" + state.queued); Log.i("Boundary queued +" + state.queued.get());
executor.submit(new Runnable() { executor.submit(new Runnable() {
@Override @Override
@ -174,7 +175,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
int free = Log.getFreeMemMb(); int free = Log.getFreeMemMb();
Map<String, String> crumb = new HashMap<>(); Map<String, String> crumb = new HashMap<>();
crumb.put("queued", Integer.toString(state.queued)); crumb.put("queued", Integer.toString(state.queued.get()));
Log.breadcrumb("Boundary run", crumb); Log.breadcrumb("Boundary run", crumb);
Log.i("Boundary run free=" + free); Log.i("Boundary run free=" + free);
@ -223,11 +224,11 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
} }
}); });
} finally { } finally {
state.queued--; state.queued.decrementAndGet();
Log.i("Boundary queued -" + state.queued); Log.i("Boundary queued -" + state.queued.get());
Helper.gc(); Helper.gc();
crumb.put("queued", Integer.toString(state.queued)); crumb.put("queued", Integer.toString(state.queued.get()));
Log.breadcrumb("Boundary done", crumb); Log.breadcrumb("Boundary done", crumb);
final int f = found; final int f = found;
@ -897,7 +898,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
} }
static class State { static class State {
int queued = 0; final AtomicInteger queued = new AtomicInteger(0);
boolean destroyed = false; boolean destroyed = false;
boolean error = false; boolean error = false;
int index = 0; int index = 0;
@ -911,7 +912,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
void reset() { void reset() {
Log.i("Boundary reset"); Log.i("Boundary reset");
queued = 0; queued.set(0);
destroyed = false; destroyed = false;
error = false; error = false;
index = 0; index = 0;

Loading…
Cancel
Save