~pbms-core/pbms/async_read

« back to all changes in this revision

Viewing changes to mybs/src/cslib/CSDefs.h

  • Committer: paul-mccullagh
  • Date: 2008-03-26 11:35:17 UTC
  • Revision ID: paul-mccullagh-afb1610c21464a577ae428d72fc725eb986c05a5
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2007 SNAP Innovation GmbH
 
2
 *
 
3
 * BLOB Streaming for MySQL
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
18
 *
 
19
 * Paul McCullagh (H&G2JCtL)
 
20
 *
 
21
 * 2007-06-02
 
22
 *
 
23
 * CORE SYSTEM:
 
24
 * Common definitions that may be required be included at the
 
25
 * top of every header file.
 
26
 *
 
27
 */
 
28
 
 
29
#ifndef __CSDEFS_H__
 
30
#define __CSDEFS_H__
 
31
 
 
32
#include <sys/types.h>
 
33
 
 
34
#ifndef u_llong
 
35
#define u_llong                 unsigned long long
 
36
#endif
 
37
 
 
38
/* This value is at least 32 bits long: */
 
39
#ifndef u_int
 
40
#define u_int                   unsigned long
 
41
#endif
 
42
 
 
43
/* This value is at least 32 bits long: */
 
44
#define s_long                  long
 
45
 
 
46
/*
 
47
 * A unsigned integer at least 32 bits long.
 
48
 * The size used is whatever is most
 
49
 * convenient to the machine.
 
50
 */
 
51
#ifndef u_int
 
52
#define u_int                   unsigned int
 
53
#endif
 
54
/*
 
55
 * A signed integer at least 32 bits long.
 
56
 * The size used is whatever is most
 
57
 * convenient to the machine.
 
58
 */
 
59
#define s_int                   int
 
60
 
 
61
/*
 
62
 * An unsigned integer 2 bytes long.
 
63
 */
 
64
#ifndef u_short
 
65
#define u_short                 unsigned short
 
66
#endif
 
67
 
 
68
/*
 
69
 * An unsigned integer, 1 byte long:
 
70
 */
 
71
#ifndef u_char
 
72
#define u_char                  unsigned char
 
73
#endif
 
74
 
 
75
/*
 
76
 * An usigned integer, 1 byte long:
 
77
 */
 
78
#define s_char                  unsigned char
 
79
 
 
80
/* Forward declartion of a thread: */
 
81
class CSThread;
 
82
 
 
83
#ifdef OS_WINDOWS
 
84
 
 
85
#define CS_DEFAULT_EOL          "\r\n"
 
86
#define CS_DIR_CHAR                     '\\'
 
87
#define CS_DIR_DELIM            "\\"
 
88
#define IS_DIR_CHAR(ch)         ((ch) == CS_DIR_CHAR || (ch) == '/')
 
89
 
 
90
#else
 
91
 
 
92
#define CS_DEFAULT_EOL          "\n"
 
93
#define CS_DIR_CHAR                     '/'
 
94
#define CS_DIR_DELIM            "/"
 
95
#define IS_DIR_CHAR(ch)         ((ch) == CS_DIR_CHAR)
 
96
 
 
97
#endif
 
98
 
 
99
#define CS_CALL_STACK_SIZE              100
 
100
#define CS_RELEASE_STACK_SIZE   200
 
101
#define CS_JUMP_STACK_SIZE              20
 
102
 
 
103
/* Fixed length types */
 
104
 
 
105
#ifdef CS_WIN
 
106
 
 
107
#define csInt1                  __int8
 
108
#define csInt2                  __int16
 
109
#define csInt4                  __int32
 
110
#define csInt8                  __int64
 
111
 
 
112
#define csWord1                 unsigned __int8
 
113
#define csWord2                 unsigned __int16
 
114
#define csWord4                 unsigned __int32
 
115
#define csWord8                 unsigned __int64
 
116
 
 
117
#ifndef PATH_MAX
 
118
#define PATH_MAX                MAX_PATH
 
119
#endif
 
