~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/global.h

MergedĀ inĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#define __i386__
27
27
#endif
28
28
 
29
 
#include "config.h"
 
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) */
30
96
 
31
97
/*
32
98
  Temporary solution to solve bug#7156. Include "sys/types.h" before
36
102
#include <sys/types.h>
37
103
#endif
38
104
 
39
 
#if defined(HAVE_STDINT_H)
40
 
#include <stdint.h>
41
 
#else
42
 
#error "You must have stdint!"
43
 
#endif
44
 
 
45
 
#if defined(HAVE_INTTYPES_H)
46
 
#include <inttypes.h>
47
 
#else
48
 
#error "You must have inttypes!"
49
 
#endif
50
105
 
51
106
#include <pthread.h>    /* AIX must have this included first */
52
107
 
53
108
#define _REENTRANT  1  /* Threads requires reentrant code */
54
109
 
55
 
 
56
 
/* gcc/egcs issues */
57
 
 
58
 
#if defined(__GNUC) && defined(__EXCEPTIONS)
59
 
#error "Please add -fno-exceptions to CXXFLAGS and reconfigure/recompile"
60
 
#endif
61
 
 
62
 
#ifndef stdin
63
 
#include <stdio.h>
64
 
#endif
65
 
#ifdef HAVE_STDLIB_H
66
 
#include <stdlib.h>
67
 
#endif
68
 
#ifdef HAVE_STDDEF_H
69
 
#include <stddef.h>
70
 
#endif
71
 
 
72
 
#include <math.h>
73
110
#ifdef HAVE_LIMITS_H
74
111
#include <limits.h>
75
112
#endif
80
117
#ifdef HAVE_FCNTL_H
81
118
#include <fcntl.h>
82
119
#endif
83
 
#ifdef HAVE_SYS_TIMEB_H
84
 
#include <sys/timeb.h>        /* Avoid warnings on SCO */
85
 
#endif
86
 
#if TIME_WITH_SYS_TIME
87
 
# include <sys/time.h>
88
 
# include <time.h>
89
 
#else
90
 
# if HAVE_SYS_TIME_H
91
 
#  include <sys/time.h>
92
 
# else
93
 
#  include <time.h>
94
 
# endif
95
 
#endif /* TIME_WITH_SYS_TIME */
 
120
 
96
121
#ifdef HAVE_UNISTD_H
97
122
#include <unistd.h>
98
123
#endif
99
 
#if defined(__cplusplus) && defined(NO_CPLUSPLUS_ALLOCA)
100
 
#undef HAVE_ALLOCA
101
 
#undef HAVE_ALLOCA_H
102
 
#endif
103
 
#ifdef HAVE_ALLOCA_H
104
 
#include <alloca.h>
105
 
#endif
106
 
 
107
 
#include <errno.h>        /* Recommended by debian */
108
 
 
109
 
#if defined(HAVE_STDBOOL_H)
110
 
#include <stdbool.h>
111
 
#endif
 
124
 
112
125
 
113
126
#ifdef HAVE_SYS_STAT_H
114
127
# include <sys/stat.h>
115
128
#endif
116
129
 
117
 
/*
118
 
  A lot of our programs uses asserts, so better to always include it
119
 
*/
120
 
#include <assert.h>
121
 
 
122
 
#if !defined(HAVE_UINT)
123
 
#undef HAVE_UINT
124
 
#define HAVE_UINT
125
 
typedef unsigned int uint;
126
 
typedef unsigned short ushort;
127
 
#endif
128
 
 
129
130
/* Declared in int2str() */
130
131
extern char _dig_vec_upper[];
131
132
extern char _dig_vec_lower[];
132
133
 
133
 
#if defined(__cplusplus)
134
 
template <class T>
135
 
inline bool test(const T a)
136
 
{
137
 
  return a ? true : false;
138
 
}
139
 
template <class T, class U>
140
 
inline bool test_all_bits(const T a, const U b)
141
 
{
142
 
  return ((a & b) == b);
143
 
}
144
 
#else
145
 
#define test(a)    ((a) ? 1 : 0)
146
 
#define test_all_bits(a,b) (((a) & (b)) == (b))
147
 
#endif
148
 
 
 
134
#ifdef __cplusplus
 
135
template <class T> void set_if_bigger(T &a, const T &b)
 
136
{
 
137
  if (a < b)
 
138
    a=b;
 
139
}
 
140
 
 
141
template <class T> void set_if_smaller(T &a, const T &b)
 
142
{
 
143
  if (a > b)
 
144
    a=b;
 
145
}
 
146
#else
 
147
#ifdef __GNUC__
 
148
#define set_if_bigger(a,b) do {                 \
 
