~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/univ.i

  • Committer: Lee
  • Date: 2008-10-30 22:02:01 UTC
  • mto: (572.1.2 devel)
  • mto: This revision was merged to the branch mainline in revision 573.
  • Revision ID: lbieber@lbieber-desktop-20081030220201-elb6qprbzpn7c5a4
add my name to the AUTHORS file

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
Version control for database, common definitions, and include files
 
3
 
 
4
(c) 1994 - 2000 Innobase Oy
 
5
 
 
6
Created 1/20/1994 Heikki Tuuri
 
7
****************************************************************************/
 
8
 
 
9
#ifndef univ_i
 
10
#define univ_i
 
11
 
 
12
#define INNODB_VERSION_MAJOR    1
 
13
#define INNODB_VERSION_MINOR    0
 
14
#define INNODB_VERSION_BUGFIX   1
 
15
 
 
16
/* The following is the InnoDB version as shown in
 
17
SELECT plugin_version FROM information_schema.plugins;
 
18
calculated in in make_version_string() in sql/sql_show.cc like this:
 
19
"version >> 8" . "version & 0xff"
 
20
because the version is shown with only one dot, we skip the last
 
21
component, i.e. we show M.N.P as M.N */
 
22
#define INNODB_VERSION_SHORT    \
 
23
        (INNODB_VERSION_MAJOR << 8 | INNODB_VERSION_MINOR)
 
24
 
 
25
/* auxiliary macros to help creating the version as string */
 
26
#define __INNODB_VERSION(a, b, c)       (#a "." #b "." #c)
 
27
#define _INNODB_VERSION(a, b, c)        __INNODB_VERSION(a, b, c)
 
28
 
 
29
#define INNODB_VERSION_STR                      \
 
30
        _INNODB_VERSION(INNODB_VERSION_MAJOR,   \
 
31
                        INNODB_VERSION_MINOR,   \
 
32
                        INNODB_VERSION_BUGFIX)
 
33
 
 
34
#ifdef MYSQL_DYNAMIC_PLUGIN
 
35
/* In the dynamic plugin, redefine some externally visible symbols
 
36
in order not to conflict with the symbols of a builtin InnoDB. */
 
37
 
 
38
/* Rename all C++ classes that contain virtual functions, because we
 
39
have not figured out how to apply the visibility=hidden attribute to
 
40
the virtual method table (vtable) in GCC 3. */
 
41
# define ha_innobase ha_innodb
 
42
#endif /* MYSQL_DYNAMIC_PLUGIN */
 
43
 
 
44
#if (defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)) && !defined(MYSQL_SERVER) && !defined(__WIN__)
 
45
# undef __WIN__
 
46
# define __WIN__
 
47
 
 
48
# include <windows.h>
 
49
 
 
50
# if !defined(WIN64) && !defined(_WIN64)
 
51
#  define UNIV_CAN_USE_X86_ASSEMBLER
 
52
# endif
 
53
 
 
54
# ifdef _NT_
 
55
#  define __NT__
 
56
# endif
 
57
 
 
58
#else
 
59
/* The defines used with MySQL */
 
60
 
 
61
/* Include two header files from MySQL to make the Unix flavor used
 
62
in compiling more Posix-compatible. These headers also define __WIN__
 
63
if we are compiling on Windows. */
 
64
 
 
65
# if defined(BUILD_DRIZZLE)
 
66
#  include <drizzled/global.h>
 
67
#  include <mysys/my_pthread.h>
 
68
# else
 
69
#  include <my_global.h>
 
70
#  include <my_pthread.h>
 
71
# endif
 
72
 
 
73
/* Include <sys/stat.h> to get S_I... macros defined for os0file.c */
 
74
# include <sys/stat.h>
 
75
# if !defined(__NETWARE__) && !defined(__WIN__) 
 
76
#  include <sys/mman.h> /* mmap() for os0proc.c */
 
77
# endif
 
78
 
 
79
# undef PACKAGE
 
80
# undef VERSION
 
81
 
 
82
/* Include the header file generated by GNU autoconf */
 
83
# ifndef __WIN__
 
84
#  include <config.h>
 
85
# endif
 
86
 
 
87
# ifdef HAVE_SCHED_H
 
88
#  include <sched.h>
 
89
# endif
 
90
 
 
91
/* When compiling for Itanium IA64, undefine the flag below to prevent use
 
92
of the 32-bit x86 assembler in mutex operations. */
 
