Skip to content

Commit 87658bf

Browse files
committed
threadsafety: add support for custom resets_capability attribute
1 parent b53fab1 commit 87658bf

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/threadsafety.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,23 @@
3333
#define SHARED_LOCKS_REQUIRED(...) __attribute__((requires_shared_capability(__VA_ARGS__)))
3434
#define NO_THREAD_SAFETY_ANALYSIS __attribute__((no_thread_safety_analysis))
3535
#define ASSERT_EXCLUSIVE_LOCK(...) __attribute__((assert_capability(__VA_ARGS__)))
36+
37+
#if defined(__has_attribute)
38+
# if __has_attribute(resets_capability)
39+
# define HAS_RESET_CAPABILITY_ATTRIBUTE
40+
# endif
41+
#endif
42+
43+
#if defined HAS_RESET_CAPABILITY_ATTRIBUTE
44+
# define LOCKS_RESET(...) __attribute__((resets_capability(__VA_ARGS__)))
45+
# define RECURSIVE_LOCKS_REQUIRED(...) __attribute__((requires_capability(__VA_ARGS__)))
3646
#else
47+
# define LOCKS_RESET(...)
48+
# define RECURSIVE_LOCKS_REQUIRED(...)
49+
#endif
50+
51+
#else // !__clang__
52+
3753
#define LOCKABLE
3854
#define SCOPED_LOCKABLE
3955
#define GUARDED_BY(x)
@@ -52,6 +68,8 @@
5268
#define SHARED_LOCKS_REQUIRED(...)
5369
#define NO_THREAD_SAFETY_ANALYSIS
5470
#define ASSERT_EXCLUSIVE_LOCK(...)
71+
#define LOCKS_RESET(...)
72+
#define RECURSIVE_LOCKS_REQUIRED(...)
5573
#endif // __GNUC__
5674

5775
// StdMutex provides an annotated version of std::mutex for us,

0 commit comments

Comments
 (0)