~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/global.h

Remove PLUGIN and MODULES.

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