bionic_macros.h revision 03eebcb6e8762e668a0d3af6bb303cccb88c5b81
18eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes/*
28eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes * Copyright (C) 2010 The Android Open Source Project
38eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes *
48eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes * Licensed under the Apache License, Version 2.0 (the "License");
58eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes * you may not use this file except in compliance with the License.
68eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes * You may obtain a copy of the License at
78eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes *
88eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes *      http://www.apache.org/licenses/LICENSE-2.0
98eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes *
108eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes * Unless required by applicable law or agreed to in writing, software
118eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
128eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes * See the License for the specific language governing permissions and
148eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes * limitations under the License.
158eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes */
168eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes
178eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes#ifndef _BIONIC_MACROS_H_
188eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes#define _BIONIC_MACROS_H_
198eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes
208eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes// DISALLOW_COPY_AND_ASSIGN disallows the copy and operator= functions.
218eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes// It goes in the private: declarations in a class.
228eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
238eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes  TypeName(const TypeName&);               \
248eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes  void operator=(const TypeName&)
258eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes
268eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes// A macro to disallow all the implicit constructors, namely the
278eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes// default constructor, copy constructor and operator= functions.
288eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes//
298eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes// This should be used in the private: declarations for a class
308eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes// that wants to prevent anyone from instantiating it. This is
318eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes// especially useful for classes containing only static methods.
328eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
338eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes  TypeName();                                    \
348eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes  DISALLOW_COPY_AND_ASSIGN(TypeName)
358eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes
3603eebcb6e8762e668a0d3af6bb303cccb88c5b81Christopher Ferris#define BIONIC_ALIGN(value, alignment) \
3703eebcb6e8762e668a0d3af6bb303cccb88c5b81Christopher Ferris  (((value) + (alignment) - 1) & ~((alignment) - 1))
3803eebcb6e8762e668a0d3af6bb303cccb88c5b81Christopher Ferris
3903eebcb6e8762e668a0d3af6bb303cccb88c5b81Christopher Ferris#define BIONIC_ROUND_UP_POWER_OF_2(value) \
4003eebcb6e8762e668a0d3af6bb303cccb88c5b81Christopher Ferris  (1UL << (sizeof(value) * 8 - 1 - __builtin_clz(value)))
4103eebcb6e8762e668a0d3af6bb303cccb88c5b81Christopher Ferris
428eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39Elliott Hughes#endif // _BIONIC_MACROS_H_
43