1
by brian
clean slate |
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 |
#if (defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)) && !defined(MYSQL_SERVER) && !defined(__WIN__)
|
|
13 |
# undef __WIN__
|
|
14 |
# define __WIN__
|
|
15 |
||
16 |
# include <windows.h>
|
|
17 |
||
18 |
# if !defined(WIN64) && !defined(_WIN64)
|
|
19 |
# define UNIV_CAN_USE_X86_ASSEMBLER
|
|
20 |
# endif
|
|
21 |
||
22 |
# ifdef _NT_
|
|
23 |
# define __NT__
|
|
24 |
# endif
|
|
25 |
||
26 |
#else
|
|
27 |
/* The defines used with MySQL */
|
|
28 |
||
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. */
|
|
32 |
||
33 |
# include <my_global.h>
|
|
34 |
# include <my_pthread.h>
|
|
35 |
||
36 |
/* Include <sys/stat.h> to get S_I... macros defined for os0file.c */
|
|
37 |
# include <sys/stat.h>
|
|
38 |
||
39 |
# undef PACKAGE
|
|
40 |
# undef VERSION
|
|
41 |
||
42 |
/* Include the header file generated by GNU autoconf */
|
|
43 |
# ifndef __WIN__
|
|
44 |
# include "config.h"
|
|
45 |
# endif
|
|
46 |
||
47 |
# ifdef HAVE_SCHED_H
|
|
48 |
# include <sched.h>
|
|
49 |
# endif
|
|
50 |
||
51 |
/* When compiling for Itanium IA64, undefine the flag below to prevent use
|
|
52 |
of the 32-bit x86 assembler in mutex operations. */
|
|
53 |
||
54 |
# if defined(__WIN__) && !defined(WIN64) && !defined(_WIN64)
|
|
55 |
# define UNIV_CAN_USE_X86_ASSEMBLER
|
|
56 |
# endif
|
|
57 |
||
58 |
/* We only try to do explicit inlining of functions with gcc and
|
|
59 |
Microsoft Visual C++ */
|
|
60 |
||
61 |
# if !defined(__GNUC__)
|
|
62 |
# undef UNIV_MUST_NOT_INLINE /* Remove compiler warning */ |
|
63 |
# define UNIV_MUST_NOT_INLINE
|
|
64 |
# endif
|
|
65 |
||
66 |
# ifdef HAVE_PREAD
|
|
67 |
# define HAVE_PWRITE
|
|
68 |
# endif
|
|
69 |
||
70 |
#endif /* #if (defined(WIN32) || ... */ |
|
71 |
||
72 |
/* DEBUG VERSION CONTROL
|
|
73 |
===================== */
|
|
74 |
||
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. */
|
|
79 |
/*
|
|
80 |
#define UNIV_INIT_MEM_TO_ZERO
|
|
81 |
*/
|
|
82 |
||
83 |
/* Make a non-inline debug version */
|
|
84 |
||
85 |
#if 0
|
|
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
|
|
102 |
in sync0sync.c */
|
|
103 |
#define UNIV_BTR_PRINT /* enable functions for
|
|
104 |
printing B-trees */
|
|
105 |
#endif
|
|
106 |
||
107 |
#define UNIV_BTR_DEBUG /* check B-tree links */ |
|
108 |
#define UNIV_LIGHT_MEM_DEBUG /* light memory debugging */ |
|
109 |
||
110 |
#ifdef HAVE_purify
|
|
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
|
|
115 |
by one. */
|
|
116 |
#define UNIV_SET_MEM_TO_ZERO
|
|
117 |
#endif
|
|
118 |
||
119 |
/*
|
|
120 |
#define UNIV_SQL_DEBUG
|
|
121 |
#define UNIV_LOG_DEBUG
|
|
122 |
*/
|
|
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 */
|
|
126 |
/*
|
|
127 |
#define UNIV_BASIC_LOG_DEBUG
|
|
128 |
*/
|
|
129 |
/* the above option enables basic recovery debugging:
|
|
130 |
new allocated file pages are reset */
|
|
131 |
||
132 |
#if (!defined(UNIV_DEBUG) && !defined(INSIDE_HA_INNOBASE_CC) && !defined(UNIV_MUST_NOT_INLINE))
|
|
133 |
/* Definition for inline version */
|
|
134 |
||
135 |
#ifdef __WIN__
|
|
136 |
#define UNIV_INLINE __inline
|
|
137 |
#else
|
|
138 |
#define UNIV_INLINE static __inline__
|
|
139 |
#endif
|
|
140 |
||
141 |
#else
|
|
142 |
/* If we want to compile a noninlined version we use the following macro
|
|
143 |
definitions: */
|
|
144 |
||
145 |
#define UNIV_NONINL
|
|
146 |
#define UNIV_INLINE
|
|
147 |
||
148 |
#endif /* UNIV_DEBUG */ |
|
149 |
||
150 |
#ifdef _WIN32
|
|
151 |
#define UNIV_WORD_SIZE 4
|
|
152 |
#elif defined(_WIN64)
|
|
153 |
#define UNIV_WORD_SIZE 8
|
|
154 |
#else
|
|
155 |
/* MySQL config.h generated by GNU autoconf will define SIZEOF_LONG in Posix */
|
|
156 |
#define UNIV_WORD_SIZE SIZEOF_LONG
|
|
157 |
#endif
|
|
158 |
||
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
|
|
162 |
||
163 |
/* The following alignment is used in aligning lints etc. */
|
|
164 |
#define UNIV_WORD_ALIGNMENT UNIV_WORD_SIZE
|
|
165 |
||
166 |
/*
|
|
167 |
DATABASE VERSION CONTROL
|
|
168 |
========================
|
|
169 |
*/
|
|
170 |
||
171 |
/* The universal page size of the database */
|
|
172 |
#define UNIV_PAGE_SIZE (2 * 8192) /* NOTE! Currently, this has to be a |
|
173 |
power of 2 */
|
|
174 |
/* The 2-logarithm of UNIV_PAGE_SIZE: */
|
|
175 |
#define UNIV_PAGE_SIZE_SHIFT 14
|
|
176 |
||
177 |
/* Maximum number of parallel threads in a parallelized operation */
|
|
178 |
#define UNIV_MAX_PARALLELISM 32
|
|
179 |
||
180 |
/*
|
|
181 |
UNIVERSAL TYPE DEFINITIONS
|
|
182 |
==========================
|
|
183 |
*/
|
|
184 |
||
185 |
/* Note that inside MySQL 'byte' is defined as char on Linux! */
|
|
186 |
#define byte unsigned char
|
|
187 |
||
188 |
/* Define an unsigned integer type that is exactly 32 bits. */
|
|
189 |
||
190 |
#if SIZEOF_INT == 4
|
|
191 |
typedef unsigned int ib_uint32_t; |
|
192 |
#elif SIZEOF_LONG == 4
|
|
193 |
typedef unsigned long ib_uint32_t; |
|
194 |
#else
|
|
195 |
#error "Neither int or long is 4 bytes"
|
|
196 |
#endif
|
|
197 |
||
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
|
|
201 |
macro ULINTPF. */
|
|
202 |
||
203 |
#ifdef _WIN64
|
|
204 |
typedef unsigned __int64 ulint; |
|
205 |
#define ULINTPF "%I64u"
|
|
206 |
typedef __int64 lint; |
|
207 |
#else
|
|
208 |
typedef unsigned long int ulint; |
|
209 |
#define ULINTPF "%lu"
|
|
210 |
typedef long int lint; |
|
211 |
#endif
|
|
212 |
||
213 |
#ifdef __WIN__
|
|
214 |
typedef __int64 ib_longlong; |
|
215 |
#else
|
|
216 |
typedef longlong ib_longlong; |
|
217 |
#endif
|
|
218 |
||
219 |
typedef unsigned long long int ullint; |
|
220 |
||
221 |
#ifndef __WIN__
|
|
222 |
#if SIZEOF_LONG != SIZEOF_VOIDP
|
|
223 |
#error "Error: InnoDB's ulint must be of the same size as void*"
|
|
224 |
#endif
|
|
225 |
#endif
|
|
226 |
||
227 |
/* The 'undefined' value for a ulint */
|
|
228 |
#define ULINT_UNDEFINED ((ulint)(-1))
|
|
229 |
||
230 |
/* The undefined 32-bit unsigned integer */
|
|
231 |
#define ULINT32_UNDEFINED 0xFFFFFFFF
|
|
232 |
||
233 |
/* Maximum value for a ulint */
|
|
234 |
#define ULINT_MAX ((ulint)(-2))
|
|
235 |
||
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! */
|
|
238 |
#define ibool ulint
|
|
239 |
||
240 |
#ifndef TRUE
|
|
241 |
||
242 |
#define TRUE 1
|
|
243 |
#define FALSE 0
|
|
244 |
||
245 |
#endif
|
|
246 |
||
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
|
|
251 |
computers! */
|
|
252 |
||
253 |
#define UNIV_SQL_NULL ULINT32_UNDEFINED
|
|
254 |
||
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. */
|
|
259 |
||
260 |
#define UNIV_EXTERN_STORAGE_FIELD (UNIV_SQL_NULL - UNIV_PAGE_SIZE)
|
|
261 |
||
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
|
|
269 |
it is read. */
|
|
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)
|
|
274 |
#else
|
|
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)
|
|
280 |
#endif
|
|
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)
|
|
285 |
||
286 |
/* Compile-time constant of the given array's size. */
|
|
287 |
#define UT_ARR_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
|
288 |
||
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
|
|
291 |
functions. */
|
|
292 |
||
293 |
#ifdef __WIN__
|
|
294 |
typedef ulint os_thread_ret_t; |
|
295 |
#define OS_THREAD_DUMMY_RETURN return(0)
|
|
296 |
#else
|
|
297 |
typedef void* os_thread_ret_t; |
|
298 |
#define OS_THREAD_DUMMY_RETURN return(NULL)
|
|
299 |
#endif
|
|
300 |
||
301 |
#include <stdio.h> |
|
302 |
#include "ut0dbg.h" |
|
303 |
#include "ut0ut.h" |
|
304 |
#include "db0err.h" |
|
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)))); \
|
|
319 |
} while (0)
|
|
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)))); \
|
|
328 |
} while (0)
|
|
329 |
#else
|
|
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)
|
|
336 |
#endif
|
|
337 |
#define UNIV_MEM_ASSERT_AND_FREE(addr, size) do { \
|
|
338 |
UNIV_MEM_ASSERT_W(addr, size); \
|
|
339 |
UNIV_MEM_FREE(addr, size); \
|
|
340 |
} while (0)
|
|
341 |
#define UNIV_MEM_ASSERT_AND_ALLOC(addr, size) do { \
|
|
342 |
UNIV_MEM_ASSERT_W(addr, size); \
|
|
343 |
UNIV_MEM_ALLOC(addr, size); \
|
|
344 |
} while (0)
|
|
345 |
||
346 |
#endif
|