~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/global.h

  • Committer: Stewart Smith
  • Date: 2009-03-11 06:37:19 UTC
  • mto: (910.4.19 sparc) (937.2.1 sparc)
  • mto: This revision was merged to the branch mainline in revision 931.
  • Revision ID: stewart@flamingspork.com-20090311063719-v9iqjd00ts6260vv
batch up more INSERTs into transactions to help tests run quicker.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
/* This is the include file that should be included 'first' in every C file. */
 
21
 
 
22
#ifndef DRIZZLE_SERVER_GLOBAL_H
 
23
#define DRIZZLE_SERVER_GLOBAL_H
 
24
 
 
25
#if defined(i386) && !defined(__i386__)
 
26
#define __i386__
 
27
#endif
 
28
 
 
29
#include <config.h>
 
30
 
 
31
#if defined(__cplusplus)
 
32
 
 
33
# include CSTDINT_H
 
34
# include CINTTYPES_H
 
35
# include <cstdio>
 
36
# include <cstdlib>
 
37
# include <cstddef>
 
38
# include <cassert>
 
39
# include <cerrno>
 
40
# include <sstream>
 
41
#else
 
42
# include <stdint.h>
 
43
# include <inttypes.h>
 
44
# include <stdio.h>
 
45
# include <stdlib.h>
 
46
# include <stddef.h>
 
47
# include <errno.h>        /* Recommended by debian */
 
48
/*
 
49
  A lot of our programs uses asserts, so better to always include it
 
50
*/
 
51
# include <assert.h>
 
52
# include <stdbool.h>
 
53
 
 
54
#endif // __cplusplus
 
55
 
 
56
#include <math.h>
 
57
 
 
58
#ifndef EOVERFLOW
 
59
#define EOVERFLOW 84
 
60
#endif
 
61
 
 
62
 
 
63
#if TIME_WITH_SYS_TIME
 
64
# include <sys/time.h>
 
65
# include <time.h>
 
66
#else
 
67
# if HAVE_SYS_TIME_H
 
68
#  include <sys/time.h>
 
69
# else
 
70
#  include <time.h>
 
71
# endif
 
72
#endif
 
73
#ifndef HAVE_DECL_TIMEGM
 
74
#include <gnulib/time.h>
 
75
# if defined(__cplusplus)
 
76
extern "C"
 
77
# endif
 
78
time_t timegm (struct tm *__tm);
 
79
#endif /* HAVE_DECL_TIMEGM */
 
80
 
 
81
 
 
82
/*
 
83
  Temporary solution to solve bug#7156. Include "sys/types.h" before
 
84
  the thread headers, else the function madvise() will not be defined
 
85
*/
 
86
#if defined(HAVE_SYS_TYPES_H) && ( defined(sun) || defined(__sun) )
 
87
#include <sys/types.h>
 
88
#endif
 
89
 
 
90
 
 
91
#include <pthread.h>    /* AIX must have this included first */
 
92
 
 
93
#define _REENTRANT  1  /* Threads requires reentrant code */
 
94
 
 
95
#ifdef HAVE_LIMITS_H
 
96
#include <limits.h>
 
97
#endif
 
98
 
 
99
#ifdef HAVE_SYS_TYPES_H
 
100
#include <sys/types.h>
 
101
#endif
 
102
#ifdef HAVE_FCNTL_H
 
103
#include <fcntl.h>
 
104
#endif
 
105
 
 
106
#ifdef HAVE_UNISTD_H
 
107
#include <unistd.h>
 
108
#endif
 
109
 
 
110
 
 
111
#ifdef HAVE_SYS_STAT_H
 
112
# include <sys/stat.h>
 
113
#endif
 
114
 
 
115
/* Declared in int2str() */
 
116
extern char _dig_vec_upper[];
 
117
extern char _dig_vec_lower[];
 
118
 
 
119
#define set_if_bigger(a,b)  do { if ((a) < (b)) (a)=(b); } while(0)
 
120
 
 
121
#define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
 
122
#define array_elements(A) ((size_t) (sizeof(A)/sizeof(A[0])))
 
123
 
 
124
/* Some types that is different between systems */
 
125
 
 
126
typedef int  File;    /* File descriptor */
 
127
 
 
128
#ifdef HAVE_SYS_SOCKET_H
 
129
#include <sys/socket.h>
 
130
#endif
 
131
 
 
132
 
 
133
#ifndef FN_LIBCHAR
 
134
#define FN_LIBCHAR  '/'
 
135
#define FN_ROOTDIR  "/"
 
136
#endif
 
137
#define MY_NFILE  64  /* This is only used to save filenames */
 
138
#ifndef OS_FILE_LIMIT
 
