macros: Add thread-safety annotation macros

Extracted from !7529

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9061>
This commit is contained in:
Kristian Høgsberg 2021-02-12 12:26:47 -08:00 committed by Marge Bot
parent 1cef1a34bb
commit 0d5fe24c9b
2 changed files with 33 additions and 0 deletions

View File

@ -1040,6 +1040,7 @@ else
'-Werror=incompatible-pointer-types',
'-Werror=int-conversion',
'-Wimplicit-fallthrough',
'-Werror=thread-safety',
'-Wno-missing-field-initializers',
'-Wno-format-truncation',
'-fno-math-errno',

View File

@ -40,6 +40,10 @@
# define __has_builtin(x) 0
#endif
#ifndef __has_attribute
# define __has_attribute(x) 0
#endif
/**
* __builtin_expect macros
*/
@ -412,4 +416,32 @@ enum pipe_debug_type
#endif
#endif
/* Macros for static type-safety checking.
*
* https://clang.llvm.org/docs/ThreadSafetyAnalysis.html
*/
#if __has_attribute(capability)
typedef int __attribute__((capability("mutex"))) lock_cap_t;
#define guarded_by(l) __attribute__((guarded_by(l)))
#define acquire_cap(l) __attribute((acquire_capability(l), no_thread_safety_analysis))
#define release_cap(l) __attribute((release_capability(l), no_thread_safety_analysis))
#define assert_cap(l) __attribute((assert_capability(l), no_thread_safety_analysis))
#define requires_cap(l) __attribute((requires_capability(l)))
#define disable_thread_safety_analysis __attribute((no_thread_safety_analysis))
#else
typedef int lock_cap_t;
#define guarded_by(l)
#define acquire_cap(l)
#define release_cap(l)
#define assert_cap(l)
#define requires_cap(l)
#define disable_thread_safety_analysis
#endif
#endif /* UTIL_MACROS_H */