Commit 4386ee8c authored by Marko Mäkelä's avatar Marko Mäkelä

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.
parent 03a8eaa0
......@@ -574,15 +574,17 @@ struct st_replace *glob_replace= 0;
void replace_strings_append(struct st_replace *rep, DYNAMIC_STRING* ds,
const char *from, int len);
static void cleanup_and_exit(int exit_code) __attribute__((noreturn));
ATTRIBUTE_NORETURN
static void cleanup_and_exit(int exit_code);
void really_die(const char *msg) __attribute__((noreturn));
ATTRIBUTE_NORETURN
void really_die(const char *msg);
void report_or_die(const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
void die(const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 1, 2)
__attribute__((noreturn));
ATTRIBUTE_NORETURN ATTRIBUTE_FORMAT(printf, 1, 2)
void die(const char *fmt, ...);
static void make_error_message(char *buf, size_t len, const char *fmt, va_list args);
void abort_not_supported_test(const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 1, 2)
__attribute__((noreturn));
ATTRIBUTE_NORETURN ATTRIBUTE_FORMAT(printf, 1, 2)
void abort_not_supported_test(const char *fmt, ...);
void verbose_msg(const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
void log_msg(const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
......
......@@ -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 */
......@@ -19,6 +19,6 @@
#include "my_global.h" /* ulong */
void unireg_init(ulong options);
void unireg_end(void) __attribute__((noreturn));
ATTRIBUTE_NORETURN void unireg_end(void);
#endif /* INIT_INCLUDED */
......@@ -1570,7 +1570,7 @@ static void close_server_sock();
static void clean_up_mutexes(void);
static void wait_for_signal_thread_to_end(void);
static void create_pid_file();
static void mysqld_exit(int exit_code) __attribute__((noreturn));
ATTRIBUTE_NORETURN static void mysqld_exit(int exit_code);
#endif
static void delete_pid_file(myf flags);
static void end_ssl();
......
......@@ -708,7 +708,7 @@ enum enum_query_type
/* query_id */
extern query_id_t global_query_id;
void unireg_end(void) __attribute__((noreturn));
ATTRIBUTE_NORETURN void unireg_end(void);
/* increment query_id and return it. */
inline __attribute__((warn_unused_result)) query_id_t next_query_id()
......
......@@ -1005,7 +1005,7 @@ fil_flush_low(fil_space_t* space)
@param[in] size desired size in number of pages
@param[out] success whether the operation succeeded
@return whether the operation should be retried */
static UNIV_COLD __attribute__((warn_unused_result, nonnull))
static ATTRIBUTE_COLD __attribute__((warn_unused_result, nonnull))
bool
fil_space_extend_must_retry(
fil_space_t* space,
......
......@@ -102,7 +102,7 @@ then we will not allocate more extents
@param[in,out] space tablespace
@param[in,out] header tablespace header
@param[in,out] mtr mini-transaction */
static UNIV_COLD
static ATTRIBUTE_COLD
void
fsp_fill_free_list(
bool init_space,
......@@ -899,7 +899,7 @@ data file.
@param[in,out] header tablespace header
@param[in,out] mtr mini-transaction
@return true if success */
static UNIV_COLD MY_ATTRIBUTE((warn_unused_result))
static ATTRIBUTE_COLD __attribute__((warn_unused_result))
bool
fsp_try_extend_data_file_with_pages(
fil_space_t* space,
......@@ -932,7 +932,7 @@ fsp_try_extend_data_file_with_pages(
@param[in,out] mtr mini-transaction
@return number of pages added
@retval 0 if the tablespace was not extended */
UNIV_COLD MY_ATTRIBUTE((nonnull))
ATTRIBUTE_COLD __attribute__((nonnull))
static
ulint
fsp_try_extend_data_file(fil_space_t* space, fsp_header_t* header, mtr_t* mtr)
......
......@@ -271,7 +271,7 @@ innobase_get_int_col_max_value(
const Field* field); /*!< in: MySQL field */
/* Report an InnoDB error to the client by invoking my_error(). */
static UNIV_COLD MY_ATTRIBUTE((nonnull))
static ATTRIBUTE_COLD __attribute__((nonnull))
void
my_error_innodb(
/*============*/
......
......@@ -172,7 +172,7 @@ btr_corruption_report(
/*==================*/
const buf_block_t* block, /*!< in: corrupted block */
const dict_index_t* index) /*!< in: index tree */
UNIV_COLD MY_ATTRIBUTE((nonnull));
ATTRIBUTE_COLD __attribute__((nonnull));
/** Assert that a B-tree page is not corrupted.
@param block buffer block containing a B-tree page
......
......@@ -1867,7 +1867,7 @@ dict_set_corrupted(
dict_index_t* index, /*!< in/out: index */
trx_t* trx, /*!< in/out: transaction */
const char* ctx) /*!< in: context */
UNIV_COLD MY_ATTRIBUTE((nonnull));
ATTRIBUTE_COLD __attribute__((nonnull));
/** Flags an index corrupted in the data dictionary cache only. This
is used mostly to mark a corrupted index when index's own dictionary
......
......@@ -128,10 +128,8 @@ os_thread_join(
/** Exits the current thread.
@param[in] detach if true, the thread will be detached right before
exiting. If false, another thread is responsible for joining this thread */
void
os_thread_exit(
bool detach = true)
UNIV_COLD MY_ATTRIBUTE((noreturn));
ATTRIBUTE_NORETURN ATTRIBUTE_COLD
void os_thread_exit(bool detach = true);
/*****************************************************************//**
Returns the thread identifier of current thread.
......
......@@ -101,7 +101,7 @@ row_log_online_op(
const dtuple_t* tuple, /*!< in: index tuple */
trx_id_t trx_id) /*!< in: transaction ID for insert,
or 0 for delete */
UNIV_COLD MY_ATTRIBUTE((nonnull));
ATTRIBUTE_COLD __attribute__((nonnull));
/******************************************************//**
Gets the error status of the online index rebuild log.
......@@ -137,7 +137,7 @@ row_log_table_delete(
const ulint* offsets,/*!< in: rec_get_offsets(rec,index) */
const byte* sys) /*!< in: DB_TRX_ID,DB_ROLL_PTR that should
be logged, or NULL to use those in rec */
UNIV_COLD MY_ATTRIBUTE((nonnull(1,2,3)));
ATTRIBUTE_COLD __attribute__((nonnull(1,2,3)));
/******************************************************//**
Logs an update operation to a table that is being rebuilt.
......@@ -174,7 +174,7 @@ row_log_table_get_pk(
byte* sys, /*!< out: DB_TRX_ID,DB_ROLL_PTR for
row_log_table_delete(), or NULL */
mem_heap_t** heap) /*!< in/out: memory heap where allocated */
UNIV_COLD MY_ATTRIBUTE((nonnull(1,2,5), warn_unused_result));
ATTRIBUTE_COLD __attribute__((nonnull(1,2,5), warn_unused_result));
/******************************************************//**
Logs an insert to a table that is being rebuilt.
......@@ -195,7 +195,7 @@ row_log_table_blob_free(
/*====================*/
dict_index_t* index, /*!< in/out: clustered index, X-latched */
ulint page_no)/*!< in: starting page number of the BLOB */
UNIV_COLD MY_ATTRIBUTE((nonnull));
ATTRIBUTE_COLD __attribute__((nonnull));
/******************************************************//**
Notes that a BLOB is being allocated during online ALTER TABLE. */
void
......@@ -203,7 +203,7 @@ row_log_table_blob_alloc(
/*=====================*/
dict_index_t* index, /*!< in/out: clustered index, X-latched */
ulint page_no)/*!< in: starting page number of the BLOB */
UNIV_COLD MY_ATTRIBUTE((nonnull));
ATTRIBUTE_COLD __attribute__((nonnull));
/** Apply the row_log_table log to a table upon completing rebuild.
@param[in] thr query graph
......
......@@ -319,7 +319,7 @@ void
trx_undo_free_prepared(
/*===================*/
trx_t* trx) /*!< in/out: PREPARED transaction */
UNIV_COLD MY_ATTRIBUTE((nonnull));
ATTRIBUTE_COLD __attribute__((nonnull));
/* Forward declaration. */
namespace undo {
......
......@@ -258,23 +258,6 @@ easy way to get it to work. See http://bugs.mysql.com/bug.php?id=52263. */
#endif
#endif
#if defined(COMPILER_HINTS) \
&& defined __GNUC__ \
&& (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 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 UNIV_COLD MY_ATTRIBUTE((cold))
#else
# define UNIV_COLD /* empty */
#endif
#define UNIV_INLINE static inline
#define UNIV_WORD_SIZE SIZEOF_SIZE_T
......
......@@ -39,13 +39,13 @@ Created 1/30/1994 Heikki Tuuri
/*************************************************************//**
Report a failed assertion. */
ATTRIBUTE_NORETURN ATTRIBUTE_COLD __attribute__((nonnull(2)))
void
ut_dbg_assertion_failed(
/*====================*/
const char* expr, /*!< in: the failed assertion */
const char* file, /*!< in: source file containing the assertion */
unsigned line) /*!< in: line number of the assertion */
UNIV_COLD MY_ATTRIBUTE((nonnull(2), noreturn));
unsigned line); /*!< in: line number of the assertion */
/** Abort execution if EXPR does not evaluate to nonzero.
@param EXPR assertion expression that should hold */
......
......@@ -299,7 +299,7 @@ void
ut_print_timestamp(
/*===============*/
FILE* file) /*!< in: file where to print */
UNIV_COLD MY_ATTRIBUTE((nonnull));
ATTRIBUTE_COLD __attribute__((nonnull));
#ifndef UNIV_INNOCHECKSUM
......@@ -505,6 +505,7 @@ use this class directly, instead use one of the derived classes. */
class logger {
public:
template<typename T>
ATTRIBUTE_COLD
logger& operator<<(const T& rhs)
{
m_oss << rhs;
......@@ -515,6 +516,7 @@ class logger {
@param[in] buf the buffer whose contents will be logged.
@param[in] count the length of the buffer buf.
@return the output stream into which buffer was written. */
ATTRIBUTE_COLD
std::ostream&
write(
const char* buf,
......@@ -527,6 +529,7 @@ class logger {
@param[in] buf the buffer whose contents will be logged.
@param[in] count the length of the buffer buf.
@return the output stream into which buffer was written. */
ATTRIBUTE_COLD
std::ostream&
write(
const byte* buf,
......@@ -539,6 +542,7 @@ class logger {
protected:
/* This class must not be used directly, hence making the default
constructor protected. */
ATTRIBUTE_COLD
logger() {}
};
......@@ -555,6 +559,7 @@ statement. If a named object is created, then the log message will be emitted
only when it goes out of scope or destroyed. */
class info : public logger {
public:
ATTRIBUTE_COLD
~info();
};
......@@ -562,6 +567,7 @@ class info : public logger {
class info for further details. */
class warn : public logger {
public:
ATTRIBUTE_COLD
~warn();
};
......@@ -569,6 +575,7 @@ class warn : public logger {
documentation of class info for further details. */
class error : public logger {
public:
ATTRIBUTE_COLD
~error();
};
......@@ -577,6 +584,7 @@ by crashing it. Use this class when MySQL server needs to be stopped
immediately. Refer to the documentation of class info for usage details. */
class fatal : public logger {
public:
ATTRIBUTE_NORETURN
~fatal();
};
......@@ -584,10 +592,12 @@ class fatal : public logger {
warning message */
class error_or_warn : public logger {
public:
ATTRIBUTE_COLD
error_or_warn(bool pred)
: m_error(pred)
{}
ATTRIBUTE_COLD
~error_or_warn();
private:
const bool m_error;
......@@ -597,10 +607,12 @@ class error_or_warn : public logger {
error message. */
class fatal_or_error : public logger {
public:
ATTRIBUTE_COLD
fatal_or_error(bool pred)
: m_fatal(pred)
{}
ATTRIBUTE_COLD
~fatal_or_error();
private:
const bool m_fatal;
......
......@@ -174,9 +174,9 @@ os_thread_join(
/** Exits the current thread.
@param[in] detach if true, the thread will be detached right before
exiting. If false, another thread is responsible for joining this thread */
ATTRIBUTE_NORETURN
void
os_thread_exit(
bool detach)
os_thread_exit(bool detach)
{
#ifdef UNIV_DEBUG_THREAD_CREATION
ib::info() << "Thread exits, id "
......
......@@ -158,7 +158,7 @@ TODO: Remove this function. Everything should use MYSQL_TYPE_NEWDECIMAL.
@param[in] b_length length of b, in bytes (not UNIV_SQL_NULL)
@return positive, 0, negative, if a is greater, equal, less than b,
respectively */
static UNIV_COLD
static ATTRIBUTE_COLD
int
cmp_decimal(
const byte* a,
......
......@@ -30,6 +30,7 @@ Created 1/30/1994 Heikki Tuuri
/*************************************************************//**
Report a failed assertion. */
ATTRIBUTE_NORETURN
void
ut_dbg_assertion_failed(
/*====================*/
......
......@@ -834,6 +834,7 @@ error::~error()
sql_print_error("InnoDB: %s", m_oss.str().c_str());
}
ATTRIBUTE_NORETURN
fatal::~fatal()
{
sql_print_error("[FATAL] InnoDB: %s", m_oss.str().c_str());
......
......@@ -89,7 +89,7 @@ static int sort_record_index(MARIA_SORT_PARAM *sort_param, MARIA_PAGE *page,
uint sortkey, File new_file,
my_bool update_index);
static my_bool write_log_record(HA_CHECK *param);
static void my_exit(int exit_code) __attribute__ ((noreturn));
ATTRIBUTE_NORETURN static void my_exit(int exit_code);
HA_CHECK check_param;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment