mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / innobase / include / univ.i
blob804f0e356059cb00f7602293b0dfcd3b2c2d18f4
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 ****************************************************************************/
9 #ifndef univ_i
10 #define univ_i
12 #if (defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)) && !defined(MYSQL_SERVER) && !defined(__WIN__)
13 # undef __WIN__
14 # define __WIN__
16 # include <windows.h>
18 # if !defined(WIN64) && !defined(_WIN64)
19 # define UNIV_CAN_USE_X86_ASSEMBLER
20 # endif
22 # ifdef _NT_
23 # define __NT__
24 # endif
26 #else
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>
39 # undef PACKAGE
40 # undef VERSION
42 /* Include the header file generated by GNU autoconf */
43 # ifndef __WIN__
44 # include "config.h"
45 # endif
47 # ifdef HAVE_SCHED_H
48 # include <sched.h>
49 # endif
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
56 # endif
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
64 # endif
66 # ifdef HAVE_PREAD
67 # define HAVE_PWRITE
68 # endif
70 #endif /* #if (defined(WIN32) || ... */
72 /* DEBUG VERSION CONTROL
73 ===================== */
75 /* Make a non-inline debug version */
77 #if defined HAVE_VALGRIND
78 # define UNIV_DEBUG_VALGRIND
79 #endif /* HAVE_VALGRIND */
80 #if 0
81 #define UNIV_DEBUG_VALGRIND /* Enable extra
82 Valgrind instrumentation */
83 #define UNIV_BLOB_LIGHT_DEBUG /* Enable off-page column
84 debugging without UNIV_DEBUG */
85 #define UNIV_DEBUG /* Enable ut_ad() assertions */
86 #define UNIV_LIST_DEBUG /* debug UT_LIST_ macros */
87 #define UNIV_MEM_DEBUG /* detect memory leaks etc */
88 #define UNIV_IBUF_DEBUG /* debug the insert buffer;
89 this limits the database to IBUF_COUNT_N_SPACES and IBUF_COUNT_N_PAGES,
90 and the insert buffer must be empty when the database is started */
91 #define UNIV_SYNC_DEBUG /* debug mutex and latch
92 operations (very slow); also UNIV_DEBUG must be defined */
93 #define UNIV_SEARCH_DEBUG /* debug B-tree comparisons */
94 #define UNIV_SYNC_PERF_STAT /* operation counts for
95 rw-locks and mutexes */
96 #define UNIV_SEARCH_PERF_STAT /* statistics for the
97 adaptive hash index */
98 #define UNIV_SRV_PRINT_LATCH_WAITS /* enable diagnostic output
99 in sync0sync.c */
100 #define UNIV_BTR_PRINT /* enable functions for
101 printing B-trees */
102 #endif
104 #define UNIV_BTR_DEBUG /* check B-tree links */
105 #define UNIV_LIGHT_MEM_DEBUG /* light memory debugging */
108 #define UNIV_SQL_DEBUG
109 #define UNIV_LOG_DEBUG
111 /* the above option prevents forcing of log to disk
112 at a buffer page write: it should be tested with this
113 option off; also some ibuf tests are suppressed */
115 #if (!defined(UNIV_DEBUG) && !defined(INSIDE_HA_INNOBASE_CC) && !defined(UNIV_MUST_NOT_INLINE))
116 /* Definition for inline version */
118 #ifdef __WIN__
119 #define UNIV_INLINE __inline
120 #else
121 #define UNIV_INLINE static __inline__
122 #endif
124 #else
125 /* If we want to compile a noninlined version we use the following macro
126 definitions: */
128 #define UNIV_NONINL
129 #define UNIV_INLINE
131 #endif /* UNIV_DEBUG */
133 #ifdef _WIN32
134 #define UNIV_WORD_SIZE 4
135 #elif defined(_WIN64)
136 #define UNIV_WORD_SIZE 8
137 #else
138 /* MySQL config.h generated by GNU autoconf will define SIZEOF_LONG in Posix */
139 #define UNIV_WORD_SIZE SIZEOF_LONG
140 #endif
142 /* The following alignment is used in memory allocations in memory heap
143 management to ensure correct alignment for doubles etc. */
144 #define UNIV_MEM_ALIGNMENT 8
146 /* The following alignment is used in aligning lints etc. */
147 #define UNIV_WORD_ALIGNMENT UNIV_WORD_SIZE
150 DATABASE VERSION CONTROL
151 ========================
154 /* The universal page size of the database */
155 #define UNIV_PAGE_SIZE (2 * 8192) /* NOTE! Currently, this has to be a
156 power of 2 */
157 /* The 2-logarithm of UNIV_PAGE_SIZE: */
158 #define UNIV_PAGE_SIZE_SHIFT 14
160 /* Maximum number of parallel threads in a parallelized operation */
161 #define UNIV_MAX_PARALLELISM 32
163 /** The maximum length of a table name. This is the MySQL limit and is
164 defined in mysql_com.h like NAME_CHAR_LEN*SYSTEM_CHARSET_MBMAXLEN, the
165 number does not include a terminating '\0'. InnoDB probably can handle
166 longer names internally */
167 #define MAX_TABLE_NAME_LEN 192
169 /** The maximum length of a database name. Like MAX_TABLE_NAME_LEN this is
170 the MySQL's NAME_LEN, see check_and_convert_db_name(). */
171 #define MAX_DATABASE_NAME_LEN MAX_TABLE_NAME_LEN
173 /** MAX_FULL_NAME_LEN defines the full name path including the
174 database name and table name. In addition, 14 bytes is added for:
175 2 for surrounding quotes around table name
176 1 for the separating dot (.)
177 9 for the #mysql50# prefix */
178 #define MAX_FULL_NAME_LEN \
179 (MAX_TABLE_NAME_LEN + MAX_DATABASE_NAME_LEN + 14)
182 UNIVERSAL TYPE DEFINITIONS
183 ==========================
186 /* Note that inside MySQL 'byte' is defined as char on Linux! */
187 #define byte unsigned char
189 /* Define an unsigned integer type that is exactly 32 bits. */
191 #if SIZEOF_INT == 4
192 typedef unsigned int ib_uint32_t;
193 #elif SIZEOF_LONG == 4
194 typedef unsigned long ib_uint32_t;
195 #else
196 #error "Neither int or long is 4 bytes"
197 #endif
199 /* Another basic type we use is unsigned long integer which should be equal to
200 the word size of the machine, that is on a 32-bit platform 32 bits, and on a
201 64-bit platform 64 bits. We also give the printf format for the type as a
202 macro ULINTPF. */
204 #ifdef _WIN64
205 typedef unsigned __int64 ulint;
206 #define ULINTPF "%I64u"
207 typedef __int64 lint;
208 #else
209 typedef unsigned long int ulint;
210 #define ULINTPF "%lu"
211 typedef long int lint;
212 #endif
214 #ifdef __WIN__
215 typedef __int64 ib_longlong;
216 typedef unsigned __int64 ib_ulonglong;
217 #else
218 /* Note: longlong and ulonglong come from MySQL headers. */
219 typedef longlong ib_longlong;
220 typedef ulonglong ib_ulonglong;
221 #endif
223 typedef unsigned long long int ullint;
225 #ifndef __WIN__
226 #if SIZEOF_LONG != SIZEOF_VOIDP
227 #error "Error: InnoDB's ulint must be of the same size as void*"
228 #endif
229 #endif
231 /* The 'undefined' value for a ulint */
232 #define ULINT_UNDEFINED ((ulint)(-1))
234 /* The undefined 32-bit unsigned integer */
235 #define ULINT32_UNDEFINED 0xFFFFFFFF
237 /* Maximum value for a ulint */
238 #define ULINT_MAX ((ulint)(-2))
240 /* THe 'undefined' value for ullint */
241 #define ULLINT_UNDEFINED ((ullint)(-1))
243 /* Maximum value for a ullint */
244 #define ULLINT_MAX ((ullint)(-2))
246 /* This 'ibool' type is used within Innobase. Remember that different included
247 headers may define 'bool' differently. Do not assume that 'bool' is a ulint! */
248 #define ibool ulint
250 #ifndef TRUE
252 #define TRUE 1
253 #define FALSE 0
255 #endif
257 /* The following number as the length of a logical field means that the field
258 has the SQL NULL as its value. NOTE that because we assume that the length
259 of a field is a 32-bit integer when we store it, for example, to an undo log
260 on disk, we must have also this number fit in 32 bits, also in 64-bit
261 computers! */
263 #define UNIV_SQL_NULL ULINT32_UNDEFINED
265 /* Lengths which are not UNIV_SQL_NULL, but bigger than the following
266 number indicate that a field contains a reference to an externally
267 stored part of the field in the tablespace. The length field then
268 contains the sum of the following flag and the locally stored len. */
270 #define UNIV_EXTERN_STORAGE_FIELD (UNIV_SQL_NULL - UNIV_PAGE_SIZE)
272 /* Some macros to improve branch prediction and reduce cache misses */
273 #if defined(__GNUC__) && (__GNUC__ > 2) && ! defined(__INTEL_COMPILER)
274 /* Tell the compiler that 'expr' probably evaluates to 'constant'. */
275 # define UNIV_EXPECT(expr,constant) __builtin_expect(expr, constant)
276 /* Tell the compiler that a pointer is likely to be NULL */
277 # define UNIV_LIKELY_NULL(ptr) __builtin_expect((ulint) ptr, 0)
278 /* Minimize cache-miss latency by moving data at addr into a cache before
279 it is read. */
280 # define UNIV_PREFETCH_R(addr) __builtin_prefetch(addr, 0, 3)
281 /* Minimize cache-miss latency by moving data at addr into a cache before
282 it is read or written. */
283 # define UNIV_PREFETCH_RW(addr) __builtin_prefetch(addr, 1, 3)
284 #else
285 /* Dummy versions of the macros */
286 # define UNIV_EXPECT(expr,value) (expr)
287 # define UNIV_LIKELY_NULL(expr) (expr)
288 # define UNIV_PREFETCH_R(addr) ((void) 0)
289 # define UNIV_PREFETCH_RW(addr) ((void) 0)
290 #endif
291 /* Tell the compiler that cond is likely to hold */
292 #define UNIV_LIKELY(cond) UNIV_EXPECT(cond, TRUE)
293 /* Tell the compiler that cond is unlikely to hold */
294 #define UNIV_UNLIKELY(cond) UNIV_EXPECT(cond, FALSE)
296 /* Compile-time constant of the given array's size. */
297 #define UT_ARR_SIZE(a) (sizeof(a) / sizeof((a)[0]))
299 /* The return type from a thread's start function differs between Unix and
300 Windows, so define a typedef for it and a macro to use at the end of such
301 functions. */
303 #ifdef __WIN__
304 typedef ulint os_thread_ret_t;
305 #define OS_THREAD_DUMMY_RETURN return(0)
306 #else
307 typedef void* os_thread_ret_t;
308 #define OS_THREAD_DUMMY_RETURN return(NULL)
309 #endif
311 #include <stdio.h>
312 #include "ut0dbg.h"
313 #include "ut0ut.h"
314 #include "db0err.h"
315 #ifdef UNIV_DEBUG_VALGRIND
316 # include <valgrind/memcheck.h>
317 # define UNIV_MEM_VALID(addr, size) VALGRIND_MAKE_MEM_DEFINED(addr, size)
318 # define UNIV_MEM_INVALID(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size)
319 # define UNIV_MEM_FREE(addr, size) VALGRIND_MAKE_MEM_NOACCESS(addr, size)
320 # define UNIV_MEM_ALLOC(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size)
321 # define UNIV_MEM_ASSERT_RW(addr, size) do { \
322 const void* _p = (const void*) (ulint) \
323 VALGRIND_CHECK_MEM_IS_DEFINED(addr, size); \
324 if (UNIV_LIKELY_NULL(_p)) \
325 fprintf(stderr, "%s:%d: %p[%u] undefined at %ld\n", \
326 __FILE__, __LINE__, \
327 (const void*) (addr), (unsigned) (size), (long) \
328 (((const char*) _p) - ((const char*) (addr)))); \
329 } while (0)
330 # define UNIV_MEM_ASSERT_W(addr, size) do { \
331 const void* _p = (const void*) (ulint) \
332 VALGRIND_CHECK_MEM_IS_ADDRESSABLE(addr, size); \
333 if (UNIV_LIKELY_NULL(_p)) \
334 fprintf(stderr, "%s:%d: %p[%u] unwritable at %ld\n", \
335 __FILE__, __LINE__, \
336 (const void*) (addr), (unsigned) (size), (long) \
337 (((const char*) _p) - ((const char*) (addr)))); \
338 } while (0)
339 #else
340 # define UNIV_MEM_VALID(addr, size) do {} while(0)
341 # define UNIV_MEM_INVALID(addr, size) do {} while(0)
342 # define UNIV_MEM_FREE(addr, size) do {} while(0)
343 # define UNIV_MEM_ALLOC(addr, size) do {} while(0)
344 # define UNIV_MEM_ASSERT_RW(addr, size) do {} while(0)
345 # define UNIV_MEM_ASSERT_W(addr, size) do {} while(0)
346 #endif
347 #define UNIV_MEM_ASSERT_AND_FREE(addr, size) do { \
348 UNIV_MEM_ASSERT_W(addr, size); \
349 UNIV_MEM_FREE(addr, size); \
350 } while (0)
351 #define UNIV_MEM_ASSERT_AND_ALLOC(addr, size) do { \
352 UNIV_MEM_ASSERT_W(addr, size); \
353 UNIV_MEM_ALLOC(addr, size); \
354 } while (0)
356 #endif