~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/global.h

  • Committer: Padraig O'Sullivan
  • Date: 2009-03-21 01:02:23 UTC
  • mto: (960.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 961.
  • Revision ID: osullivan.padraig@gmail.com-20090321010223-j8cph7eeyt1u3xol
Fixed function object to ensure it correctly returns a boolean type since
memcmp returns an integer. Added some more comments.

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