~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/global.h

  • Committer: Monty Taylor
  • Date: 2009-03-04 02:48:12 UTC
  • mto: (917.1.2 mordred)
  • mto: This revision was merged to the branch mainline in revision 918.
  • Revision ID: mordred@inaugust.com-20090304024812-5wb6wpye5c1iitbq
Applied atomic patch to current tree.

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