Summary: - Unify treatment of modelled and annotated executors by making things go through attributes. - Add a return attribute to summaries, so that we can track flows of thread guards/executors/future stuff through returned values. - Dispatch modeled functions to model summaries. This will help in following diffs where runnables will also go through attributes. Reviewed By: skcho Differential Revision: D18660185 fbshipit-source-id: e26b1083emaster
parent
61c0a92682
commit
20a7e9d75b
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import android.os.Binder;
|
||||
import android.os.RemoteException;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
class AttributeFlows {
|
||||
static Binder binder;
|
||||
|
||||
private static void doTransact() {
|
||||
try {
|
||||
binder.transact(0, null, null, 0);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
|
||||
private Executor getBackgroundExecutor() {
|
||||
return Executors.getBackgroundExecutor();
|
||||
}
|
||||
|
||||
private Executor indirectlyGetBackgroundExecutor() {
|
||||
return getBackgroundExecutor();
|
||||
}
|
||||
|
||||
private Executor getForegroundExecutor() {
|
||||
return Executors.getForegroundExecutor();
|
||||
}
|
||||
|
||||
private Executor indirectlyGetForegroundExecutor() {
|
||||
return getForegroundExecutor();
|
||||
}
|
||||
|
||||
// starvation via scheduling a transaction on UI thread
|
||||
public void postBlockingCallToUIThreadBad() {
|
||||
indirectlyGetForegroundExecutor()
|
||||
.execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
doTransact();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// no report here
|
||||
public void postBlockingCallToNonUIThreadOk() {
|
||||
indirectlyGetBackgroundExecutor()
|
||||
.execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
doTransact();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ForUiThread private final Executor mUiThreadExecutor = null;
|
||||
@ForNonUiThread private final Executor mNonUiThreadExecutor = null;
|
||||
|
||||
private Executor getAnnotatedBackgroundExecutor() {
|
||||
return mNonUiThreadExecutor;
|
||||
}
|
||||
|
||||
private Executor indirectlyGetAnnotatedBackgroundExecutor() {
|
||||
return getAnnotatedBackgroundExecutor();
|
||||
}
|
||||
|
||||
private Executor getAnnotatedForegroundExecutor() {
|
||||
return mUiThreadExecutor;
|
||||
}
|
||||
|
||||
private Executor indirectlyGetAnnotatedForegroundExecutor() {
|
||||
return getAnnotatedForegroundExecutor();
|
||||
}
|
||||
|
||||
// starvation via scheduling a transaction on UI thread
|
||||
public void postBlockingCallToAnnnotatedUIThreadBad() {
|
||||
indirectlyGetAnnotatedForegroundExecutor()
|
||||
.execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
doTransact();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// no report here
|
||||
public void postBlockingCallToAnnotatedNonUIThreadOk() {
|
||||
indirectlyGetAnnotatedBackgroundExecutor()
|
||||
.execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
doTransact();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
// modeled executors
|
||||
class Executors {
|
||||
static Executor uiExecutor;
|
||||
|
||||
static Executor getForegroundExecutor() {
|
||||
return uiExecutor;
|
||||
}
|
||||
|
||||
static Executor bgExecutor;
|
||||
|
||||
static Executor getBackgroundExecutor() {
|
||||
return bgExecutor;
|
||||
}
|
||||
|
||||
public static void postOnUiThread(Runnable runnable) {}
|
||||
|
||||
public static void runOnUiThread(Runnable runnable) {}
|
||||
|
||||
public static void postOnUiThreadDelayed(Runnable runnable, long delayMs) {}
|
||||
|
||||
public static void scheduleGuaranteedDelayed(
|
||||
Runnable job, long delayMillis, long lastExecution) {}
|
||||
}
|
Loading…
Reference in new issue