~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/ut0dbg.h

  • Committer: Monty Taylor
  • Date: 2008-09-16 00:00:48 UTC
  • mto: This revision was merged to the branch mainline in revision 391.
  • Revision ID: monty@inaugust.com-20080916000048-3rvrv3gv9l0ad3gs
Fixed copyright headers in drizzled/

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (C) 1994, 2009, Innobase Oy. All Rights Reserved.
4
 
 
5
 
This program is free software; you can redistribute it and/or modify it under
6
 
the terms of the GNU General Public License as published by the Free Software
7
 
Foundation; version 2 of the License.
8
 
 
9
 
This program is distributed in the hope that it will be useful, but WITHOUT
10
 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
 
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
 
 
13
 
You should have received a copy of the GNU General Public License along with
14
 
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/*****************************************************************//**
20
 
@file include/ut0dbg.h
21
 
Debug utilities for Innobase
22
 
 
23
 
Created 1/30/1994 Heikki Tuuri
24
 
**********************************************************************/
25
 
 
26
 
#ifndef ut0dbg_h
27
 
#define ut0dbg_h
28
 
 
29
 
#include "univ.i"
30
 
#include <stdlib.h>
31
 
#include "os0thread.h"
32
 
 
33
 
#if defined(__GNUC__) && (__GNUC__ > 2)
34
 
/** Test if an assertion fails.
35
 
@param EXPR     assertion expression
36
 
@return         nonzero if EXPR holds, zero if not */
37
 
# define UT_DBG_FAIL(EXPR) UNIV_UNLIKELY(!((ulint)(EXPR)))
38
 
#else
39
 
/** This is used to eliminate compiler warnings */
40
 
extern ulint    ut_dbg_zero;
41
 
/** Test if an assertion fails.
42
 
@param EXPR     assertion expression
43
 
@return         nonzero if EXPR holds, zero if not */
44
 
# define UT_DBG_FAIL(EXPR) !((ulint)(EXPR) + ut_dbg_zero)
45
 
#endif
46
 
 
47
 
/*************************************************************//**
48
 
Report a failed assertion. */
49
 
#ifdef __cplusplus
50
 
extern "C"
51
 
#endif
52
 
UNIV_INTERN
53
 
void
54
 
ut_dbg_assertion_failed(
55
 
/*====================*/
56
 
        const char* expr,       /*!< in: the failed assertion */
57
 
        const char* file,       /*!< in: source file containing the assertion */
58
 
        ulint line);            /*!< in: line number of the assertion */
59
 
 
60
 
#if defined(__WIN__) || defined(__INTEL_COMPILER)
61
 
# undef UT_DBG_USE_ABORT
62
 
#elif defined(__GNUC__) && (__GNUC__ > 2)
63
 
# define UT_DBG_USE_ABORT
64
 
#endif
65
 
 
66
 
#ifndef UT_DBG_USE_ABORT
67
 
/** A null pointer that will be dereferenced to trigger a memory trap */
68
 
extern ulint*   ut_dbg_null_ptr;
69
 
#endif
70
 
 
71
 
#if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
72
 
/** If this is set to TRUE by ut_dbg_assertion_failed(), all threads
73
 
will stop at the next ut_a() or ut_ad(). */
74
 
extern ibool    ut_dbg_stop_threads;
75
 
 
76
 
/*************************************************************//**
77
 
Stop a thread after assertion failure. */
78
 
UNIV_INTERN
79
 
void
80
 
ut_dbg_stop_thread(
81
 
/*===============*/
82
 
        const char*     file,
83
 
        ulint           line);
84
 
#endif
85
 
 
86
 
#ifdef UT_DBG_USE_ABORT
87
 
/** Abort the execution. */
88
 
# define UT_DBG_PANIC abort()
89
 
/** Stop threads (null operation) */
90
 
# define UT_DBG_STOP do {} while (0)
91
 
#else /* UT_DBG_USE_ABORT */
92
 
/** Abort the execution. */
93
 
# define UT_DBG_PANIC                                   \
94
 
        if (*(ut_dbg_null_ptr)) ut_dbg_null_ptr = NULL
95
 
/** Stop threads in ut_a(). */
96
 
# define UT_DBG_STOP do                                         \
97
 
        if (UNIV_UNLIKELY(ut_dbg_stop_threads)) {               \
98
 
                ut_dbg_stop_thread(__FILE__, (ulint) __LINE__); \
99
 
        } while (0)
100
 
#endif /* UT_DBG_USE_ABORT */
101
 
 
102
 
/** Abort execution if EXPR does not evaluate to nonzero.
103
 
@param EXPR     assertion expression that should hold */
104
 
#define ut_a(EXPR) do {                                         \
105
 
        if (UT_DBG_FAIL(EXPR)) {                                \
106
 
                ut_dbg_assertion_failed(#EXPR,                  \
107
 
                                __FILE__, (ulint) __LINE__);    \
108
 
                UT_DBG_PANIC;                                   \
109
 
        }                                                       \
110
 
        UT_DBG_STOP;                                            \
111
 
} while (0)
112
 
 
113
 
/** Abort execution. */
114
 
#define ut_error do {                                           \
115
 
        ut_dbg_assertion_failed(0, __FILE__, (ulint) __LINE__); \
116
 
        UT_DBG_PANIC;                                           \
117
 
} while (0)
118
 
 
119
 
#ifdef UNIV_DEBUG
120
 
/** Debug assertion. Does nothing unless UNIV_DEBUG is defined. */
121
 
#define ut_ad(EXPR)     ut_a(EXPR)
122
 
/** Debug statement. Does nothing unless UNIV_DEBUG is defined. */
123
 
#define ut_d(EXPR)      do {EXPR;} while (0)
124
 
#else
125
 
/** Debug assertion. Does nothing unless UNIV_DEBUG is defined. */
126
 
#define ut_ad(EXPR)
127
 
/** Debug statement. Does nothing unless UNIV_DEBUG is defined. */
128
 
#define ut_d(EXPR)
129
 
#endif
130
 
 
131
 
/** Silence warnings about an unused variable by doing a null assignment.
132
 
@param A        the unused variable */
133
 
#define UT_NOT_USED(A)  A = A
134
 
 
135
 
#ifdef UNIV_COMPILE_TEST_FUNCS
136
 
 
137
 
#include <sys/types.h>
138
 
#include <sys/time.h>
139
 
#include <sys/resource.h>
140
 
 
141
 
/** structure used for recording usage statistics */
142
 
typedef struct speedo_struct {
143
 
        struct rusage   ru;     /*!< getrusage() result */
144
 
        struct timeval  tv;     /*!< gettimeofday() result */
145
 
} speedo_t;
146
 
 
147
 
/*******************************************************************//**
148
 
Resets a speedo (records the current time in it). */
149
 
UNIV_INTERN
150
 
void
151
 
speedo_reset(
152
 
/*=========*/
153
 
        speedo_t*       speedo);        /*!< out: speedo */
154
 
 
155
 
/*******************************************************************//**
156
 
Shows the time elapsed and usage statistics since the last reset of a
157
 
speedo. */
158
 
UNIV_INTERN
159
 
void
160
 
speedo_show(
161
 
/*========*/
162
 
        const speedo_t* speedo);        /*!< in: speedo */
163
 
 
164
 
#endif /* UNIV_COMPILE_TEST_FUNCS */
165
 
 
166
 
#endif