1
/***************************************************************************
2
Version control for database, common definitions, and include files
4
(c) 1994 - 2000 Innobase Oy
6
Created 1/20/1994 Heikki Tuuri
7
****************************************************************************/
12
#if (defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)) && !defined(MYSQL_SERVER) && !defined(__WIN__)
18
# if !defined(WIN64) && !defined(_WIN64)
19
# define UNIV_CAN_USE_X86_ASSEMBLER
27
/* The defines used with MySQL */
29
/* Include two header files from MySQL to make the Unix flavor used
30
in compiling more Posix-compatible. These headers also define __WIN__
31
if we are compiling on Windows. */
33
# include <my_global.h>
34
# include <my_pthread.h>
36
/* Include <sys/stat.h> to get S_I... macros defined for os0file.c */
37
# include <sys/stat.h>
42
/* Include the header file generated by GNU autoconf */
51
/* When compiling for Itanium IA64, undefine the flag below to prevent use
52
of the 32-bit x86 assembler in mutex operations. */
54
# if defined(__WIN__) && !defined(WIN64) && !defined(_WIN64)
55
# define UNIV_CAN_USE_X86_ASSEMBLER
58
/* We only try to do explicit inlining of functions with gcc and
59
Microsoft Visual C++ */
61
# if !defined(__GNUC__)
62
# undef UNIV_MUST_NOT_INLINE /* Remove compiler warning */
63
# define UNIV_MUST_NOT_INLINE
70
#endif /* #if (defined(WIN32) || ... */
72
/* DEBUG VERSION CONTROL
73
===================== */
75
/* The following flag will make InnoDB to initialize
76
all memory it allocates to zero. It hides Purify
77
warnings about reading unallocated memory unless
78
memory is read outside the allocated blocks. */
80
#define UNIV_INIT_MEM_TO_ZERO
83
/* Make a non-inline debug version */
86
#define UNIV_DEBUG_VALGRIND /* Enable extra
87
Valgrind instrumentation */
88
#define UNIV_DEBUG /* Enable ut_ad() assertions */
89
#define UNIV_LIST_DEBUG /* debug UT_LIST_ macros */
90
#define UNIV_MEM_DEBUG /* detect memory leaks etc */
91
#define UNIV_IBUF_DEBUG /* debug the insert buffer;
92
this limits the database to IBUF_COUNT_N_SPACES and IBUF_COUNT_N_PAGES,
93
and the insert buffer must be empty when the database is started */
94
#define UNIV_SYNC_DEBUG /* debug mutex and latch
95
operations (very slow); also UNIV_DEBUG must be defined */
96
#define UNIV_SEARCH_DEBUG /* debug B-tree comparisons */
97
#define UNIV_SYNC_PERF_STAT /* operation counts for
98
rw-locks and mutexes */
99
#define UNIV_SEARCH_PERF_STAT /* statistics for the
100
adaptive hash index */
101
#define UNIV_SRV_PRINT_LATCH_WAITS /* enable diagnostic output
103
#define UNIV_BTR_PRINT /* enable functions for
107
#define UNIV_BTR_DEBUG /* check B-tree links */
108
#define UNIV_LIGHT_MEM_DEBUG /* light memory debugging */
111
/* The following sets all new allocated memory to zero before use:
112
this can be used to eliminate unnecessary Purify warnings, but note that
113
it also masks many bugs Purify could detect. For detailed Purify analysis it
114
is best to remove the define below and look through the warnings one
116
#define UNIV_SET_MEM_TO_ZERO
120
#define UNIV_SQL_DEBUG
121
#define UNIV_LOG_DEBUG
123
/* the above option prevents forcing of log to disk
124
at a buffer page write: it should be tested with this
125
option off; also some ibuf tests are suppressed */
127
#define UNIV_BASIC_LOG_DEBUG
129
/* the above option enables basic recovery debugging:
130
new allocated file pages are reset */
132
#if (!defined(UNIV_DEBUG) && !defined(INSIDE_HA_INNOBASE_CC) && !defined(UNIV_MUST_NOT_INLINE))
133
/* Definition for inline version */
136
#define UNIV_INLINE __inline
138
#define UNIV_INLINE static __inline__
142
/* If we want to compile a noninlined version we use the following macro
148
#endif /* UNIV_DEBUG */
151
#define UNIV_WORD_SIZE 4
152
#elif defined(_WIN64)
153
#define UNIV_WORD_SIZE 8
155
/* MySQL config.h generated by GNU autoconf will define SIZEOF_LONG in Posix */
156
#define UNIV_WORD_SIZE SIZEOF_LONG
159
/* The following alignment is used in memory allocations in memory heap
160
management to ensure correct alignment for doubles etc. */
161
#define UNIV_MEM_ALIGNMENT 8
163
/* The following alignment is used in aligning lints etc. */
164
#define UNIV_WORD_ALIGNMENT UNIV_WORD_SIZE
167
DATABASE VERSION CONTROL
168
========================
171
/* The universal page size of the database */
172
#define UNIV_PAGE_SIZE (2 * 8192) /* NOTE! Currently, this has to be a
174
/* The 2-logarithm of UNIV_PAGE_SIZE: */
175
#define UNIV_PAGE_SIZE_SHIFT 14
177
/* Maximum number of parallel threads in a parallelized operation */
178
#define UNIV_MAX_PARALLELISM 32
181
UNIVERSAL TYPE DEFINITIONS
182
==========================
185
/* Note that inside MySQL 'byte' is defined as char on Linux! */
186
#define byte unsigned char
188
/* Define an unsigned integer type that is exactly 32 bits. */
191
typedef unsigned int ib_uint32_t;
192
#elif SIZEOF_LONG == 4
193
typedef unsigned long ib_uint32_t;
195
#error "Neither int or long is 4 bytes"
198
/* Another basic type we use is unsigned long integer which should be equal to
199
the word size of the machine, that is on a 32-bit platform 32 bits, and on a
200
64-bit platform 64 bits. We also give the printf format for the type as a
204
typedef unsigned __int64 ulint;
205
#define ULINTPF "%I64u"
206
typedef __int64 lint;
208
typedef unsigned long int ulint;
209
#define ULINTPF "%lu"
210
typedef long int lint;
214
typedef __int64 ib_longlong;
216
typedef longlong ib_longlong;
219
typedef unsigned long long int ullint;
222
#if SIZEOF_LONG != SIZEOF_VOIDP
223
#error "Error: InnoDB's ulint must be of the same size as void*"
227
/* The 'undefined' value for a ulint */
228
#define ULINT_UNDEFINED ((ulint)(-1))
230
/* The undefined 32-bit unsigned integer */
231
#define ULINT32_UNDEFINED 0xFFFFFFFF
233
/* Maximum value for a ulint */
234
#define ULINT_MAX ((ulint)(-2))
236
/* This 'ibool' type is used within Innobase. Remember that different included
237
headers may define 'bool' differently. Do not assume that 'bool' is a ulint! */
247
/* The following number as the length of a logical field means that the field
248
has the SQL NULL as its value. NOTE that because we assume that the length
249
of a field is a 32-bit integer when we store it, for example, to an undo log
250
on disk, we must have also this number fit in 32 bits, also in 64-bit
253
#define UNIV_SQL_NULL ULINT32_UNDEFINED
255
/* Lengths which are not UNIV_SQL_NULL, but bigger than the following
256
number indicate that a field contains a reference to an externally
257
stored part of the field in the tablespace. The length field then
258
contains the sum of the following flag and the locally stored len. */
260
#define UNIV_EXTERN_STORAGE_FIELD (UNIV_SQL_NULL - UNIV_PAGE_SIZE)
262
/* Some macros to improve branch prediction and reduce cache misses */
263
#if defined(__GNUC__) && (__GNUC__ > 2) && ! defined(__INTEL_COMPILER)
264
/* Tell the compiler that 'expr' probably evaluates to 'constant'. */
265
# define UNIV_EXPECT(expr,constant) __builtin_expect(expr, constant)
266
/* Tell the compiler that a pointer is likely to be NULL */
267
# define UNIV_LIKELY_NULL(ptr) __builtin_expect((ulint) ptr, 0)
268
/* Minimize cache-miss latency by moving data at addr into a cache before
270
# define UNIV_PREFETCH_R(addr) __builtin_prefetch(addr, 0, 3)
271
/* Minimize cache-miss latency by moving data at addr into a cache before
272
it is read or written. */
273
# define UNIV_PREFETCH_RW(addr) __builtin_prefetch(addr, 1, 3)
275
/* Dummy versions of the macros */
276
# define UNIV_EXPECT(expr,value) (expr)
277
# define UNIV_LIKELY_NULL(expr) (expr)
278
# define UNIV_PREFETCH_R(addr) ((void) 0)
279
# define UNIV_PREFETCH_RW(addr) ((void) 0)
281
/* Tell the compiler that cond is likely to hold */
282
#define UNIV_LIKELY(cond) UNIV_EXPECT(cond, TRUE)
283
/* Tell the compiler that cond is unlikely to hold */
284
#define UNIV_UNLIKELY(cond) UNIV_EXPECT(cond, FALSE)
286
/* Compile-time constant of the given array's size. */
287
#define UT_ARR_SIZE(a) (sizeof(a) / sizeof((a)[0]))
289
/* The return type from a thread's start function differs between Unix and
290
Windows, so define a typedef for it and a macro to use at the end of such
294
typedef ulint os_thread_ret_t;
295
#define OS_THREAD_DUMMY_RETURN return(0)
297
typedef void* os_thread_ret_t;
298
#define OS_THREAD_DUMMY_RETURN return(NULL)
305
#ifdef UNIV_DEBUG_VALGRIND
306
# include <valgrind/memcheck.h>
307
# define UNIV_MEM_VALID(addr, size) VALGRIND_MAKE_MEM_DEFINED(addr, size)
308
# define UNIV_MEM_INVALID(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size)
309
# define UNIV_MEM_FREE(addr, size) VALGRIND_MAKE_MEM_NOACCESS(addr, size)
310
# define UNIV_MEM_ALLOC(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size)
311
# define UNIV_MEM_ASSERT_RW(addr, size) do { \
312
const void* _p = (const void*) (ulint) \
313
VALGRIND_CHECK_MEM_IS_DEFINED(addr, size); \
314
if (UNIV_LIKELY_NULL(_p)) \
315
fprintf(stderr, "%s:%d: %p[%u] undefined at %ld\n", \
316
__FILE__, __LINE__, \
317
(const void*) (addr), (unsigned) (size), (long) \
318
(((const char*) _p) - ((const char*) (addr)))); \
320
# define UNIV_MEM_ASSERT_W(addr, size) do { \
321
const void* _p = (const void*) (ulint) \
322
VALGRIND_CHECK_MEM_IS_ADDRESSABLE(addr, size); \
323
if (UNIV_LIKELY_NULL(_p)) \
324
fprintf(stderr, "%s:%d: %p[%u] unwritable at %ld\n", \
325
__FILE__, __LINE__, \
326
(const void*) (addr), (unsigned) (size), (long) \
327
(((const char*) _p) - ((const char*) (addr)))); \
330
# define UNIV_MEM_VALID(addr, size) do {} while(0)
331
# define UNIV_MEM_INVALID(addr, size) do {} while(0)
332
# define UNIV_MEM_FREE(addr, size) do {} while(0)
333
# define UNIV_MEM_ALLOC(addr, size) do {} while(0)
334
# define UNIV_MEM_ASSERT_RW(addr, size) do {} while(0)
335
# define UNIV_MEM_ASSERT_W(addr, size) do {} while(0)
337
#define UNIV_MEM_ASSERT_AND_FREE(addr, size) do { \
338
UNIV_MEM_ASSERT_W(addr, size); \
339
UNIV_MEM_FREE(addr, size); \
341
#define UNIV_MEM_ASSERT_AND_ALLOC(addr, size) do { \
342
UNIV_MEM_ASSERT_W(addr, size); \
343
UNIV_MEM_ALLOC(addr, size); \