149
  const typeof(a) _a = (a);                     \
 
150
  const typeof(b) _b = (b);                     \
 
151
  (void) (&_a == &_b);                          \
 
152
  if ((a) < (b)) (a)=(b);                       \
 
153
  } while(0)
 
154
#define set_if_smaller(a,b) do {                \
 
155
  const typeof(a) _a = (a);                     \
 
156
  const typeof(b) _b = (b);                     \
 
157
  (void) (&_a == &_b);                          \
 
158
  if ((a) > (b)) (a)=(b);                       \
 
159
  } while(0)
 
160
 
 
161
#else
149
162
#define set_if_bigger(a,b)  do { if ((a) < (b)) (a)=(b); } while(0)
150
 
 
151
163
#define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
152
 
#define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1))
 
164
#endif
 
165
#endif
 
166
 
153
167
#define array_elements(A) ((size_t) (sizeof(A)/sizeof(A[0])))
154
168
 
155
169
/* Some types that is different between systems */
160
174
#include <sys/socket.h>
161
175
#endif
162
176
 
163
 
/* file create flags */
164
 
 
165
 
#ifndef O_SHARE      /* Probably not windows */
166
 
#define O_SHARE    0  /* Flag to my_open for shared files */
167
 
#endif /* O_SHARE */
168
 
 
169
 
#ifndef O_BINARY
170
 
#define O_BINARY  0  /* Flag to my_open for binary files */
171
 
#endif
172
 
 
173
 
#ifndef FILE_BINARY
174
 
#define FILE_BINARY  O_BINARY /* Flag to my_fopen for binary streams */
175
 
#endif
176
 
 
177
 
#define F_TO_EOF  0L  /* Param to lockf() to lock rest of file */
178
 
 
179
 
#ifndef O_TEMPORARY
180
 
#define O_TEMPORARY  0
181
 
#endif
182
 
#ifndef O_SHORT_LIVED
183
 
#define O_SHORT_LIVED  0
184
 
#endif
185
 
#ifndef O_NOFOLLOW
186
 
#define O_NOFOLLOW      0
187
 
#endif
188
 
 
189
 
 
190
177
 
191
178
#ifndef FN_LIBCHAR
192
179
#define FN_LIBCHAR  '/'
204
191
#define MALLOC_OVERHEAD 8
205
192
 
206
193
/* get memory in huncs */
207
 
#define ONCE_ALLOC_INIT    (uint) (4096-MALLOC_OVERHEAD)
 
194
static const uint32_t ONCE_ALLOC_INIT= 4096;
208
195
/* Typical record cash */
209
 
#define RECORD_CACHE_SIZE  (uint) (64*1024-MALLOC_OVERHEAD)
 
196
static const uint32_t RECORD_CACHE_SIZE= 64*1024;
210
197
/* Typical key cash */
211
 
#define KEY_CACHE_SIZE    (uint) (8*1024*1024-MALLOC_OVERHEAD)
 
198
static const uint32_t KEY_CACHE_SIZE= 8*1024*1024;
 
199
 
212
200
/* Default size of a key cache block  */
213
 
#define KEY_CACHE_BLOCK_SIZE  (uint) 1024
 
201
static const uint32_t KEY_CACHE_BLOCK_SIZE= 1024;
214
202
 
215
203
 
216
204
/* Some things that this system doesn't have */
232
220
#error "please add -DSTACK_DIRECTION=1 or -1 to your CPPFLAGS"
233
221
#endif
234
222
 
235
 
#if !defined(HAVE_STRTOK_R)
236
 
#define strtok_r(A,B,C) strtok((A),(B))
237
 
#endif
238
 
 
239
223
#ifdef HAVE_FLOAT_H
240
224
#include <float.h>
241
225
#else
274
258
  Max size that must be added to a so that we know Size to make
275
259
  adressable obj.
276
260
*/
277
 
#if SIZEOF_CHARP == 4
278
 
typedef int32_t    my_ptrdiff_t;
279
 
#else
280
 
typedef int64_t   my_ptrdiff_t;
281
 
#endif
 
261
typedef ptrdiff_t my_ptrdiff_t;
282
262
 
283
263
#define MY_ALIGN(A,L)  (((A) + (L) - 1) & ~((L) - 1))
284
264
#define ALIGN_SIZE(A)  MY_ALIGN((A),sizeof(double))
298
278
typedef unsigned long ulong;      /* Short for unsigned long */
299
279
#endif
300
280
 
301
 
#if SIZEOF_OFF_T > 4 
302
281
typedef uint64_t my_off_t;
303
 
#else
304
 
typedef unsigned long my_off_t;
 
282
 
 
283
#if defined(SIZEOF_OFF_T)
 
