X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fcompiler.h;h=fb4d46cd1fd7b1ed11ab24dd5a6c7ad58749dd62;hb=69fc54f47bbc35e81bfe2e38e57f5dcfd9858df4;hp=94a2218a18d67b4d6d8b142141eb80671e08768b;hpb=5624b8ea01f98d2238b6c88c172c760e3c4b4525;p=sliver-openvswitch.git diff --git a/lib/compiler.h b/lib/compiler.h index 94a2218a1..fb4d46cd1 100644 --- a/lib/compiler.h +++ b/lib/compiler.h @@ -65,6 +65,16 @@ * while the specific MUTEX is held. * * + * On a variable A of mutex type: + * + * - OVS_ACQ_BEFORE(B), where B is a mutex or a comma-separated list of + * mutexes, declare that if both A and B are acquired at the same time, + * then A must be acquired before B. That is, B nests inside A. + * + * - OVS_ACQ_AFTER(B) is the opposite of OVS_ACQ_BEFORE(B), that is, it + * declares that A nests inside B. + * + * * On a function, the following attributes apply to mutexes: * * - OVS_ACQUIRES(MUTEX) indicate that the function must be called without @@ -84,6 +94,7 @@ * - OVS_LOCKS_EXCLUDED(MUTEX) indicates that the function may only be * called when MUTEX is not held. * + * * The following variants, with the same syntax, apply to reader-writer locks: * * mutex rwlock, for reading rwlock, for writing @@ -115,30 +126,11 @@ #define OVS_GUARDED_BY(...) __attribute__((guarded_by(__VA_ARGS__))) #define OVS_RELEASES(...) __attribute__((unlock_function(__VA_ARGS__))) #define OVS_EXCLUDED(...) __attribute__((locks_excluded(__VA_ARGS__))) -#elif __CHECKER__ -/* "sparse" annotations for mutexes and mutex-like constructs. - * - * Change the thread-safety check annotations to use "context" attribute. - * - * OVS_MACRO_LOCK and OVS_MACRO_RELEASE are suitable for use within macros, - * where there is no function prototype to annotate. */ -#define OVS_LOCKABLE -#define OVS_REQ_RDLOCK(...) __attribute__((context(MUTEX, 1, 1))) -#define OVS_ACQ_RDLOCK(...) __attribute__((context(MUTEX, 0, 1))) -#define OVS_REQ_WRLOCK(...) __attribute__((context(MUTEX, 1, 1))) -#define OVS_ACQ_WRLOCK(...) __attribute__((context(MUTEX, 0, 1))) -#define OVS_REQUIRES(...) __attribute__((context(MUTEX, 1, 1))) -#define OVS_ACQUIRES(...) __attribute__((context(MUTEX, 0, 1))) -#define OVS_TRY_WRLOCK(RETVAL, ...) -#define OVS_TRY_RDLOCK(RETVAL, ...) -#define OVS_TRY_LOCK(REVAL, ...) -#define OVS_GUARDED -#define OVS_GUARDED_BY(...) -#define OVS_EXCLUDED(...) -#define OVS_RELEASES(...) __attribute__((context(MUTEX, 1, 0))) -#define OVS_MACRO_LOCK(...) __context__(MUTEX, 0, 1) -#define OVS_MACRO_RELEASE(...) __context__(MUTEX, 1, 0) -#else +#define OVS_ACQ_BEFORE(...) __attribute__((acquired_before(__VA_ARGS__))) +#define OVS_ACQ_AFTER(...) __attribute__((acquired_after(__VA_ARGS__))) +#define OVS_NO_THREAD_SAFETY_ANALYSIS \ + __attribute__((no_thread_safety_analysis)) +#else /* not Clang */ #define OVS_LOCKABLE #define OVS_REQ_RDLOCK(...) #define OVS_ACQ_RDLOCK(...) @@ -153,8 +145,9 @@ #define OVS_GUARDED_BY(...) #define OVS_EXCLUDED(...) #define OVS_RELEASES(...) -#define OVS_MACRO_LOCK(...) -#define OVS_MACRO_RELEASE(...) +#define OVS_ACQ_BEFORE(...) +#define OVS_ACQ_AFTER(...) +#define OVS_NO_THREAD_SAFETY_ANALYSIS #endif /* ISO C says that a C implementation may choose any integer type for an enum