14 #define THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x))
16 #define CAPABILITY(x) \
17 THREAD_ANNOTATION_ATTRIBUTE__(capability(x))
19 #define SCOPED_CAPABILITY \
20 THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable)
22 #define GUARDED_BY(x) \
23 THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x))
25 #define PT_GUARDED_BY(x) \
26 THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x))
28 #define ACQUIRED_BEFORE(...) \
29 THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(__VA_ARGS__))
31 #define ACQUIRED_AFTER(...) \
32 THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(__VA_ARGS__))
34 #define REQUIRES(...) \
35 THREAD_ANNOTATION_ATTRIBUTE__(requires_capability(__VA_ARGS__))
37 #define REQUIRES_SHARED(...) \
38 THREAD_ANNOTATION_ATTRIBUTE__(requires_shared_capability(__VA_ARGS__))
40 #define ACQUIRE(...) \
41 THREAD_ANNOTATION_ATTRIBUTE__(acquire_capability(__VA_ARGS__))
43 #define ACQUIRE_SHARED(...) \
44 THREAD_ANNOTATION_ATTRIBUTE__(acquire_shared_capability(__VA_ARGS__))
46 #define RELEASE(...) \
47 THREAD_ANNOTATION_ATTRIBUTE__(release_capability(__VA_ARGS__))
49 #define RELEASE_SHARED(...) \
50 THREAD_ANNOTATION_ATTRIBUTE__(release_shared_capability(__VA_ARGS__))
52 #define TRY_ACQUIRE(...) \
53 THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_capability(__VA_ARGS__))
55 #define TRY_ACQUIRE_SHARED(...) \
56 THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_shared_capability(__VA_ARGS__))
58 #define EXCLUDES(...) \
59 THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(__VA_ARGS__))
61 #define ASSERT_CAPABILITY(x) \
62 THREAD_ANNOTATION_ATTRIBUTE__(assert_capability(x))
64 #define ASSERT_SHARED_CAPABILITY(x) \
65 THREAD_ANNOTATION_ATTRIBUTE__(assert_shared_capability(x))
67 #define RETURN_CAPABILITY(x) \
68 THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x))
70 #define NO_THREAD_SAFETY_ANALYSIS \
71 THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis)
73 typedef struct CAPABILITY("mutex") {
74 volatile _Atomic(uint_fast32_t) lock;
77 #define TRN_MUTEX_STATIC_INITIALIZER {.lock = 0U}
79 typedef struct CAPABILITY("mutex") {
83 } trn_recursive_mutex_t;
85 #define TRN_RECURSIVE_MUTEX_STATIC_INITIALIZER {.mutex = TRN_MUTEX_STATIC_INITIALIZER, .owner = 0, .count = 0}
87 void trn_mutex_create(trn_mutex_t *mutex);
88 void trn_mutex_lock(trn_mutex_t *mutex) ACQUIRE(mutex);
95 bool trn_mutex_try_lock(trn_mutex_t *mutex) TRY_ACQUIRE(
true, mutex);
96 void trn_mutex_unlock(trn_mutex_t *mutex) RELEASE(mutex);
97 void trn_recursive_mutex_create(trn_recursive_mutex_t *recursive);
98 void trn_recursive_mutex_lock(trn_recursive_mutex_t *recursive) ACQUIRE(recursive);
104 bool trn_recursive_mutex_try_lock(trn_recursive_mutex_t *recursive) TRY_ACQUIRE(
true, recursive);
105 void trn_recursive_mutex_unlock(trn_recursive_mutex_t *recursive) RELEASE(recursive);
handle_t thread_h
Thread handle.
Definition: types.h:39
void trn_recursive_mutex_interrupt_lock(trn_recursive_mutex_t *recursive) ACQUIRE(recursive)
Locks the mutex. If it is currently being held by another thread, that thread will be interrupted via...
void trn_mutex_interrupt_lock(trn_mutex_t *mutex) ACQUIRE(mutex)
Locks the mutex. If it is currently being held by a thread, that thread will be interrupted via svcCa...