Home | History | Annotate | Download | only in minikin
      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 #define MINIKIN_PREVENT_COPY_AND_ASSIGN(Type) \
     20     Type(const Type&) = delete;               \
     21     Type& operator=(const Type&) = delete
     22 
     23 #define MINIKIN_PREVENT_COPY_ASSIGN_AND_MOVE(Type) \
     24     Type(const Type&) = delete;                    \
     25     Type& operator=(const Type&) = delete;         \
     26     Type(Type&&) = delete;                         \
     27     Type& operator=(Type&&) = delete
     28 
     29 // Following thread annotations are partially copied from Abseil thread_annotations.h file.
     30 // https://github.com/abseil/abseil-cpp/blob/master/absl/base/thread_annotations.h
     31 
     32 #if defined(__clang__)
     33 #define THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x))
     34 #else
     35 #define THREAD_ANNOTATION_ATTRIBUTE__(x)  // no-op
     36 #endif
     37 
     38 // GUARDED_BY()
     39 //
     40 // Documents if a shared field or global variable needs to be protected by a
     41 // mutex. GUARDED_BY() allows the user to specify a particular mutex that
     42 // should be held when accessing the annotated variable.
     43 //
     44 // Example:
     45 //
     46 //   Mutex mu;
     47 //   int p1 GUARDED_BY(mu);
     48 #define GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x))
     49 
     50 // EXCLUSIVE_LOCKS_REQUIRED()
     51 //
     52 // Documents a function that expects a mutex to be held prior to entry.
     53 // The mutex is expected to be held both on entry to, and exit from, the
     54 // function.
     55 //
     56 // Example:
     57 //
     58 //   Mutex mu1, mu2;
     59 //   int a GUARDED_BY(mu1);
     60 //   int b GUARDED_BY(mu2);
     61 //
     62 //   void foo() EXCLUSIVE_LOCKS_REQUIRED(mu1, mu2) { ... };
     63 #define EXCLUSIVE_LOCKS_REQUIRED(...) \
     64     THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(__VA_ARGS__))
     65 
     66 #endif  // MINIKIN_MACROS_H
     67