92
34
os_thread_sleep(2000 /* 2 ms */); \
95
#endif /* !UNIV_HOTBACKUP */
97
/********************************************************//**
38
/************************************************************
98
39
Gets the high 32 bits in a ulint. That is makes a shift >> 32,
99
40
but since there seem to be compiler bugs in both gcc and Visual C++,
100
we do this by a special conversion.
41
we do this by a special conversion. */
106
ulint a); /*!< in: ulint */
107
/******************************************************//**
108
Calculates the minimum of two ulints.
47
ulint a); /* in: ulint */
48
/**********************************************************
49
Calculates the minimum of two ulints. */
114
ulint n1, /*!< in: first number */
115
ulint n2); /*!< in: second number */
116
/******************************************************//**
117
Calculates the maximum of two ulints.
55
ulint n1, /* in: first number */
56
ulint n2); /* in: second number */
57
/**********************************************************
58
Calculates the maximum of two ulints. */
123
ulint n1, /*!< in: first number */
124
ulint n2); /*!< in: second number */
125
/****************************************************************//**
64
ulint n1, /* in: first number */
65
ulint n2); /* in: second number */
66
/********************************************************************
126
67
Calculates minimum of two ulint-pairs. */
131
ulint* a, /*!< out: more significant part of minimum */
132
ulint* b, /*!< out: less significant part of minimum */
133
ulint a1, /*!< in: more significant part of first pair */
134
ulint b1, /*!< in: less significant part of first pair */
135
ulint a2, /*!< in: more significant part of second pair */
136
ulint b2); /*!< in: less significant part of second pair */
137
/******************************************************//**
139
@return 1 if a > b, 0 if a == b, -1 if a < b */
72
ulint* a, /* out: more significant part of minimum */
73
ulint* b, /* out: less significant part of minimum */
74
ulint a1, /* in: more significant part of first pair */
75
ulint b1, /* in: less significant part of first pair */
76
ulint a2, /* in: more significant part of second pair */
77
ulint b2); /* in: less significant part of second pair */
78
/**********************************************************
79
Compares two ulints. */
144
ulint a, /*!< in: ulint */
145
ulint b); /*!< in: ulint */
146
/*******************************************************//**
147
Compares two pairs of ulints.
148
@return -1 if a < b, 0 if a == b, 1 if a > b */
84
/* out: 1 if a > b, 0 if a == b, -1 if a < b */
85
ulint a, /* in: ulint */
86
ulint b); /* in: ulint */
87
/***********************************************************
88
Compares two pairs of ulints. */
153
ulint a1, /*!< in: more significant part of first pair */
154
ulint a2, /*!< in: less significant part of first pair */
155
ulint b1, /*!< in: more significant part of second pair */
156
ulint b2); /*!< in: less significant part of second pair */
157
/*************************************************************//**
158
Determines if a number is zero or a power of two.
160
@return nonzero if n is zero or a power of two; zero otherwise */
93
/* out: -1 if a < b, 0 if a == b,
95
ulint a1, /* in: more significant part of first pair */
96
ulint a2, /* in: less significant part of first pair */
97
ulint b1, /* in: more significant part of second pair */
98
ulint b2); /* in: less significant part of second pair */
99
/*****************************************************************
100
Determines if a number is zero or a power of two. */
161
101
#define ut_is_2pow(n) UNIV_LIKELY(!((n) & ((n) - 1)))
162
/*************************************************************//**
163
Calculates fast the remainder of n/m when m is a power of two.
164
@param n in: numerator
165
@param m in: denominator, must be a power of two
166
@return the remainder of n/m */
102
/*****************************************************************
103
Calculates fast the remainder of n/m when m is a power of two. */
167
104
#define ut_2pow_remainder(n, m) ((n) & ((m) - 1))
168
/*************************************************************//**
105
/*****************************************************************
169
106
Calculates the biggest multiple of m that is not bigger than n
170
when m is a power of two. In other words, rounds n down to m * k.
171
@param n in: number to round down
172
@param m in: alignment, must be a power of two
173
@return n rounded down to the biggest possible integer multiple of m */
107
when m is a power of two. In other words, rounds n down to m * k. */
174
108
#define ut_2pow_round(n, m) ((n) & ~((m) - 1))
175
/** Align a number down to a multiple of a power of two.
176
@param n in: number to round down
177
@param m in: alignment, must be a power of two
178
@return n rounded down to the biggest possible integer multiple of m */
179
109
#define ut_calc_align_down(n, m) ut_2pow_round(n, m)
180
/********************************************************//**
110
/************************************************************
181
111
Calculates the smallest multiple of m that is not smaller than n
182
when m is a power of two. In other words, rounds n up to m * k.
183
@param n in: number to round up
184
@param m in: alignment, must be a power of two
185
@return n rounded up to the smallest possible integer multiple of m */
112
when m is a power of two. In other words, rounds n up to m * k. */
186
113
#define ut_calc_align(n, m) (((n) + ((m) - 1)) & ~((m) - 1))
187
/*************************************************************//**
114
/*****************************************************************
188
115
Calculates fast the 2-logarithm of a number, rounded upward to an
190
@return logarithm in the base 2, rounded upward */
195
ulint n); /*!< in: number */
196
/*************************************************************//**
197
Calculates 2 to power n.
198
@return 2 to power n */
121
/* out: logarithm in the base 2, rounded upward */
122
ulint n); /* in: number */
123
/*****************************************************************
124
Calculates 2 to power n. */
203
ulint n); /*!< in: number */
204
/*************************************************************//**
205
Calculates fast the number rounded up to the nearest power of 2.
206
@return first power of 2 which is >= n */
129
/* out: 2 to power n */
130
ulint n); /* in: number */
131
/*****************************************************************
132
Calculates fast the number rounded up to the nearest power of 2. */
211
ulint n) /*!< in: number != 0 */
212
__attribute__((const));
137
/* out: first power of 2 which is >= n */
138
ulint n) /* in: number != 0 */
139
__attribute__((__const__));
214
/** Determine how many bytes (groups of 8 bits) are needed to
215
store the given number of bits.
217
@return number of bytes (octets) needed to represent b */
141
/* Determine how many bytes (groups of 8 bits) are needed to
142
store the given number of bits. */
218
143
#define UT_BITS_IN_BYTES(b) (((b) + 7) / 8)
220
/**********************************************************//**
145
/**************************************************************
221
146
Returns system time. We do not specify the format of the time returned:
222
the only way to manipulate it is to use the function ut_difftime.
223
@return system time */
147
the only way to manipulate it is to use the function ut_difftime. */
228
#ifndef UNIV_HOTBACKUP
229
/**********************************************************//**
152
/**************************************************************
230
153
Returns system time.
231
154
Upon successful completion, the value 0 is returned; otherwise the
232
155
value -1 is returned and the global variable errno is set to indicate the
234
@return 0 on success, -1 otherwise */
239
ulint* sec, /*!< out: seconds since the Epoch */
240
ulint* ms); /*!< out: microseconds since the Epoch+*sec */
161
/* out: 0 on success, -1 otherwise */
162
ulint* sec, /* out: seconds since the Epoch */
163
ulint* ms); /* out: microseconds since the Epoch+*sec */
242
/**********************************************************//**
165
/**************************************************************
243
166
Returns the number of microseconds since epoch. Similar to
244
167
time(3), the return value is also stored in *tloc, provided
245
that tloc is non-NULL.
246
@return us since epoch */
168
that tloc is non-NULL. */
251
ullint* tloc); /*!< out: us since epoch, if non-NULL */
252
/**********************************************************//**
253
Returns the number of milliseconds since some epoch. The
254
value may wrap around. It should only be used for heuristic
256
@return ms since epoch */
261
#endif /* !UNIV_HOTBACKUP */
173
/* out: us since epoch */
174
ullint* tloc); /* out: us since epoch, if non-NULL */
263
/**********************************************************//**
264
Returns the difference of two times in seconds.
265
@return time2 - time1 expressed in seconds */
176
/**************************************************************
177
Returns the difference of two times in seconds. */
270
ib_time_t time2, /*!< in: time */
271
ib_time_t time1); /*!< in: time */
272
/**********************************************************//**
182
/* out: time2 - time1 expressed in seconds */
183
ib_time_t time2, /* in: time */
184
ib_time_t time1); /* in: time */
185
/**************************************************************
273
186
Prints a timestamp to a file. */
276
189
ut_print_timestamp(
277
190
/*===============*/
278
FILE* file); /*!< in: file where to print */
279
/**********************************************************//**
191
FILE* file); /* in: file where to print */
192
/**************************************************************
280
193
Sprintfs a timestamp to a buffer, 13..14 chars plus terminating NUL. */
283
196
ut_sprintf_timestamp(
284
197
/*=================*/
285
char* buf); /*!< in: buffer where to sprintf */
286
#ifdef UNIV_HOTBACKUP
287
/**********************************************************//**
198
char* buf); /* in: buffer where to sprintf */
199
/**************************************************************
288
200
Sprintfs a timestamp to a buffer with no spaces and with ':' characters
289
201
replaced by '_'. */
292
204
ut_sprintf_timestamp_without_extra_chars(
293
205
/*=====================================*/
294
char* buf); /*!< in: buffer where to sprintf */
295
/**********************************************************//**
206
char* buf); /* in: buffer where to sprintf */
207
/**************************************************************
296
208
Returns current year, month, day. */
299
211
ut_get_year_month_day(
300
212
/*==================*/
301
ulint* year, /*!< out: current year */
302
ulint* month, /*!< out: month */
303
ulint* day); /*!< out: day */
304
#else /* UNIV_HOTBACKUP */
305
/*************************************************************//**
213
ulint* year, /* out: current year */
214
ulint* month, /* out: month */
215
ulint* day); /* out: day */
216
/*****************************************************************
306
217
Runs an idle loop on CPU. The argument gives the desired delay
307
in microseconds on 100 MHz Pentium + Visual C++.
308
@return dummy value */
218
in microseconds on 100 MHz Pentium + Visual C++. */
313
ulint delay); /*!< in: delay in microseconds on 100 MHz Pentium */
314
#endif /* UNIV_HOTBACKUP */
315
/*************************************************************//**
223
/* out: dummy value */
224
ulint delay); /* in: delay in microseconds on 100 MHz Pentium */
225
/*****************************************************************
316
226
Prints the contents of a memory buffer in hex and ascii. */
321
FILE* file, /*!< in: file where to print */
322
const void* buf, /*!< in: memory buffer */
323
ulint len); /*!< in: length of the buffer */
231
FILE* file, /* in: file where to print */
232
const void* buf, /* in: memory buffer */
233
ulint len); /* in: length of the buffer */
325
/**********************************************************************//**
235
/**************************************************************************
326
236
Outputs a NUL-terminated file name, quoted with apostrophes. */
329
239
ut_print_filename(
330
240
/*==============*/
331
FILE* f, /*!< in: output stream */
332
const char* name); /*!< in: name to print */
241
FILE* f, /* in: output stream */
242
const char* name); /* in: name to print */
334
#ifndef UNIV_HOTBACKUP
335
244
/* Forward declaration of transaction handle */
336
245
struct trx_struct;
338
/**********************************************************************//**
247
/**************************************************************************
339
248
Outputs a fixed-length string, quoted as an SQL identifier.
340
249
If the string contains a slash '/', the string will be
341
250
output as two identifiers separated by a period (.),
362
FILE* f, /*!< in: output stream */
363
struct trx_struct*trx, /*!< in: transaction (NULL=no quotes) */
364
ibool table_id,/*!< in: TRUE=print a table name,
271
FILE* f, /* in: output stream */
272
struct trx_struct*trx, /* in: transaction (NULL=no quotes) */
273
ibool table_id,/* in: TRUE=print a table name,
365
274
FALSE=print other identifier */
366
const char* name, /*!< in: name to print */
367
ulint namelen);/*!< in: length of name */
275
const char* name, /* in: name to print */
276
ulint namelen);/* in: length of name */
369
/**********************************************************************//**
278
/**************************************************************************
370
279
Catenate files. */
375
FILE* dest, /*!< in: output file */
376
FILE* src); /*!< in: input file to be appended to output */
377
#endif /* !UNIV_HOTBACKUP */
284
FILE* dest, /* in: output file */
285
FILE* src); /* in: input file to be appended to output */
287
/**************************************************************************
380
/**********************************************************************//**
381
A substitute for snprintf(3), formatted output conversion into
383
@return number of characters that would have been printed if the size
384
were unlimited, not including the terminating '\0'. */
389
char* str, /*!< out: string */
390
size_t size, /*!< in: str size */
391
const char* fmt, /*!< in: format */
392
...); /*!< in: format values */
293
/* out: number of characters that would
294
have been printed if the size were
295
unlimited, not including the terminating
297
char* str, /* out: string */
298
size_t size, /* in: str size */
299
const char* fmt, /* in: format */
300
...); /* in: format values */
394
/**********************************************************************//**
395
A wrapper for snprintf(3), formatted output conversion into
397
# define ut_snprintf snprintf
302
#define ut_snprintf snprintf
398
303
#endif /* __WIN__ */
400
/*************************************************************//**
401
Convert an error number to a human readable text message. The
402
returned string is static and should not be freed or modified.
403
@return string, describing the error */
408
enum db_err num); /*!< in: error number */
410
305
#ifndef UNIV_NONINL
411
306
#include "ut0ut.ic"