139
#define OS_FILE_LIMIT  65535
 
140
#endif
 
141
 
 
142
/*
 
143
  How much overhead does malloc have. The code often allocates
 
144
  something like 1024-MALLOC_OVERHEAD bytes
 
145
*/
 
146
#define MALLOC_OVERHEAD 8
 
147
 
 
148
/* get memory in huncs */
 
149
#define ONCE_ALLOC_INIT    (uint32_t) (4096-MALLOC_OVERHEAD)
 
150
/* Typical record cash */
 
151
#define RECORD_CACHE_SIZE  (uint32_t) (64*1024-MALLOC_OVERHEAD)
 
152
/* Typical key cash */
 
153
#define KEY_CACHE_SIZE    (uint32_t) (8*1024*1024-MALLOC_OVERHEAD)
 
154
/* Default size of a key cache block  */
 
155
#define KEY_CACHE_BLOCK_SIZE  (uint32_t) 1024
 
156
 
 
157
 
 
158
/* Some things that this system doesn't have */
 
159
 
 
160
/* Some defines of functions for portability */
 
161
 
 
162
#undef remove    /* Crashes MySQL on SCO 5.0.0 */
 
163
#ifndef uint64_t2double
 
164
#define uint64_t2double(A) ((double) (uint64_t) (A))
 
165
#define my_off_t2double(A)  ((double) (my_off_t) (A))
 
166
#endif
 
167
 
 
168
#ifndef offsetof
 
169
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
 
170
#endif
 
171
#define ulong_to_double(X) ((double) (ulong) (X))
 
172
 
 
173
#ifndef STACK_DIRECTION
 
174
#error "please add -DSTACK_DIRECTION=1 or -1 to your CPPFLAGS"
 
175
#endif
 
176
 
 
177
#ifdef HAVE_FLOAT_H
 
178
#include <float.h>
 
179
#else
 
180
#if !defined(FLT_MIN)
 
181
#define FLT_MIN         ((float)1.40129846432481707e-45)
 
182
#endif
 
183
#if !defined(FLT_MAX)
 
184
#define FLT_MAX         ((float)3.40282346638528860e+38)
 
185
#endif
 
186
#endif
 
187
 
 
188
/* From limits.h instead */
 
189
#ifndef DBL_MIN
 
190
#define DBL_MIN    4.94065645841246544e-324
 
191
#endif
 
192
#ifndef DBL_MAX
 
193
#define DBL_MAX    1.79769313486231470e+308
 
194
#endif
 
195
#ifndef SIZE_T_MAX
 
196
#define SIZE_T_MAX ~((size_t) 0)
 
197
#endif
 
198
 
 
199
 
 
200
/* Define missing math constants. */
 
201
#ifndef M_PI
 
202
#define M_PI 3.14159265358979323846
 
203
#endif
 
204
#ifndef M_E
 
205
#define M_E 2.7182818284590452354
 
206
#endif
 
207
#ifndef M_LN2
 
208
#define M_LN2 0.69314718055994530942
 
209
#endif
 
210
 
 
211
/*
 
212
  Max size that must be added to a so that we know Size to make
 
213
  adressable obj.
 
214
*/
 
215
typedef ptrdiff_t my_ptrdiff_t;
 
216
 
 
217
#define MY_ALIGN(A,L)  (((A) + (L) - 1) & ~((L) - 1))
 
218
#define ALIGN_SIZE(A)  MY_ALIGN((A),sizeof(double))
 
219
/* Size to make adressable obj. */
 
220
#define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A),sizeof(t)))
 
221
/* Offset of field f in structure t */
 
222
#define OFFSET(t, f)  ((size_t)(char *)&((t *)0)->f)
 
223
#define ADD_TO_PTR(ptr,size,type) (type) ((unsigned char*) (ptr)+size)
 
224
#define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((unsigned char*) (A) - (unsigned char*) (B))
 
225
 
 
226
#define MY_DIV_UP(A, B) (((A) + (B) - 1) / (B))
 
227
#define MY_ALIGNED_BYTE_ARRAY(N, S, T) T N[MY_DIV_UP(S, sizeof(T))]
 
228
 
 
229
/* Typdefs for easyier portability */
 
230
 
 
231
#if !defined(HAVE_ULONG) && !defined(__USE_MISC)
 
232
typedef unsigned long ulong;      /* Short for unsigned long */
 
233
#endif
 
234
 
 
235
typedef uint64_t my_off_t;
 
236
 
 
237
#if defined(SIZEOF_OFF_T)
 
238
# if (SIZEOF_OFF_T == 8)
 
239
#  define OFF_T_MAX (INT64_MAX)
 
