[starvation][concurrency] split guard lock treatment and add support for non-recursive locks (per language)
	
		
	
				
					
				
			Reviewed By: jeremydubreil Differential Revision: D13320542 fbshipit-source-id: feb5d58a8master
							parent
							
								
									a37d85dddc
								
							
						
					
					
						commit
						27d8a65906
					
				@ -1,2 +1,8 @@
 | 
				
			||||
codetoanalyze/cpp/starvation/basics.cpp, basics::Basic_thread1, 17, DEADLOCK, no_bucket, ERROR, [[Trace 1] `basics::Basic_thread1`,locks `this.mutex_1` in class `basics::Basic*`,locks `this.mutex_2` in class `basics::Basic*`,[Trace 2] `basics::Basic_thread2`,locks `this.mutex_2` in class `basics::Basic*`,locks `this.mutex_1` in class `basics::Basic*`]
 | 
				
			||||
codetoanalyze/cpp/starvation/basics.cpp, basics::WithGuard_thread1, 42, DEADLOCK, no_bucket, ERROR, [[Trace 1] `basics::WithGuard_thread1`,locks `this.mutex_1` in class `basics::WithGuard*`,locks `this.mutex_2` in class `basics::WithGuard*`,[Trace 2] `basics::WithGuard_thread2`,locks `this.mutex_2` in class `basics::WithGuard*`,locks `this.mutex_1` in class `basics::WithGuard*`]
 | 
				
			||||
codetoanalyze/cpp/starvation/basics.cpp, basics::Basic_thread1_bad, 18, DEADLOCK, no_bucket, ERROR, [[Trace 1] `basics::Basic_thread1_bad`,locks `this.mutex_1` in class `basics::Basic*`,locks `this.mutex_2` in class `basics::Basic*`,[Trace 2] `basics::Basic_thread2_bad`,locks `this.mutex_2` in class `basics::Basic*`,locks `this.mutex_1` in class `basics::Basic*`]
 | 
				
			||||
codetoanalyze/cpp/starvation/basics.cpp, basics::SelfDeadlock_complicated_bad, 131, DEADLOCK, no_bucket, ERROR, [In method`basics::SelfDeadlock_complicated_bad`,locks `this.mutex_` in class `basics::SelfDeadlock*`,locks `this.mutex_` in class `basics::SelfDeadlock*`]
 | 
				
			||||
codetoanalyze/cpp/starvation/basics.cpp, basics::SelfDeadlock_interproc1_bad, 114, DEADLOCK, no_bucket, ERROR, [In method`basics::SelfDeadlock_interproc1_bad`,locks `this.mutex_` in class `basics::SelfDeadlock*`,Method call: `basics::SelfDeadlock_interproc2_bad`,locks `this.mutex_` in class `basics::SelfDeadlock*`]
 | 
				
			||||
codetoanalyze/cpp/starvation/basics.cpp, basics::SelfDeadlock_thread_bad, 105, DEADLOCK, no_bucket, ERROR, [In method`basics::SelfDeadlock_thread_bad`,locks `this.mutex_` in class `basics::SelfDeadlock*`,locks `this.mutex_` in class `basics::SelfDeadlock*`]
 | 
				
			||||
codetoanalyze/cpp/starvation/basics.cpp, basics::WithGuard_thread1_bad, 44, DEADLOCK, no_bucket, ERROR, [[Trace 1] `basics::WithGuard_thread1_bad`,locks `this.mutex_1` in class `basics::WithGuard*`,locks `this.mutex_2` in class `basics::WithGuard*`,[Trace 2] `basics::WithGuard_thread2_bad`,locks `this.mutex_2` in class `basics::WithGuard*`,locks `this.mutex_1` in class `basics::WithGuard*`]
 | 
				
			||||
codetoanalyze/cpp/starvation/recursive.cpp, Recursive_FP_multi_ok, 26, DEADLOCK, no_bucket, ERROR, [In method`Recursive_FP_multi_ok`,locks `this.recursive_mutex_` in class `Recursive*`,locks `this.recursive_mutex_` in class `Recursive*`]
 | 
				
			||||
codetoanalyze/cpp/starvation/recursive.cpp, Recursive_FP_path_sensitive_ok, 36, DEADLOCK, no_bucket, ERROR, [In method`Recursive_FP_path_sensitive_ok`,locks `this.mutex_` in class `Recursive*`,locks `this.mutex_` in class `Recursive*`]
 | 
				
			||||
codetoanalyze/cpp/starvation/recursive.cpp, Recursive_FP_unknown_ok, 31, DEADLOCK, no_bucket, ERROR, [In method`Recursive_FP_unknown_ok`,locks `this.umutex_` in class `Recursive*`,locks `this.umutex_` in class `Recursive*`]
 | 
				
			||||
 | 
				
			||||
@ -0,0 +1,48 @@
 | 
				
			||||
/*
 | 
				
			||||
 * Copyright (c) 2018-present, Facebook, Inc.
 | 
				
			||||
 *
 | 
				
			||||
 * This source code is licensed under the MIT license found in the
 | 
				
			||||
 * LICENSE file in the root directory of this source tree.
 | 
				
			||||
 */
 | 
				
			||||
 | 
				
			||||
#include <mutex>
 | 
				
			||||
 | 
				
			||||
struct UnknownMutex {
 | 
				
			||||
  UnknownMutex() {}
 | 
				
			||||
 | 
				
			||||
  void lock() {}
 | 
				
			||||
 | 
				
			||||
  void unlock() {}
 | 
				
			||||
 | 
				
			||||
  UnknownMutex(const UnknownMutex&) = delete;
 | 
				
			||||
  UnknownMutex& operator=(const UnknownMutex&) = delete;
 | 
				
			||||
};
 | 
				
			||||
 | 
				
			||||
class Recursive {
 | 
				
			||||
 public:
 | 
				
			||||
  Recursive() {}
 | 
				
			||||
 | 
				
			||||
  void FP_multi_ok() {
 | 
				
			||||
    std::lock_guard<std::recursive_mutex> l(recursive_mutex_);
 | 
				
			||||
    { std::lock_guard<std::recursive_mutex> l(recursive_mutex_); }
 | 
				
			||||
  }
 | 
				
			||||
 | 
				
			||||
  void FP_unknown_ok() {
 | 
				
			||||
    std::lock_guard<UnknownMutex> l(umutex_);
 | 
				
			||||
    { std::lock_guard<UnknownMutex> l(umutex_); }
 | 
				
			||||
  }
 | 
				
			||||
 | 
				
			||||
  void FP_path_sensitive_ok() {
 | 
				
			||||
    std::lock_guard<std::mutex> l(mutex_);
 | 
				
			||||
    bool flag = false;
 | 
				
			||||
 | 
				
			||||
    if (flag) {
 | 
				
			||||
      std::lock_guard<std::mutex> l(mutex_);
 | 
				
			||||
    }
 | 
				
			||||
  }
 | 
				
			||||
 | 
				
			||||
 private:
 | 
				
			||||
  std::recursive_mutex recursive_mutex_;
 | 
				
			||||
  std::mutex mutex_;
 | 
				
			||||
  UnknownMutex umutex_;
 | 
				
			||||
};
 | 
				
			||||
					Loading…
					
					
				
		Reference in new issue