1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

Add ATTRIBUTE_NORETURN and ATTRIBUTE_COLD

ATTRIBUTE_NORETURN is supported on all platforms (MSVS and GCC-like).
It declares that a function will not return; instead, the thread or
the whole process will terminate.

ATTRIBUTE_COLD is supported starting with GCC 4.3. It declares that
a function is supposed to be executed rarely. Rarely used error-handling
functions and functions that emit messages to the error log should be
tagged such.
This commit is contained in:
Marko Mäkelä
2017-08-31 08:20:29 +03:00
parent 03a8eaa072
commit 4386ee8ccc
21 changed files with 70 additions and 50 deletions

View File

@@ -148,6 +148,29 @@ struct my_aligned_storage
#define MY_ALIGNED(size)
#endif
#ifdef __GNUC__
# define ATTRIBUTE_NORETURN __attribute__((noreturn))
# if MY_GNUC_PREREQ(4,3)
/** Starting with GCC 4.3, the "cold" attribute is used to inform the
compiler that a function is unlikely executed. The function is
optimized for size rather than speed and on many targets it is placed
into special subsection of the text section so all cold functions
appears close together improving code locality of non-cold parts of
program. The paths leading to call of cold functions within code are
marked as unlikely by the branch prediction mechanism. optimize a
rarely invoked function for size instead for speed. */
# define ATTRIBUTE_COLD __attribute__((cold))
# endif
#elif defined _WIN32
# define ATTRIBUTE_NORETURN __declspec(noreturn)
#else
# define ATTRIBUTE_NORETURN /* empty */
#endif
#ifndef ATTRIBUTE_COLD
# define ATTRIBUTE_COLD /* empty */
#endif
#include <my_attribute.h>
#endif /* MY_COMPILER_INCLUDED */