93
 
 
94
# if defined(__WIN__) && !defined(WIN64) && !defined(_WIN64)
 
95
#  define UNIV_CAN_USE_X86_ASSEMBLER
 
96
# endif
 
97
 
 
98
/* We only try to do explicit inlining of functions with gcc and
 
99
Microsoft Visual C++ */
 
100
 
 
101
# if !defined(__GNUC__)
 
102
#  undef  UNIV_MUST_NOT_INLINE                  /* Remove compiler warning */
 
103
#  define UNIV_MUST_NOT_INLINE
 
104
# endif
 
105
 
 
106
# ifdef HAVE_PREAD
 
107
#  define HAVE_PWRITE
 
108
# endif
 
109
 
 
110
#endif /* #if (defined(WIN32) || ... */
 
111
 
 
112
/*                      DEBUG VERSION CONTROL
 
113
                        ===================== */
 
114
 
 
115
/* The following flag will make InnoDB to initialize
 
116
all memory it allocates to zero. It hides Purify
 
117
warnings about reading unallocated memory unless
 
118
memory is read outside the allocated blocks. */
 
119
/*
 
120
#define UNIV_INIT_MEM_TO_ZERO
 
121
*/
 
122
 
 
123
/* When this macro is defined then additional test functions will be
 
124
compiled. These functions live at the end of each relevant source file
 
125
and have "test_" prefix. These functions are not called from anywhere in
 
126
the code, they can be called from gdb after
 
127
innobase_start_or_create_for_mysql() has executed using the call
 
128
command. Not tested on Windows. */
 
129
/*
 
130
#define UNIV_COMPILE_TEST_FUNCS
 
131
*/
 
132
 
 
133
#if 0
 
134
#define UNIV_DEBUG_VALGRIND                     /* Enable extra
 
135
                                                Valgrind instrumentation */
 
136
#define UNIV_DEBUG_PRINT                        /* Enable the compilation of
 
137
                                                some debug print functions */
 
138
#define UNIV_BUF_DEBUG                          /* Enable buffer pool
 
139
                                                debugging without UNIV_DEBUG */
 
140
#define UNIV_DEBUG                              /* Enable ut_ad() assertions
 
141
                                                and disable UNIV_INLINE */
 
142
#define UNIV_DEBUG_FILE_ACCESSES                /* Debug .ibd file access
 
143
                                                (field file_page_was_freed
 
144
                                                in buf_page_t) */
 
145
#define UNIV_HASH_DEBUG                         /* debug HASH_ macros */
 
146
#define UNIV_LIST_DEBUG                         /* debug UT_LIST_ macros */
 
147
#define UNIV_MEM_DEBUG                          /* detect memory leaks etc */
 
148
#define UNIV_IBUF_DEBUG                         /* debug the insert buffer */
 
149
#define UNIV_IBUF_COUNT_DEBUG                   /* debug the insert buffer;
 
150
this limits the database to IBUF_COUNT_N_SPACES and IBUF_COUNT_N_PAGES,
 
151
and the insert buffer must be empty when the database is started */
 
152
#define UNIV_SYNC_DEBUG                         /* debug mutex and latch
 
153
operations (very slow); also UNIV_DEBUG must be defined */
 
154
#define UNIV_SEARCH_DEBUG                       /* debug B-tree comparisons */
 
155
#define UNIV_SYNC_PERF_STAT                     /* operation counts for
 
156
                                                rw-locks and mutexes */
 
157
#define UNIV_SEARCH_PERF_STAT                   /* statistics for the
 
158
                                                adaptive hash index */
 
159
#define UNIV_SRV_PRINT_LATCH_WAITS              /* enable diagnostic output
 
160
                                                in sync0sync.c */
 
161
#define UNIV_BTR_PRINT                          /* enable functions for
 
162
                                                printing B-trees */
 
163
#define UNIV_ZIP_DEBUG                          /* extensive consistency checks
 
164
                                                for compressed pages */
 
165
#endif
 
166
 
 
167
#define UNIV_BTR_DEBUG                          /* check B-tree links */
 
168
#define UNIV_LIGHT_MEM_DEBUG                    /* light memory debugging */
 
169
 
 
170
#ifdef HAVE_purify
 
171
/* The following sets all new allocated memory to zero before use:
 
172
this can be used to eliminate unnecessary Purify warnings, but note that
 
173
it also masks many bugs Purify could detect. For detailed Purify analysis it
 
174
is best to remove the define below and look through the warnings one
 
175
by one. */
 
