Prevent interrupting backoff

pull/185/head
M66B 4 years ago
parent 2dea5ebd5d
commit eb589c0524

@ -4056,7 +4056,7 @@ class Core {
static class State {
private int backoff;
private boolean keepalive = false;
private boolean backingoff = false;
private ConnectionHelper.NetworkState networkState;
private Thread thread = new Thread();
private Semaphore semaphore = new Semaphore(0);
@ -4101,12 +4101,12 @@ class Core {
return true;
}
boolean acquire(long milliseconds, boolean keepalive) throws InterruptedException {
boolean acquire(long milliseconds, boolean backingoff) throws InterruptedException {
try {
this.keepalive = keepalive;
this.backingoff = backingoff;
return semaphore.tryAcquire(milliseconds, TimeUnit.MILLISECONDS);
} finally {
this.keepalive = false;
this.backingoff = false;
}
}
@ -4137,7 +4137,7 @@ class Core {
if (ex instanceof OperationCanceledException)
recoverable = false;
if (keepalive) {
if (!backingoff) {
thread.interrupt();
yield();
}

@ -899,7 +899,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
try {
long backoff = RECONNECT_BACKOFF - ago;
EntityLog.log(ServiceSynchronize.this, account.name + " reconnect backoff=" + (backoff / 1000));
state.acquire(backoff, false);
state.acquire(backoff, true);
} catch (InterruptedException ex) {
Log.w(account.name + " backoff " + ex.toString());
}
@ -1535,7 +1535,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
try {
wlAccount.release();
state.acquire(2 * duration, true);
state.acquire(2 * duration, false);
Log.i("### " + account.name + " keeping alive");
} catch (InterruptedException ex) {
EntityLog.log(this, account.name + " waited state=" + state);
@ -1653,7 +1653,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (cbackoff > backoff) {
try {
EntityLog.log(this, account.name + " reconnect backoff=" + cbackoff);
state.acquire(cbackoff * 1000L, false);
state.acquire(cbackoff * 1000L, true);
} catch (InterruptedException ex) {
Log.w(account.name + " cbackoff " + ex.toString());
}
@ -1663,7 +1663,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (backoff <= CONNECT_BACKOFF_MAX) {
// Short back-off period, keep device awake
try {
state.acquire(backoff * 1000L, false);
state.acquire(backoff * 1000L, true);
} catch (InterruptedException ex) {
Log.w(account.name + " backoff " + ex.toString());
}
@ -1696,7 +1696,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
try {
wlAccount.release();
state.acquire(2 * backoff * 1000L, false);
state.acquire(2 * backoff * 1000L, true);
Log.i("### " + account.name + " backoff done");
} catch (InterruptedException ex) {
Log.w(account.name + " backoff " + ex.toString());

Loading…
Cancel
Save