diff options
author | Andy Schwerin <schwerin@10gen.com> | 2012-04-11 16:04:22 -0400 |
---|---|---|
committer | Andy Schwerin <schwerin@10gen.com> | 2012-04-12 12:22:05 -0400 |
commit | 6ae3906856e44147061a7fe7d60a1e73445ee40a (patch) | |
tree | 415c872041ca66e6f4033ca73a2a6c7080a04cf1 /src/mongo/platform/compiler_gcc.h | |
parent | e819261720e48699679c511c69f2f82c2c6a94ab (diff) | |
download | mongo-6ae3906856e44147061a7fe7d60a1e73445ee40a.tar.gz |
Introduce mongo/platform/compiler.h.
Get rid of most uses of __attribute__ and __declspec outside of the
platform/compiler headers.
Diffstat (limited to 'src/mongo/platform/compiler_gcc.h')
-rw-r--r-- | src/mongo/platform/compiler_gcc.h | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/mongo/platform/compiler_gcc.h b/src/mongo/platform/compiler_gcc.h new file mode 100644 index 00000000000..878d2ce7465 --- /dev/null +++ b/src/mongo/platform/compiler_gcc.h @@ -0,0 +1,71 @@ +// @file mongo/platform/compiler_gcc.h + +/* + * Copyright 2012 10gen Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +/** + * Compiler-specific implementations for gcc. + */ + +/** + * Use this to decorate the declaration of functions that will not return. + * + * Correct: + * MONGO_COMPILER_NORETURN void myAbortFunction(); + */ +#define MONGO_COMPILER_NORETURN __attribute__((__noreturn__)) + +/** + * Use this to decorate unused variable declarations. + */ +#define MONGO_COMPILER_VARIABLE_UNUSED __attribute__((__unused__)) + +/** + * Use this on a type declaration to specify its minimum alignment. + * + * Alignments should probably always be powers of two. Also, note that most allocators will not be + * able to guarantee better than 16- or 32-byte alignment. + * + * Correct: + * class MONGO_COMPILER_ALIGN_TYPE(16) MyClass {...}; + * + * Incorrect: + * MONGO_COMPILER_ALIGN_TYPE(16) class MyClass {...}; + * class MyClass{...} MONGO_COMPILER_ALIGN_TYPE(16); + */ +#define MONGO_COMPILER_ALIGN_TYPE(ALIGNMENT) __attribute__(( __aligned__(ALIGNMENT) )) + +/** + * Use this on a global variable or structure field declaration to specify that it must be allocated + * at a location that is aligned to a multiple of "ALIGNMENT" bytes. + * + * Note that most allocators will not allow heap allocated alignments that are better than 16- or + * 32-byte aligned. Stack allocators may only guarantee up to the natural word length worth of + * alignment. + * + * Correct: + * class MyClass { + * MONGO_COMPILER_ALIGN_VARIABLE(8) char a; + * }; + * + * MONGO_COMPILER_ALIGN_VARIABLE(8) class MyClass {...} singletonInstance; + * + * Incorrect: + * int MONGO_COMPILER_ALIGN_VARIABLE(16) a, b; + */ +#define MONGO_COMPILER_ALIGN_VARIABLE(ALIGNMENT) __attribute__(( __aligned__(ALIGNMENT) )) |