176
#define UNIV_SET_MEM_TO_ZERO
 
177
#endif
 
178
 
 
179
/*
 
180
#define UNIV_SQL_DEBUG
 
181
#define UNIV_LOG_DEBUG
 
182
*/
 
183
                        /* the above option prevents forcing of log to disk
 
184
                        at a buffer page write: it should be tested with this
 
185
                        option off; also some ibuf tests are suppressed */
 
186
/*
 
187
#define UNIV_BASIC_LOG_DEBUG
 
188
*/
 
189
                        /* the above option enables basic recovery debugging:
 
190
                        new allocated file pages are reset */
 
191
 
 
192
/* Linkage specifier for non-static InnoDB symbols (variables and functions)
 
193
that are only referenced from within InnoDB, not from MySQL */
 
194
#ifdef __WIN__
 
195
# define UNIV_INTERN
 
196
#else
 
197
# define UNIV_INTERN __attribute__((visibility ("hidden")))
 
198
#endif
 
199
 
 
200
#if (!defined(UNIV_DEBUG) && !defined(UNIV_MUST_NOT_INLINE))
 
201
/* Definition for inline version */
 
202
 
 
203
#ifdef __WIN__
 
204
#define UNIV_INLINE     __inline
 
205
#else
 
206
#define UNIV_INLINE static __inline__
 
207
#endif
 
208
 
 
209
#else
 
210
/* If we want to compile a noninlined version we use the following macro
 
211
definitions: */
 
212
 
 
213
#define UNIV_NONINL
 
214
#define UNIV_INLINE     UNIV_INTERN
 
215
 
 
216
#endif  /* UNIV_DEBUG */
 
217
 
 
218
#ifdef _WIN32
 
219
#define UNIV_WORD_SIZE          4
 
220
#elif defined(_WIN64)
 
221
#define UNIV_WORD_SIZE          8
 
222
#else
 
223
/* MySQL config.h generated by GNU autoconf will define SIZEOF_LONG in Posix */
 
224
#define UNIV_WORD_SIZE          SIZEOF_LONG
 
225
#endif
 
226
 
 
227
/* The following alignment is used in memory allocations in memory heap
 
228
management to ensure correct alignment for doubles etc. */
 
229
#define UNIV_MEM_ALIGNMENT      8
 
230
 
 
231
/* The following alignment is used in aligning lints etc. */
 
232
#define UNIV_WORD_ALIGNMENT     UNIV_WORD_SIZE
 
233
 
 
234
/*
 
235
                        DATABASE VERSION CONTROL
 
236
                        ========================
 
237
*/
 
238
 
 
239
/* The 2-logarithm of UNIV_PAGE_SIZE: */
 
240
#define UNIV_PAGE_SIZE_SHIFT    14
 
241
/* The universal page size of the database */
 
242
#define UNIV_PAGE_SIZE          (1 << UNIV_PAGE_SIZE_SHIFT)
 
243
 
 
244
/* Maximum number of parallel threads in a parallelized operation */
 
245
#define UNIV_MAX_PARALLELISM    32
 
246
 
 
247
/*
 
248
                        UNIVERSAL TYPE DEFINITIONS
 
249
                        ==========================
 
250
*/
 
251
 
 
252
/* Note that inside MySQL 'byte' is defined as char on Linux! */
 
253
#define byte                    unsigned char
 
254
 
 
255
/* Define an unsigned integer type that is exactly 32 bits. */
 
256
 
 
257
#if SIZEOF_INT == 4
 
258
typedef unsigned int            ib_uint32_t;
 
259
#elif SIZEOF_LONG == 4
 
260
typedef unsigned long           ib_uint32_t;
 
261
#else
 
262
#error "Neither int or long is 4 bytes"
 
263
#endif
 
264
 
 
265
/* Another basic type we use is unsigned long integer which should be equal to
 
266
the word size of the machine, that is on a 32-bit platform 32 bits, and on a
 
267
64-bit platform 64 bits. We also give the printf format for the type as a
 
268
macro ULINTPF. */
 
269
 
 
270
#ifdef _WIN64
 
271
typedef unsigned __int64        ulint;
 
272
#define ULINTPF                 "%I64u"
 
273
typedef __int64                 lint;
 
274
#else
 
275
typedef unsigned long int       ulint;
 
276
#define ULINTPF                 "%lu"
 
277
typedef long int                lint;
 
