skipping ReadWrite Locks

Summary: We want to skip readwrite locks for now, maybe report on their misuses later.

Reviewed By: sblackshear

Differential Revision: D4110998

fbshipit-source-id: 986f77e
master
Peter O'Hearn 8 years ago committed by Facebook Github Bot
parent 874e7f000d
commit 2d424b7779

@ -746,7 +746,8 @@ let add_guarded_by_constraints tenv prop lexp pdesc =
let exn = Exceptions.Unsafe_guarded_by_access (err_desc, __POS__) in let exn = Exceptions.Unsafe_guarded_by_access (err_desc, __POS__) in
Reporting.log_error pname exn in Reporting.log_error pname exn in
let rec is_read_write_lock typ = let rec is_read_write_lock typ =
let str_is_read_write_lock str = string_is_suffix "ReadWriteUpdateLock" str in let str_is_read_write_lock str = string_is_suffix "ReadWriteUpdateLock" str ||
string_is_suffix "ReadWriteLock" str in
match typ with match typ with
| Typ.Tstruct name -> str_is_read_write_lock (Typename.name name) | Typ.Tstruct name -> str_is_read_write_lock (Typename.name name)
| Typ.Tptr (typ, _) -> is_read_write_lock typ | Typ.Tptr (typ, _) -> is_read_write_lock typ

@ -16,6 +16,8 @@ import java.lang.annotation.Target;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import javax.annotation.concurrent.GuardedBy; import javax.annotation.concurrent.GuardedBy;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.io.Closeable; import java.io.Closeable;
@ -432,4 +434,43 @@ public class GuardedByExample {
} }
*/ */
ReadWriteLock mRWL;
@GuardedBy("mRWL")
Integer guardedbymRWL;
Integer someOtherInt;
void readLockOK() {
mRWL.readLock().lock();
someOtherInt = guardedbymRWL;
mRWL.readLock().unlock();
}
void writeLockOK() {
mRWL.writeLock().lock();
guardedbymRWL = 55;
mRWL.writeLock().unlock();
}
ReentrantReadWriteLock mRRWL;
@GuardedBy("mRRWL")
Integer guardedbymRRWL;
void reentrantReadLockOK() {
mRRWL.readLock().lock();
someOtherInt = guardedbymRRWL;
mRRWL.readLock().unlock();
}
void reentrantWriteLockOK() {
mRRWL.writeLock().lock();
guardedbymRRWL = 55;
mRRWL.writeLock().unlock();
}
// TODO: warn on misuse of read/write locks.
} }

Loading…
Cancel
Save