[LockConsistency] Model std::unique_lock::try_lock

Summary: `std::unique_lock` constructor allows to create a unique lock without locking the mutex. `std::unique_lock::try_lock` returns true if mutex has been acquired successfully, and false otherwise. It could be that an exception is being thrown while trying to acquire mutex, which is not modeled.

Reviewed By: jberdine

Differential Revision: D6185568

fbshipit-source-id: 192bf10
master
Daiva Naudziuniene 7 years ago committed by Facebook Github Bot
parent bb0a42d25d
commit 535ba01a25

@ -88,7 +88,10 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
fun pname ->
QualifiedCppName.Match.match_qualifiers matcher (Typ.Procname.get_qualifiers pname)
and is_cpp_trylock =
let matcher = QualifiedCppName.Match.of_fuzzy_qual_names ["std::unique_lock::owns_lock"] in
let matcher =
QualifiedCppName.Match.of_fuzzy_qual_names
["std::unique_lock::owns_lock"; "std::unique_lock::try_lock"]
in
fun pname ->
QualifiedCppName.Match.match_qualifiers matcher (Typ.Procname.get_qualifiers pname)
in

@ -13,3 +13,4 @@ codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock_get2, 4, LOCK_CONSI
codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock_get4, 1, LOCK_CONSISTENCY_VIOLATION, [<Read trace>,access to `&this.suspiciously_read1`,<Write trace>,access to `&this.suspiciously_read1`]
codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock_get4, 2, LOCK_CONSISTENCY_VIOLATION, [<Read trace>,access to `&this.suspiciously_read2`,<Write trace>,access to `&this.suspiciously_read2`]
codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock_get5, 5, LOCK_CONSISTENCY_VIOLATION, [<Read trace>,access to `&this.suspiciously_read1`,<Write trace>,access to `&this.suspiciously_read1`]
codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock_get6, 5, LOCK_CONSISTENCY_VIOLATION, [<Read trace>,access to `&this.suspiciously_read1`,<Write trace>,access to `&this.suspiciously_read1`]

@ -67,6 +67,15 @@ class UniqueLock {
}
}
int get6() {
std::unique_lock<std::mutex> lock(mutex_, std::defer_lock);
if (lock.try_lock()) {
return well_guarded1;
} else {
return suspiciously_read1;
}
}
private:
int well_guarded1;
int suspiciously_read1;

Loading…
Cancel
Save