~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Merged in changes. 
Edited a the comment test case so deal with our version bump.

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., 59 Temple
15
 
Place, Suite 330, Boston, MA 02111-1307 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
 
UNIV_INTERN
50
 
void
51
 
ut_dbg_assertion_failed(
52
 
/*====================*/
53
 
        const char* expr,       /*!< in: the failed assertion */
54
 
        const char* file,       /*!< in: source file containing the assertion */
55
 
        ulint line);            /*!< in: line number of the assertion */
56
 
 
57
 
#ifdef __NETWARE__
58
 
/** Flag for ignoring further assertion failures.  This is set to TRUE
59
 
when on NetWare there happens an InnoDB assertion failure or other
60
 
fatal error condition that requires an immediate shutdown. */
61
 
extern ibool    panic_shutdown;
62
 
/* Abort the execution. */
63
 
void ut_dbg_panic(void);
64
 
# define UT_DBG_PANIC ut_dbg_panic()
65
 
/* Stop threads in ut_a(). */
66
 
# define UT_DBG_STOP    do {} while (0) /* We do not do this on NetWare */
67
 
#else /* __NETWARE__ */
68
 
# if defined(__WIN__) || defined(__INTEL_COMPILER)
69
 
#  undef UT_DBG_USE_ABORT
70
 
# elif defined(__GNUC__) && (__GNUC__ > 2)
71
 
#  define UT_DBG_USE_ABORT
72
 
# endif
73
 
 
74
 
# ifndef UT_DBG_USE_ABORT
75
 
/** A null pointer that will be dereferenced to trigger a memory trap */
76
 
extern ulint*   ut_dbg_null_ptr;
77
 
# endif
78
 
 
79
 
# if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
80
 
/** If this is set to TRUE by ut_dbg_assertion_failed(), all threads
81
 
will stop at the next ut_a() or ut_ad(). */
82
 
extern ibool    ut_dbg_stop_threads;
83
 
 
84
 
/*************************************************************//**
85
 
Stop a thread after assertion failure. */
86
 
UNIV_INTERN
87
 
void
88
 
ut_dbg_stop_thread(
89
 
/*===============*/
90
 
        const char*     file,
91
 
        ulint           line);
92
 
# endif
93
 
 
94
 
# ifdef UT_DBG_USE_ABORT
95
 
/** Abort the execution. */
96
 
#  define UT_DBG_PANIC abort()
97
 
/** Stop threads (null operation) */
98
 
#  define UT_DBG_STOP do {} while (0)
99
 
# else /* UT_DBG_USE_ABORT */
100
 
/** Abort the execution. */
101
 
#  define UT_DBG_PANIC                                  \
102
 
        if (*(ut_dbg_null_ptr)) ut_dbg_null_ptr = NULL
103
 
/** Stop threads in ut_a(). */
104
 
#  define UT_DBG_STOP do                                                \
105
 
        if (UNIV_UNLIKELY(ut_dbg_stop_threads)) {               \
106
 
                ut_dbg_stop_thread(__FILE__, (ulint) __LINE__); \
107
 
        } while (0)
108
 
# endif /* UT_DBG_USE_ABORT */
109
 
#endif /* __NETWARE__ */
110
 
 
111
 
/** Abort execution if EXPR does not evaluate to nonzero.
112
 
@param EXPR     assertion expression that should hold */
113
 
#define ut_a(EXPR) do {                                         \
114
 
        if (UT_DBG_FAIL(EXPR)) {                                \
115
 
                ut_dbg_assertion_failed(#EXPR,                  \
116
 
                                __FILE__, (ulint) __LINE__);    \
117
 
                UT_DBG_PANIC;                                   \
118
 
        }                                                       \
119
 
        UT_DBG_STOP;                                            \
120
 
} while (0)
121
 
 
122
 
/** Abort execution. */
123
 
#define ut_error do {                                           \
124
 
        ut_dbg_assertion_failed(0, __FILE__, (ulint) __LINE__); \
125
 
        UT_DBG_PANIC;                                           \
126
 
} while (0)
127
 
 
128
 
#ifdef UNIV_DEBUG
129
 
/** Debug assertion. Does nothing unless UNIV_DEBUG is defined. */
130
 
#define ut_ad(EXPR)     ut_a(EXPR)
131
 
/** Debug statement. Does nothing unless UNIV_DEBUG is defined. */
132
 
#define ut_d(EXPR)      do {EXPR;} while (0)
133
 
#else
134
 
/** Debug assertion. Does nothing unless UNIV_DEBUG is defined. */
135
 
#define ut_ad(EXPR)
136
 
/** Debug statement. Does nothing unless UNIV_DEBUG is defined. */
137
 
#define ut_d(EXPR)
138
 
#endif
139
 
 
140
 
/** Silence warnings about an unused variable by doing a null assignment.
141
 
@param A        the unused variable */
142
 
#define UT_NOT_USED(A)  A = A
143
 
 
144
 
#ifdef UNIV_COMPILE_TEST_FUNCS
145
 
 
146
 
#include <sys/types.h>
147
 
#include <sys/time.h>
148
 
#include <sys/resource.h>
149
 
 
150
 
/** structure used for recording usage statistics */
151
 
typedef struct speedo_struct {
152
 
        struct rusage   ru;     /*!< getrusage() result */
153
 
        struct timeval  tv;     /*!< gettimeofday() result */
154
 
} speedo_t;
155
 
 
156
 
/*******************************************************************//**
157
 
Resets a speedo (records the current time in it). */
158
 
UNIV_INTERN
159
 
void
160
 
speedo_reset(
161
 
/*=========*/
162
 
        speedo_t*       speedo);        /*!< out: speedo */
163
 
 
164
 
/*******************************************************************//**
165
 
Shows the time elapsed and usage statistics since the last reset of a
166
 
speedo. */
167
 
UNIV_INTERN
168
 
void
169
 
speedo_show(
170
 
/*========*/
171
 
        const speedo_t* speedo);        /*!< in: speedo */
172
 
 
173
 
#endif /* UNIV_COMPILE_TEST_FUNCS */
174
 
 
175
 
#endif