1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #ifndef MINIKIN_MACROS_H 17 #define MINIKIN_MACROS_H 18 19 #if defined(__clang__) 20 #define IGNORE_INTEGER_OVERFLOW __attribute__((no_sanitize("integer"))) 21 #else 22 #define IGNORE_INTEGER_OVERFLOW // no-op 23 #endif // __clang__ 24 25 #define MINIKIN_PREVENT_COPY_AND_ASSIGN(Type) \ 26 Type(const Type&) = delete; \ 27 Type& operator=(const Type&) = delete 28 29 #define MINIKIN_PREVENT_COPY_ASSIGN_AND_MOVE(Type) \ 30 Type(const Type&) = delete; \ 31 Type& operator=(const Type&) = delete; \ 32 Type(Type&&) = delete; \ 33 Type& operator=(Type&&) = delete 34 35 // Following thread annotations are partially copied from Abseil thread_annotations.h file. 36 // https://github.com/abseil/abseil-cpp/blob/master/absl/base/thread_annotations.h 37 38 #if defined(__clang__) 39 #define THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x)) 40 #else 41 #define THREAD_ANNOTATION_ATTRIBUTE__(x) // no-op 42 #endif 43 44 // GUARDED_BY() 45 // 46 // Documents if a shared field or global variable needs to be protected by a 47 // mutex. GUARDED_BY() allows the user to specify a particular mutex that 48 // should be held when accessing the annotated variable. 49 // 50 // Example: 51 // 52 // Mutex mu; 53 // int p1 GUARDED_BY(mu); 54 #define GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x)) 55 56 // EXCLUSIVE_LOCKS_REQUIRED() 57 // 58 // Documents a function that expects a mutex to be held prior to entry. 59 // The mutex is expected to be held both on entry to, and exit from, the 60 // function. 61 // 62 // Example: 63 // 64 // Mutex mu1, mu2; 65 // int a GUARDED_BY(mu1); 66 // int b GUARDED_BY(mu2); 67 // 68 // void foo() EXCLUSIVE_LOCKS_REQUIRED(mu1, mu2) { ... }; 69 #define EXCLUSIVE_LOCKS_REQUIRED(...) \ 70 THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(__VA_ARGS__)) 71 72 #endif // MINIKIN_MACROS_H 73