blob: 4f3cf8997cd7210f500bd07ac0870b849615bd4e [file] [log] [blame]
Elliott Hughes8eac9af2014-05-09 19:12:08 -07001/*
2 * Copyright (C) 2010 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
17#ifndef _BIONIC_MACROS_H_
18#define _BIONIC_MACROS_H_
19
Andreas Gampe00bbc7f2014-11-10 22:04:08 -080020// Frameworks OpenGL code currently leaks this header and allows
21// collisions with other declarations, e.g., from libnativehelper.
22// TODO: Remove once cleaned up. b/18334516
23#if !defined(DISALLOW_COPY_AND_ASSIGN)
Elliott Hughes8eac9af2014-05-09 19:12:08 -070024// DISALLOW_COPY_AND_ASSIGN disallows the copy and operator= functions.
25// It goes in the private: declarations in a class.
26#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
Dmitriy Ivanovd9ff7222014-09-08 16:22:22 -070027 TypeName(const TypeName&) = delete; \
28 void operator=(const TypeName&) = delete
Andreas Gampe00bbc7f2014-11-10 22:04:08 -080029#endif // !defined(DISALLOW_COPY_AND_ASSIGN)
Elliott Hughes8eac9af2014-05-09 19:12:08 -070030
31// A macro to disallow all the implicit constructors, namely the
32// default constructor, copy constructor and operator= functions.
33//
34// This should be used in the private: declarations for a class
35// that wants to prevent anyone from instantiating it. This is
36// especially useful for classes containing only static methods.
37#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
Dmitriy Ivanovd9ff7222014-09-08 16:22:22 -070038 TypeName() = delete; \
Elliott Hughes8eac9af2014-05-09 19:12:08 -070039 DISALLOW_COPY_AND_ASSIGN(TypeName)
40
Christopher Ferris03eebcb2014-06-13 13:57:51 -070041#define BIONIC_ALIGN(value, alignment) \
42 (((value) + (alignment) - 1) & ~((alignment) - 1))
43
44#define BIONIC_ROUND_UP_POWER_OF_2(value) \
Christopher Ferris27047fa2014-07-14 18:47:23 -070045 (sizeof(value) == 8) \
46 ? (1UL << (64 - __builtin_clzl(static_cast<unsigned long>(value)))) \
47 : (1UL << (32 - __builtin_clz(static_cast<unsigned int>(value))))
Christopher Ferris03eebcb2014-06-13 13:57:51 -070048
Elliott Hughes8eac9af2014-05-09 19:12:08 -070049#endif // _BIONIC_MACROS_H_