1 //===-- sanitizer_thread_safety.h -------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file is shared between sanitizer tools. 10 // 11 // Wrappers around thread safety annotations. 12 // https://clang.llvm.org/docs/ThreadSafetyAnalysis.html 13 //===----------------------------------------------------------------------===// 14 15 #ifndef SANITIZER_THREAD_SAFETY_H 16 #define SANITIZER_THREAD_SAFETY_H 17 18 #if defined(__clang__) 19 # define THREAD_ANNOTATION(x) __attribute__((x)) 20 #else 21 # define THREAD_ANNOTATION(x) 22 #endif 23 24 #define MUTEX THREAD_ANNOTATION(capability("mutex")) 25 #define SCOPED_LOCK THREAD_ANNOTATION(scoped_lockable) 26 #define GUARDED_BY(x) THREAD_ANNOTATION(guarded_by(x)) 27 #define PT_GUARDED_BY(x) THREAD_ANNOTATION(pt_guarded_by(x)) 28 #define REQUIRES(...) THREAD_ANNOTATION(requires_capability(__VA_ARGS__)) 29 #define REQUIRES_SHARED(...) \ 30 THREAD_ANNOTATION(requires_shared_capability(__VA_ARGS__)) 31 #define ACQUIRE(...) THREAD_ANNOTATION(acquire_capability(__VA_ARGS__)) 32 #define ACQUIRE_SHARED(...) \ 33 THREAD_ANNOTATION(acquire_shared_capability(__VA_ARGS__)) 34 #define TRY_ACQUIRE(...) THREAD_ANNOTATION(try_acquire_capability(__VA_ARGS__)) 35 #define RELEASE(...) THREAD_ANNOTATION(release_capability(__VA_ARGS__)) 36 #define RELEASE_SHARED(...) \ 37 THREAD_ANNOTATION(release_shared_capability(__VA_ARGS__)) 38 #define EXCLUDES(...) THREAD_ANNOTATION(locks_excluded(__VA_ARGS__)) 39 #define CHECK_LOCKED(...) THREAD_ANNOTATION(assert_capability(__VA_ARGS__)) 40 #define NO_THREAD_SAFETY_ANALYSIS THREAD_ANNOTATION(no_thread_safety_analysis) 41 42 #endif 43