278
#endif
 
279
 
 
280
#ifdef __WIN__
 
281
typedef __int64                 ib_int64_t;
 
282
typedef unsigned __int64        ib_uint64_t;
 
283
#else
 
284
/* Note: longlong and ulonglong come from MySQL headers. */
 
285
# if defined(BUILD_DRIZZLE)
 
286
typedef int64_t                 ib_int64_t;
 
287
typedef uint64_t                ib_uint64_t;
 
288
typedef uint16_t                uint16;
 
289
typedef bool                    my_bool;
 
290
typedef uint32_t                uint32;
 
291
# else
 
292
typedef longlong                ib_int64_t;
 
293
typedef ulonglong               ib_uint64_t;
 
294
#define PRIu64                  "llu"
 
295
# endif // DRIZZLE
 
296
#endif
 
297
 
 
298
typedef unsigned long long int  ullint;
 
299
 
 
300
#ifndef __WIN__
 
301
#if SIZEOF_LONG != SIZEOF_VOIDP
 
302
#error "Error: InnoDB's ulint must be of the same size as void*"
 
303
#endif
 
304
#endif
 
305
 
 
306
/* The 'undefined' value for a ulint */
 
307
#define ULINT_UNDEFINED         ((ulint)(-1))
 
308
 
 
309
/* The undefined 32-bit unsigned integer */
 
310
#define ULINT32_UNDEFINED       0xFFFFFFFF
 
311
 
 
312
/* Maximum value for a ulint */
 
313
#define ULINT_MAX               ((ulint)(-2))
 
314
 
 
315
/* Maximum value for ib_uint64_t */
 
316
#define IB_ULONGLONG_MAX        ((ib_uint64_t) (~0ULL))
 
317
 
 
318
/* This 'ibool' type is used within Innobase. Remember that different included
 
319
headers may define 'bool' differently. Do not assume that 'bool' is a ulint! */
 
320
#define ibool                   ulint
 
321
 
 
322
#ifndef TRUE
 
323
 
 
324
#define TRUE    1
 
325
#define FALSE   0
 
326
 
 
327
#endif
 
328
 
 
329
/* The following number as the length of a logical field means that the field
 
330
has the SQL NULL as its value. NOTE that because we assume that the length
 
331
of a field is a 32-bit integer when we store it, for example, to an undo log
 
332
on disk, we must have also this number fit in 32 bits, also in 64-bit
 
333
computers! */
 
334
 
 
335
#define UNIV_SQL_NULL ULINT32_UNDEFINED
 
336
 
 
337
/* Lengths which are not UNIV_SQL_NULL, but bigger than the following
 
338
number indicate that a field contains a reference to an externally
 
339
stored part of the field in the tablespace. The length field then
 
340
contains the sum of the following flag and the locally stored len. */
 
341
 
 
342
#define UNIV_EXTERN_STORAGE_FIELD (UNIV_SQL_NULL - UNIV_PAGE_SIZE)
 
343
 
 
344
/* Some macros to improve branch prediction and reduce cache misses */
 
345
#if defined(__GNUC__) && (__GNUC__ > 2) && ! defined(__INTEL_COMPILER)
 
346
/* Tell the compiler that 'expr' probably evaluates to 'constant'. */
 
347
# define UNIV_EXPECT(expr,constant) __builtin_expect(expr, constant)
 
348
/* Tell the compiler that a pointer is likely to be NULL */
 
349
# define UNIV_LIKELY_NULL(ptr) __builtin_expect((ulint) ptr, 0)
 
350
/* Minimize cache-miss latency by moving data at addr into a cache before
 
351
it is read. */
 
352
# define UNIV_PREFETCH_R(addr) __builtin_prefetch(addr, 0, 3)
 
353
/* Minimize cache-miss latency by moving data at addr into a cache before
 
354
it is read or written. */
 
355
# define UNIV_PREFETCH_RW(addr) __builtin_prefetch(addr, 1, 3)
 
356
#else
 
357
/* Dummy versions of the macros */
 
358
# define UNIV_EXPECT(expr,value) (expr)
 
359
# define UNIV_LIKELY_NULL(expr) (expr)
 
360
# define UNIV_PREFETCH_R(addr) ((void) 0)
 
361
# define UNIV_PREFETCH_RW(addr) ((void) 0)
 
362
#endif
 
363
/* Tell the compiler that cond is likely to hold */
 