120
#ifndef NAME_MAX
 
121
#define NAME_MAX                MAX_PATH
 
122
#endif
 
123
 
 
124
/* XT actually assumes that off_t is 8 bytes: */
 
125
#define off_t                   csWord8
 
126
 
 
127
#else // CS_WIN
 
128
 
 
129
#define csInt1                  int8_t
 
130
#define csInt2                  int16_t
 
131
#define csInt4                  int32_t
 
132
#define csInt8                  int64_t
 
133
 
 
134
#define csWord1                 u_int8_t
 
135
#define csWord2                 u_int16_t
 
136
#define csWord4                 u_int32_t
 
137
#define csWord8                 u_int64_t
 
138
 
 
139
#endif // CS_WIN
 
140
 
 
141
/* A pointer sized word value: */
 
142
#define csWordPS                ptrdiff_t
 
143
 
 
144
#define CS_MAX_INT_1    ((csInt1) 0x7F)
 
145
#define CS_MIN_INT_1    ((csInt1) 0x80)
 
146
#define CS_MAX_INT_2    ((csInt2) 0x7FFF)
 
147
#define CS_MIN_INT_2    ((csInt2) 0x8000)
 
148
#define CS_MAX_INT_4    ((csInt4) 0x7FFFFFFF)
 
149
#define CS_MIN_INT_4    ((csInt4) 0x80000000)
 
150
 
 
151
#define csReal4                 float
 
152
#define csReal8                 double
 
153
 
 
154
typedef csWord1                 CSDiskValue1[1];        
 
155
typedef csWord1                 CSDiskValue2[2];        
 
156
typedef csWord1                 CSDiskValue3[3];        
 
157
typedef csWord1                 CSDiskValue4[4];        
 
158
typedef csWord1                 CSDiskValue6[6];        
 
159
typedef csWord1                 CSDiskValue8[8];        
 
160
 
 
161
/*
 
162
 * Byte order on the disk is little endian! This is the byte order of the i386.
 
163
 * Little endian byte order starts with the least significan byte.
 
164
 *
 
165
 * The reason for choosing this byte order for the disk is 2-fold:
 
166
 * Firstly the i386 is the cheapest and fasted platform today.
 
167
 * Secondly the i386, unlike RISK chips (with big endian) can address
 
168
 * memory that is not aligned!
 
169
 *
 
170
 * Since the disk image of PrimeBase XT is not aligned, the second point
 
171
 * is significant. A RISK chip needs to access it byte-wise, so we might as
 
172
 * well do the byte swapping at the same time.
 
173
 *
 
174
 * The macros below are of 4 general types:
 
175
 *
 
176
 * GET/SET - Get and set 1,2,4,8 byte values (short, int, long, etc).
 
177
 * Values are swapped only on big endian platforms. This makes these
 
178
 * functions very efficient on little-endian platforms.
 
179
 *
 
180
 * COPY - Transfer data without swapping regardless of platform. This
 
181
 * function is a bit more efficient on little-endian platforms
 
182
 * because alignment is not an issue.
 
183
 *
 
184
 * MOVE - Similar to get and set, but the deals with memory instead
 
185
 * of values. Since no swapping is done on little-endian platforms
 
186
 * this function is identical to COPY on little-endian platforms.
 
187
 *
 
188
 * SWAP - Transfer and swap data regardless of the platform type.
 
189
 * Aligment is not assumed.
 
190
 *
 
191
 * The DISK component of the macro names indicates that alignment of
 
192
 * the value cannot be assumed.
 
193
 *
 
194
 */
 
195
#if BYTE_ORDER == BIG_ENDIAN
 
196
/* The native order of the machine is big endian. Since the native disk
 
197
 * disk order of XT is little endian, all data to and from disk
 
198
 * must be swapped.
 
199
 */
 
200
#define CS_SET_DISK_1(d, s)             ((d)[0] = (csWord1) (s))
 
201
 
 
202
#define CS_SET_DISK_2(d, s)             do { (d)[0] = (csWord1)  (((csWord2) (s))        & 0xFF); (d)[1] = (csWord1) ((((csWord2) (s)) >> 8 ) & 0xFF); } while (0)
 
