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:

committed by
Marge Bot

parent
1cef1a34bb
commit
0d5fe24c9b
@@ -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 */
|
||||
|
Reference in New Issue
Block a user