The Pedigree Project  0.1
threadsafety.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef _PEDIGREE_KERNEL_UTILITIES_THREADSAFETY_H
21 #define _PEDIGREE_KERNEL_UTILITIES_THREADSAFETY_H
22 
23 // Thread-safety annotations that can be used by clang
24 
25 #if defined(__clang__)
26 #define THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x))
27 #else
28 #define THREAD_ANNOTATION_ATTRIBUTE__(x) // no-op
29 #endif
30 
31 #define CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE__(capability(x))
32 #define SCOPED_CAPABILITY THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable)
33 #define GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x))
34 #define PT_GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x))
35 #define ACQUIRED_BEFORE(...) \
36  THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(__VA_ARGS__))
37 #define ACQUIRED_AFTER(...) \
38  THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(__VA_ARGS__))
39 #define REQUIRES(...) \
40  THREAD_ANNOTATION_ATTRIBUTE__(requires_capability(__VA_ARGS__))
41 #define REQUIRES_SHARED(...) \
42  THREAD_ANNOTATION_ATTRIBUTE__(requires_shared_capability(__VA_ARGS__))
43 #define ACQUIRE(...) \
44  THREAD_ANNOTATION_ATTRIBUTE__(acquire_capability(__VA_ARGS__))
45 #define ACQUIRE_SHARED(...) \
46  THREAD_ANNOTATION_ATTRIBUTE__(acquire_shared_capability(__VA_ARGS__))
47 #define RELEASE(...) \
48  THREAD_ANNOTATION_ATTRIBUTE__(release_capability(__VA_ARGS__))
49 #define RELEASE_SHARED(...) \
50  THREAD_ANNOTATION_ATTRIBUTE__(release_shared_capability(__VA_ARGS__))
51 #define TRY_ACQUIRE(...) \
52  THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_capability(__VA_ARGS__))
53 #define TRY_ACQUIRE_SHARED(...) \
54  THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_shared_capability(__VA_ARGS__))
55 #define EXCLUDES(...) THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(__VA_ARGS__))
56 #define ASSERT_CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE__(assert_capability(x))
57 #define ASSERT_SHARED_CAPABILITY(x) \
58  THREAD_ANNOTATION_ATTRIBUTE__(assert_shared_capability(x))
59 #define RETURN_CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x))
60 #define NO_THREAD_SAFETY_ANALYSIS \
61  THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis)
62 
63 #endif