203
 
 
204
#define CS_SET_DISK_3(d, s)             do { (d)[0] = (csWord1)  (((csWord4) (s))        & 0xFF); (d)[1] = (csWord1) ((((csWord4) (s)) >> 8 ) & 0xFF); \
 
205
                                                                         (d)[2] = (csWord1) ((((csWord4) (s)) >> 16) & 0xFF); } while (0)
 
206
 
 
207
#define CS_SET_DISK_4(d, s)             do { (d)[0] = (csWord1)  (((csWord4) (s))        & 0xFF); (d)[1] = (csWord1) ((((csWord4) (s)) >> 8 ) & 0xFF); \
 
208
                                                                         (d)[2] = (csWord1) ((((csWord4) (s)) >> 16) & 0xFF); (d)[3] = (csWord1) ((((csWord4) (s)) >> 24) & 0xFF); } while (0)
 
209
 
 
210
#define CS_SET_DISK_6(d, s)             do { (d)[0] = (csWord1)  (((csWord8) (s))        & 0xFF); (d)[1] = (csWord1) ((((csWord8) (s)) >> 8 ) & 0xFF); \
 
211
                                                                         (d)[2] = (csWord1) ((((csWord8) (s)) >> 16) & 0xFF); (d)[3] = (csWord1) ((((csWord8) (s)) >> 24) & 0xFF); \
 
212
                                                                         (d)[4] = (csWord1) ((((csWord8) (s)) >> 32) & 0xFF); (d)[5] = (csWord1) ((((csWord8) (s)) >> 40) & 0xFF); } while (0)
 
213
 
 
214
#define CS_SET_DISK_8(d, s)             do { (d)[0] = (csWord1)  (((csWord8) (s))        & 0xFF); (d)[1] = (csWord1) ((((csWord8) (s)) >> 8 ) & 0xFF); \
 
215
                                                                         (d)[2] = (csWord1) ((((csWord8) (s)) >> 16) & 0xFF); (d)[3] = (csWord1) ((((csWord8) (s)) >> 24) & 0xFF); \
 
216
                                                                         (d)[4] = (csWord1) ((((csWord8) (s)) >> 32) & 0xFF); (d)[5] = (csWord1) ((((csWord8) (s)) >> 40) & 0xFF); \
 
217
                                                                         (d)[6] = (csWord1) ((((csWord8) (s)) >> 48) & 0xFF); (d)[7] = (csWord1) ((((csWord8) (s)) >> 56) & 0xFF); } while (0)
 
218
 
 
219
#define CS_GET_DISK_1(s)                ((s)[0])
 
220
 
 
221
#define CS_GET_DISK_2(s)                ((csWord2) (((csWord2) (s)[0]) | (((csWord2) (s)[1]) << 8)))
 
222
 
 
223
#define CS_GET_DISK_3(s)                ((csWord4) (((csWord4) (s)[0]) | (((csWord4) (s)[1]) << 8) | (((csWord4) (s)[2]) << 16)))
 
224
 
 
225
#define CS_GET_DISK_4(s)                (((csWord4) (s)[0])        | (((csWord4) (s)[1]) << 8 ) | \
 
226
                                                                (((csWord4) (s)[2]) << 16) | (((csWord4) (s)[3]) << 24))
 
227
 
 
228
#define CS_GET_DISK_6(s)                (((csWord8) (s)[0])        | (((csWord8) (s)[1]) << 8 ) | \
 
229
                                                                (((csWord8) (s)[2]) << 16) | (((csWord8) (s)[3]) << 24) | \
 
230
                                                                (((csWord8) (s)[4]) << 32) | (((csWord8) (s)[5]) << 40))
 
231
 
 
232
#define CS_GET_DISK_8(s)                (((csWord8) (s)[0])        | (((csWord8) (s)[1]) << 8 ) | \
 
233
                                                                (((csWord8) (s)[2]) << 16) | (((csWord8) (s)[3]) << 24) | \
 