284
# if (SIZEOF_OFF_T == 8)
 
285
#  define OFF_T_MAX (INT64_MAX)
 
286
# else
 
287
#  define OFF_T_MAX (INT32_MAX)
 
288
# endif
305
289
#endif
306
 
#define MY_FILEPOS_ERROR  (~(my_off_t) 0)
307
 
 
308
 
typedef off_t os_off_t;
309
 
 
310
 
typedef int    myf;  /* Type of MyFlags in my_funcs */
311
 
#define MYF(v)          (myf) (v)
 
290
 
 
291
#define MY_FILEPOS_ERROR  -1
312
292
 
313
293
/* Defines for time function */
314
294
#define SCALE_SEC  100
317
297
#define MY_HOW_OFTEN_TO_WRITE  1000  /* How often we want info on screen */
318
298
 
319
299
 
320
 
#if defined(HAVE_CHARSET_utf8mb3) || defined(HAVE_CHARSET_utf8mb4)
321
 
#define DRIZZLE_UNIVERSAL_CLIENT_CHARSET "utf8"
322
 
#else
323
 
#define DRIZZLE_UNIVERSAL_CLIENT_CHARSET DRIZZLE_DEFAULT_CHARSET_NAME
324
 
#endif
325
 
 
326
300
#include <dlfcn.h>
327
301
 
328
302
/* FreeBSD 2.2.2 does not define RTLD_NOW) */
330
304
#define RTLD_NOW 1
331
305
#endif
332
306
 
333
 
#define cmax(a, b)       ((a) > (b) ? (a) : (b))
334
 
#define cmin(a, b)       ((a) < (b) ? (a) : (b))
 
307
#define DRIZZLE_SERVER
335
308
 
336
309
/* Length of decimal number represented by INT32. */
337
310
#define MY_INT32_NUM_DECIMAL_DIGITS 11
340
313
#define MY_INT64_NUM_DECIMAL_DIGITS 21
341
314
 
342
315
/*
 
316
  Io buffer size; Must be a power of 2 and
 
317
  a multiple of 512. May be
 
318
  smaller what the disk page size. This influences the speed of the
 
319
  isam btree library. eg to big to slow.
 
320
*/
 
321
#define IO_SIZE 4096
 
322
/* Max file name len */
 
323
#define FN_LEN 256
 
324
/* Max length of extension (part of FN_LEN) */
 
325
#define FN_EXTLEN 20
 
326
/* Max length of full path-name */
 
327
#define FN_REFLEN 512
 
328
/* File extension character */
 
329
#define FN_EXTCHAR '.'
 
330
/* ~ is used as abbrev for home dir */
 
331
#define FN_HOMELIB '~'
 
332
/* ./ is used as abbrev for current dir */
 
333
#define FN_CURLIB '.'
 
334
/* Parent directory; Must be a string */
 
335
#define FN_PARENTDIR ".."
 
336
 
 
337
/* Quote argument (before cpp) */
 
338
#ifndef QUOTE_ARG
 
339
# define QUOTE_ARG(x) #x
 
340
#endif
 
341
/* Quote argument, (after cpp) */
 
342
#ifndef STRINGIFY_ARG
 
343
# define STRINGIFY_ARG(x) QUOTE_ARG(x)
 
344
#endif
 
345
 
 
346
/*
 
347
 * The macros below are borrowed from include/linux/compiler.h in the
 
348
 * Linux kernel. Use them to indicate the likelyhood of the truthfulness
 
349
 * of a condition. This serves two purposes - newer versions of gcc will be
 
350
 * able to optimize for branch predication, which could yield siginficant
 
351
 * performance gains in frequently executed sections of the code, and the
 
352
 * other reason to use them is for documentation
 
353
 */
 
354
#if !defined(__GNUC__)
 
355
#define __builtin_expect(x, expected_value) (x)
 
356
#endif
 
357
 
 
358
#define likely(x)  __builtin_expect((x),1)
 
359
#define unlikely(x)  __builtin_expect((x),0)
 
360
 
 
361
 
 
362
/*
343
363
  Only Linux is known to need an explicit sync of the directory to make sure a
344
364
  file creation/deletion/renaming in(from,to) this directory durable.
345
365
*/
347
367
#define NEED_EXPLICIT_SYNC_DIR 1
348
368
#endif
349
369
 
350
 
#include <libdrizzle/gettext.h>
 
370
/* We need to turn off _DTRACE_VERSION if we're not going to use dtrace */
 
371
#if !defined(HAVE_DTRACE)
 
372
# undef _DTRACE_VERSION
 
373
# define _DTRACE_VERSION 0
 
374
#endif
351
375
 
352
376
#endif /* DRIZZLE_SERVER_GLOBAL_H */