364
#define UNIV_LIKELY(cond) UNIV_EXPECT(cond, TRUE)
 
365
/* Tell the compiler that cond is unlikely to hold */
 
366
#define UNIV_UNLIKELY(cond) UNIV_EXPECT(cond, FALSE)
 
367
 
 
368
/* Compile-time constant of the given array's size. */
 
369
#define UT_ARR_SIZE(a) (sizeof(a) / sizeof((a)[0]))
 
370
 
 
371
/* The return type from a thread's start function differs between Unix and
 
372
Windows, so define a typedef for it and a macro to use at the end of such
 
373
functions. */
 
374
 
 
375
#ifdef __WIN__
 
376
typedef ulint os_thread_ret_t;
 
377
#define OS_THREAD_DUMMY_RETURN return(0)
 
378
#else
 
379
typedef void* os_thread_ret_t;
 
380
#define OS_THREAD_DUMMY_RETURN return(NULL)
 
381
#endif
 
382
 
 
383
#include <stdio.h>
 
384
#include "ut0dbg.h"
 
385
#include "ut0ut.h"
 
386
#include "db0err.h"
 
387
#ifdef UNIV_DEBUG_VALGRIND
 
388
# include <valgrind/memcheck.h>
 
389
# define UNIV_MEM_VALID(addr, size) VALGRIND_MAKE_MEM_DEFINED(addr, size)
 
390
# define UNIV_MEM_INVALID(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size)
 
391
# define UNIV_MEM_FREE(addr, size) VALGRIND_MAKE_MEM_NOACCESS(addr, size)
 
392
# define UNIV_MEM_ALLOC(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size)
 
393
# define UNIV_MEM_DESC(addr, size, b) VALGRIND_CREATE_BLOCK(addr, size, b)
 
394
# define UNIV_MEM_UNDESC(b) VALGRIND_DISCARD(b)
 
395
# define UNIV_MEM_ASSERT_RW(addr, size) do {                            \
 
396
        const void* _p = (const void*) (ulint)                          \
 
397
                VALGRIND_CHECK_MEM_IS_DEFINED(addr, size);              \
 
398
        if (UNIV_LIKELY_NULL(_p))                                       \
 
399
                fprintf(stderr, "%s:%d: %p[%u] undefined at %ld\n",     \
 
400
                        __FILE__, __LINE__,                             \
 
401
                        (const void*) (addr), (unsigned) (size), (long) \
 
402
                        (((const char*) _p) - ((const char*) (addr)))); \
 
403
        } while (0)
 
404
# define UNIV_MEM_ASSERT_W(addr, size) do {                             \
 
405
        const void* _p = (const void*) (ulint)                          \
 
406
                VALGRIND_CHECK_MEM_IS_ADDRESSABLE(addr, size);          \
 
407
        if (UNIV_LIKELY_NULL(_p))                                       \
 
408
                fprintf(stderr, "%s:%d: %p[%u] unwritable at %ld\n",    \
 
409
                        __FILE__, __LINE__,                             \
 
410
                        (const void*) (addr), (unsigned) (size), (long) \
 
411
                        (((const char*) _p) - ((const char*) (addr)))); \
 
412
        } while (0)
 
413
#else
 
414
# define UNIV_MEM_VALID(addr, size) do {} while(0)
 
415
# define UNIV_MEM_INVALID(addr, size) do {} while(0)
 
416
# define UNIV_MEM_FREE(addr, size) do {} while(0)
 
417
# define UNIV_MEM_ALLOC(addr, size) do {} while(0)
 
418
# define UNIV_MEM_DESC(addr, size, b) do {} while(0)
 
419
# define UNIV_MEM_UNDESC(b) do {} while(0)
 
420
# define UNIV_MEM_ASSERT_RW(addr, size) do {} while(0)
 
421
# define UNIV_MEM_ASSERT_W(addr, size) do {} while(0)
 
422
#endif
 
423
#define UNIV_MEM_ASSERT_AND_FREE(addr, size) do {       \
 
424
        UNIV_MEM_ASSERT_W(addr, size);                  \
 
425
        UNIV_MEM_FREE(addr, size);                      \
 
426
} while (0)
 
427
#define UNIV_MEM_ASSERT_AND_ALLOC(addr, size) do {      \
 
428
        UNIV_MEM_ASSERT_W(addr, size);                  \
 
429
        UNIV_MEM_ALLOC(addr, size);                     \
 
430
} while (0)
 
431
 
 
432
#endif