234
                                                                (((csWord8) (s)[4]) << 32) | (((csWord8) (s)[5]) << 40) | \
 
235
                                                                (((csWord8) (s)[6]) << 48) | (((csWord8) (s)[7]) << 56))
 
236
 
 
237
/* Move will copy memory, and swap the bytes on a big endian machine.
 
238
 * On a little endian machine it is the same as COPY.
 
239
 */
 
240
#define CS_MOVE_DISK_1(d, s)    ((d)[0] = (s)[0])
 
241
#define CS_MOVE_DISK_2(d, s)    do { (d)[0] = (s)[1]; (d)[1] = (s)[0]; } while (0)
 
242
#define CS_MOVE_DISK_3(d, s)    do { (d)[0] = (s)[2]; (d)[1] = (s)[1]; (d)[2] = (s)[0]; } while (0)
 
243
#define CS_MOVE_DISK_4(d, s)    do { (d)[0] = (s)[3]; (d)[1] = (s)[2]; (d)[2] = (s)[1]; (d)[3] = (s)[0]; } while (0)
 
244
#define CS_MOVE_DISK_8(d, s)    do { (d)[0] = (s)[7]; (d)[1] = (s)[6]; \
 
245
                                                                         (d)[2] = (s)[5]; (d)[3] = (s)[4]; \
 
246
                                                                         (d)[4] = (s)[3]; (d)[5] = (s)[2]; \
 
247
                                                                         (d)[6] = (s)[1]; (d)[7] = (s)[0]; } while (0)
 
248
 
 
249
/*
 
250
 * Copy just copies the number of bytes assuming the data is not alligned.
 
251
 */
 
252
#define CS_COPY_DISK_1(d, s)    (d)[0] = s
 
253
#define CS_COPY_DISK_2(d, s)    do { (d)[0] = (s)[0]; (d)[1] = (s)[1]; } while (0)
 
254
#define CS_COPY_DISK_3(d, s)    do { (d)[0] = (s)[0]; (d)[1] = (s)[1]; (d)[2] = (s)[2]; } while (0)
 
255
#define CS_COPY_DISK_4(d, s)    do { (d)[0] = (s)[0]; (d)[1] = (s)[1]; (d)[2] = (s)[2]; (d)[3] = (s)[3]; } while (0)
 
256
#define CS_COPY_DISK_6(d, s)    memcpy(&((d)[0]), &((s)[0]), 6)
 
257
#define CS_COPY_DISK_8(d, s)    memcpy(&((d)[0]), &((s)[0]), 8)
 
258
#define CS_COPY_DISK_10(d, s)   memcpy(&((d)[0]), &((s)[0]), 10)
 
259
 
 
260
#define CS_SET_NULL_DISK_1(d)   CS_SET_DISK_1(d, 0)
 
261
#define CS_SET_NULL_DISK_2(d)   do { (d)[0] = 0; (d)[1] = 0; } while (0)
 
262
#define CS_SET_NULL_DISK_4(d)   do { (d)[0] = 0; (d)[1] = 0; (d)[2] = 0; (d)[3] = 0; } while (0)
 
263
#define CS_SET_NULL_DISK_6(d)   do { (d)[0] = 0; (d)[1] = 0; (d)[2] = 0; (d)[3] = 0; (d)[4] = 0; (d)[5] = 0; } while (0)
 
264
#define CS_SET_NULL_DISK_8(d)   do { (d)[0] = 0; (d)[1] = 0; (d)[2] = 0; (d)[3] = 0; (d)[4] = 0; (d)[5] = 0; (d)[6] = 0; (d)[7] = 0; } while (0)
 
265
 
 
266
#define CS_IS_NULL_DISK_1(d)    (!(CS_GET_DISK_1(d)))
 
267
#define CS_IS_NULL_DISK_4(d)    (!(d)[0] && !(d)[1] && !(d)[2] && !(d)[3])
 
