You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

threadsafety.h 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright (c) 2009-2010 Satoshi Nakamoto
  2. // Copyright (c) 2009-2014 The Starwels developers
  3. // Distributed under the MIT software license, see the accompanying
  4. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  5. #ifndef STARWELS_THREADSAFETY_H
  6. #define STARWELS_THREADSAFETY_H
  7. #ifdef __clang__
  8. // TL;DR Add GUARDED_BY(mutex) to member variables. The others are
  9. // rarely necessary. Ex: int nFoo GUARDED_BY(cs_foo);
  10. //
  11. // See http://clang.llvm.org/docs/LanguageExtensions.html#threadsafety
  12. // for documentation. The clang compiler can do advanced static analysis
  13. // of locking when given the -Wthread-safety option.
  14. #define LOCKABLE __attribute__((lockable))
  15. #define SCOPED_LOCKABLE __attribute__((scoped_lockable))
  16. #define GUARDED_BY(x) __attribute__((guarded_by(x)))
  17. #define GUARDED_VAR __attribute__((guarded_var))
  18. #define PT_GUARDED_BY(x) __attribute__((pt_guarded_by(x)))
  19. #define PT_GUARDED_VAR __attribute__((pt_guarded_var))
  20. #define ACQUIRED_AFTER(...) __attribute__((acquired_after(__VA_ARGS__)))
  21. #define ACQUIRED_BEFORE(...) __attribute__((acquired_before(__VA_ARGS__)))
  22. #define EXCLUSIVE_LOCK_FUNCTION(...) __attribute__((exclusive_lock_function(__VA_ARGS__)))
  23. #define SHARED_LOCK_FUNCTION(...) __attribute__((shared_lock_function(__VA_ARGS__)))
  24. #define EXCLUSIVE_TRYLOCK_FUNCTION(...) __attribute__((exclusive_trylock_function(__VA_ARGS__)))
  25. #define SHARED_TRYLOCK_FUNCTION(...) __attribute__((shared_trylock_function(__VA_ARGS__)))
  26. #define UNLOCK_FUNCTION(...) __attribute__((unlock_function(__VA_ARGS__)))
  27. #define LOCK_RETURNED(x) __attribute__((lock_returned(x)))
  28. #define LOCKS_EXCLUDED(...) __attribute__((locks_excluded(__VA_ARGS__)))
  29. #define EXCLUSIVE_LOCKS_REQUIRED(...) __attribute__((exclusive_locks_required(__VA_ARGS__)))
  30. #define SHARED_LOCKS_REQUIRED(...) __attribute__((shared_locks_required(__VA_ARGS__)))
  31. #define NO_THREAD_SAFETY_ANALYSIS __attribute__((no_thread_safety_analysis))
  32. #else
  33. #define LOCKABLE
  34. #define SCOPED_LOCKABLE
  35. #define GUARDED_BY(x)
  36. #define GUARDED_VAR
  37. #define PT_GUARDED_BY(x)
  38. #define PT_GUARDED_VAR
  39. #define ACQUIRED_AFTER(...)
  40. #define ACQUIRED_BEFORE(...)
  41. #define EXCLUSIVE_LOCK_FUNCTION(...)
  42. #define SHARED_LOCK_FUNCTION(...)
  43. #define EXCLUSIVE_TRYLOCK_FUNCTION(...)
  44. #define SHARED_TRYLOCK_FUNCTION(...)
  45. #define UNLOCK_FUNCTION(...)
  46. #define LOCK_RETURNED(x)
  47. #define LOCKS_EXCLUDED(...)
  48. #define EXCLUSIVE_LOCKS_REQUIRED(...)
  49. #define SHARED_LOCKS_REQUIRED(...)
  50. #define NO_THREAD_SAFETY_ANALYSIS
  51. #endif // __GNUC__
  52. #endif // STARWELS_THREADSAFETY_H