240
# else
 
241
#  define OFF_T_MAX (INT32_MAX)
 
242
# endif
 
243
#endif
 
244
 
 
245
#define MY_FILEPOS_ERROR  -1
 
246
 
 
247
/* Defines for time function */
 
248
#define SCALE_SEC  100
 
249
#define SCALE_USEC  10000
 
250
#define MY_HOW_OFTEN_TO_ALARM  2  /* How often we want info on screen */
 
251
#define MY_HOW_OFTEN_TO_WRITE  1000  /* How often we want info on screen */
 
252
 
 
253
 
 
254
#if defined(HAVE_CHARSET_utf8mb3) || defined(HAVE_CHARSET_utf8mb4)
 
255
#define DRIZZLE_UNIVERSAL_CLIENT_CHARSET "utf8"
 
256
#else
 
257
#define DRIZZLE_UNIVERSAL_CLIENT_CHARSET DRIZZLE_DEFAULT_CHARSET_NAME
 
258
#endif
 
259
 
 
260
#include <dlfcn.h>
 
261
 
 
262
/* FreeBSD 2.2.2 does not define RTLD_NOW) */
 
263
#ifndef RTLD_NOW
 
264
#define RTLD_NOW 1
 
265
#endif
 
266
 
 
267
#define cmax(a, b)       ((a) > (b) ? (a) : (b))
 
268
#define cmin(a, b)       ((a) < (b) ? (a) : (b))
 
269
 
 
270
#define DRIZZLE_SERVER
 
271
 
 
272
/* Length of decimal number represented by INT32. */
 
273
#define MY_INT32_NUM_DECIMAL_DIGITS 11
 
274
 
 
275
/* Length of decimal number represented by INT64. */
 
276
#define MY_INT64_NUM_DECIMAL_DIGITS 21
 
277
 
 
278
#define PROTOCOL_VERSION 10
 
279
/*
 
280
  Io buffer size; Must be a power of 2 and
 
281
  a multiple of 512. May be
 
282
  smaller what the disk page size. This influences the speed of the
 
283
  isam btree library. eg to big to slow.
 
284
*/
 
285
#define IO_SIZE 4096
 
286
/* Max file name len */
 
287
#define FN_LEN 256
 
288
/* Max length of extension (part of FN_LEN) */
 
289
#define FN_EXTLEN 20
 
290
/* Max length of full path-name */
 
291
#define FN_REFLEN 512
 
292
/* File extension character */
 
293
#define FN_EXTCHAR '.'
 
294
/* ~ is used as abbrev for home dir */
 
295
#define FN_HOMELIB '~'
 
296
/* ./ is used as abbrev for current dir */
 
297
#define FN_CURLIB '.'
 
298
/* Parent directory; Must be a string */
 
299
#define FN_PARENTDIR ".."
 
300
 
 
301
/* Quote argument (before cpp) */
 
302
#ifndef QUOTE_ARG
 
303
# define QUOTE_ARG(x) #x
 
304
#endif
 
305
/* Quote argument, (after cpp) */
 
306
#ifndef STRINGIFY_ARG
 
307
# define STRINGIFY_ARG(x) QUOTE_ARG(x)
 
308
#endif
 
309
 
 
310
/*
 
311
 * The macros below are borrowed from include/linux/compiler.h in the
 
312
 * Linux kernel. Use them to indicate the likelyhood of the truthfulness
 
313
 * of a condition. This serves two purposes - newer versions of gcc will be
 
314
 * able to optimize for branch predication, which could yield siginficant
 
315
 * performance gains in frequently executed sections of the code, and the
 
316
 * other reason to use them is for documentation
 
317
 */
 
318
#if !defined(__GNUC__)
 
319
#define __builtin_expect(x, expected_value) (x)
 
320
#endif
 
321
 
 
322
#define likely(x)  __builtin_expect((x),1)
 
323
#define unlikely(x)  __builtin_expect((x),0)
 
324
 
 
325
 
 
326
/*
 
327
  Only Linux is known to need an explicit sync of the directory to make sure a
 
328
  file creation/deletion/renaming in(from,to) this directory durable.
 
329
*/
 
330
#ifdef TARGET_OS_LINUX
 
331
#define NEED_EXPLICIT_SYNC_DIR 1
 
332
#endif
 
333
 
 
334
/* We need to turn off _DTRACE_VERSION if we're not going to use dtrace */
 
335
#if !defined(HAVE_DTRACE)
 
336
# undef _DTRACE_VERSION
 
337
# define _DTRACE_VERSION 0
 
338
#endif
 
339
 
 
340
#endif /* DRIZZLE_SERVER_GLOBAL_H */