268
#define CS_IS_NULL_DISK_8(d)    (!(d)[0] && !(d)[1] && !(d)[2] && !(d)[3] && !(d)[4] && !(d)[5] && !(d)[6] && !(7)[3])
 
269
 
 
270
#define CS_EQ_DISK_4(d, s)              ((d)[0] == (s)[0] && (d)[1] == (s)[1] && (d)[2] == (s)[2] && (d)[3] == (s)[3])
 
271
#define CS_EQ_DISK_8(d, s)              ((d)[0] == (s)[0] && (d)[1] == (s)[1] && (d)[2] == (s)[2] && (d)[3] == (s)[3] && \
 
272
                                                                (d)[4] == (s)[4] && (d)[5] == (s)[5] && (d)[6] == (s)[6] && (d)[7] == (s)[7])
 
273
 
 
274
#define CS_IS_FF_DISK_4(d)              ((d)[0] == 0xFF && (d)[1] == 0xFF && (d)[2] == 0xFF && (d)[3] == 0xFF)
 
275
#else
 
276
/*
 
277
 * The native order of the machine is little endian. This means the data to
 
278
 * and from disk need not be swapped. In addition to this, since
 
279
 * the i386 can access non-aligned memory we are not required to
 
280
 * handle the data byte-for-byte.
 
281
 */
 
282
#define CS_SET_DISK_1(d, s)             ((d)[0] = (csWord1) (s))
 
283
#define CS_SET_DISK_2(d, s)             (*((csWord2 *) &((d)[0])) = (csWord2) (s))
 
284
#define CS_SET_DISK_3(d, s)             do { (*((csWord2 *) &((d)[0])) = (csWord2) (s));  *((csWord1 *) &((d)[2])) = (csWord1) (((csWord4) (s)) >> 16); } while (0)
 
285
#define CS_SET_DISK_4(d, s)             (*((csWord4 *) &((d)[0])) = (csWord4) (s))
 
286
#define CS_SET_DISK_6(d, s)             do { *((csWord4 *) &((d)[0])) = (csWord4) (s); *((csWord2 *) &((d)[4])) = (csWord2) (((csWord8) (s)) >> 32); } while (0)
 
287
#define CS_SET_DISK_8(d, s)             (*((csWord8 *) &((d)[0])) = (csWord8) (s))
 
288
 
 
289
#define CS_GET_DISK_1(s)                ((s)[0])
 
290
#define CS_GET_DISK_2(s)                *((csWord2 *) &((s)[0]))
 
291
#define CS_GET_DISK_3(s)                ((csWord4) *((csWord2 *) &((s)[0])) | (((csWord4) *((csWord1 *) &((s)[2]))) << 16))
 
292
#define CS_GET_DISK_4(s)                *((csWord4 *) &((s)[0]))
 
293
#define CS_GET_DISK_6(s)                ((csWord8) *((csWord4 *) &((s)[0])) | (((csWord8) *((csWord2 *) &((s)[4]))) << 32))
 
294
#define CS_GET_DISK_8(s)                *((csWord8 *) &((s)[0]))
 
295
 
 
296
#define CS_MOVE_DISK_1(d, s)    ((d)[0] = (s)[0])
 
297
#define CS_MOVE_DISK_2(d, s)    CS_COPY_DISK_2(d, s)
 
298
#define CS_MOVE_DISK_3(d, s)    CS_COPY_DISK_3(d, s)
 
299
#define CS_MOVE_DISK_4(d, s)    CS_COPY_DISK_4(d, s)
 
300
#define CS_MOVE_DISK_8(d, s)    CS_COPY_DISK_8(d, s)
 
301
 
 
302
#define CS_COPY_DISK_1(d, s)    (d)[0] = s
 
303
#define CS_COPY_DISK_2(d, s)    (*((csWord2 *) &((d)[0])) = (*((csWord2 *) &((s)[0]))))
 
304
#define CS_COPY_DISK_3(d, s)    do { *((csWord2 *) &((d)[0])) = *((csWord2 *) &((s)[0])); (d)[2] = (s)[2]; } while (0)
 
