[thread-safety] add string parameter to @ThreadConfined

Summary: Better documentation, and could perhaps be checked instead of trusted later if the analysis understands threads better.

Reviewed By: jaegs

Differential Revision: D4537463

fbshipit-source-id: 4323c78
master
Sam Blackshear 8 years ago committed by Facebook Github Bot
parent a3e3fdb781
commit c67de3e827

@ -14,8 +14,17 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation tells the thread-safety analysis to assume that mutations in the annotated
* class/field/method are confined to the given thread name. For the thread name, you can either use
* the default constants UI/ANY or add your own.
*/
@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD })
@Retention(RetentionPolicy.CLASS)
public @interface ThreadConfined {
String value(); /** the thread that the mutations should be confined to */
public static String UI = "UI"; /** confined to the UI thread */
public static String ANY = "ANY"; /** confined to any thread (but only that thread!) */
}

@ -87,7 +87,7 @@ class Annotations implements FunctionalInterface {
con.x = 7;
}
@ThreadConfined
@ThreadConfined(ThreadConfined.UI)
class Confined {
Integer x;
@ -100,7 +100,7 @@ class Annotations implements FunctionalInterface {
Object fld;
}
@ThreadConfined Obj encapsulatedField;
@ThreadConfined(ThreadConfined.ANY) Obj encapsulatedField;
public void mutateConfinedFieldDirectlyOk() {
this.encapsulatedField = new Obj();
@ -114,7 +114,7 @@ class Annotations implements FunctionalInterface {
this.encapsulatedField.fld = new Object();
}
@ThreadConfined
@ThreadConfined("some_custom_string")
public void threadConfinedMethodOk() {
this.f = new Object();
}

Loading…
Cancel
Save