305
#define CS_COPY_DISK_4(d, s)    (*((csWord4 *) &((d)[0])) = (*((csWord4 *) &((s)[0]))))
 
306
#define CS_COPY_DISK_6(d, s)    do { *((csWord4 *) &((d)[0])) = *((csWord4 *) &((s)[0])); *((csWord2 *) &((d)[4])) = *((csWord2 *) &((s)[4])); } while (0)
 
307
#define CS_COPY_DISK_8(d, s)    (*((csWord8 *) &(d[0])) = (*((csWord8 *) &((s)[0]))))
 
308
#define CS_COPY_DISK_10(d, s)   memcpy(&((d)[0]), &((s)[0]), 10)
 
309
 
 
310
#define CS_SET_NULL_DISK_1(d)   CS_SET_DISK_1(d, 0)
 
311
#define CS_SET_NULL_DISK_2(d)   CS_SET_DISK_2(d, 0)
 
312
#define CS_SET_NULL_DISK_3(d)   CS_SET_DISK_3(d, 0)
 
313
#define CS_SET_NULL_DISK_4(d)   CS_SET_DISK_4(d, 0L)
 
314
#define CS_SET_NULL_DISK_6(d)   CS_SET_DISK_6(d, 0LL)
 
315
#define CS_SET_NULL_DISK_8(d)   CS_SET_DISK_8(d, 0LL)
 
316
 
 
317
#define CS_IS_NULL_DISK_1(d)    (!(CS_GET_DISK_1(d)))
 
318
#define CS_IS_NULL_DISK_2(d)    (!(CS_GET_DISK_2(d)))
 
319
#define CS_IS_NULL_DISK_3(d)    (!(CS_GET_DISK_3(d)))
 
320
#define CS_IS_NULL_DISK_4(d)    (!(CS_GET_DISK_4(d)))
 
321
#define CS_IS_NULL_DISK_8(d)    (!(CS_GET_DISK_8(d)))
 
322
 
 
323
#define CS_EQ_DISK_4(d, s)              (CS_GET_DISK_4(d) == CS_GET_DISK_4(s))
 
324
#define CS_EQ_DISK_8(d, s)              (CS_GET_DISK_8(d) == CS_GET_DISK_8(s))
 
325
 
 
326
#define CS_IS_FF_DISK_4(d)              (CS_GET_DISK_4(d) == 0xFFFFFFFF)
 
327
#endif
 
328
 
 
329
#define CS_CMP_DISK_4(a, b)             ((csInt4) CS_GET_DISK_4(a) - (csInt4) CS_GET_DISK_4(b))
 
330
#define CS_CMP_DISK_8(d, s)             memcmp(&((d)[0]), &((s)[0]), 8)
 
331
//#define CS_CMP_DISK_8(d, s)           (CS_CMP_DISK_4((d).h_number_4, (s).h_number_4) == 0 ? CS_CMP_DISK_4((d).h_file_4, (s).h_file_4) : CS_CMP_DISK_4((d).h_number_4, (s).h_number_4))
 
332
 
 
333
#define CS_SWAP_DISK_2(d, s)    do { (d)[0] = (s)[1]; (d)[1] = (s)[0]; } while (0)
 
334
#define CS_SWAP_DISK_3(d, s)    do { (d)[0] = (s)[2]; (d)[1] = (s)[1]; (d)[2] = (s)[0]; } while (0)
 
335
#define CS_SWAP_DISK_4(d, s)    do { (d)[0] = (s)[3]; (d)[1] = (s)[2]; (d)[2] = (s)[1]; (d)[3] = (s)[0]; } while (0)
 
336
#define CS_SWAP_DISK_8(d, s)    do { (d)[0] = (s)[7]; (d)[1] = (s)[6]; (d)[2] = (s)[5]; (d)[3] = (s)[4]; \
 
337
                                                                         (d)[4] = (s)[3]; (d)[5] = (s)[2]; (d)[6] = (s)[1]; (d)[7] = (s)[0]; } while (0)
 
338
 
 
339
#endif