1
/**********************************************************************
4
(c) 1994, 1995 Innobase Oy
6
Created 1/20/1994 Heikki Tuuri
7
***********************************************************************/
18
#define TEMP_INDEX_PREFIX '\377' /* Index name prefix in fast index
21
typedef time_t ib_time_t;
23
/*************************************************************************
24
Delays execution for at most max_wait_us microseconds or returns earlier
25
if cond becomes true; cond is evaluated every 2 ms. */
27
#define UT_WAIT_FOR(cond, max_wait_us) \
30
start_us = ut_time_us(NULL); \
32
&& ut_time_us(NULL) - start_us < (max_wait_us)) {\
34
os_thread_sleep(2000 /* 2 ms */); \
38
/************************************************************
39
Gets the high 32 bits in a ulint. That is makes a shift >> 32,
40
but since there seem to be compiler bugs in both gcc and Visual C++,
41
we do this by a special conversion. */
47
ulint a); /* in: ulint */
48
/**********************************************************
49
Calculates the minimum of two ulints. */
55
ulint n1, /* in: first number */
56
ulint n2); /* in: second number */
57
/**********************************************************
58
Calculates the maximum of two ulints. */
64
ulint n1, /* in: first number */
65
ulint n2); /* in: second number */
66
/********************************************************************
67
Calculates minimum of two ulint-pairs. */
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. */
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. */
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. */
101
#define ut_is_2pow(n) UNIV_LIKELY(!((n) & ((n) - 1)))
102
/*****************************************************************
103
Calculates fast the remainder of n/m when m is a power of two. */
104
#define ut_2pow_remainder(n, m) ((n) & ((m) - 1))
105
/*****************************************************************
106
Calculates the biggest multiple of m that is not bigger than n
107
when m is a power of two. In other words, rounds n down to m * k. */
108
#define ut_2pow_round(n, m) ((n) & ~((m) - 1))
109
#define ut_calc_align_down(n, m) ut_2pow_round(n, m)
110
/************************************************************
111
Calculates the smallest multiple of m that is not smaller than n
112
when m is a power of two. In other words, rounds n up to m * k. */
113
#define ut_calc_align(n, m) (((n) + ((m) - 1)) & ~((m) - 1))
114
/*****************************************************************
115
Calculates fast the 2-logarithm of a number, rounded upward to an
121
/* out: logarithm in the base 2, rounded upward */
122
ulint n); /* in: number */
123
/*****************************************************************
124
Calculates 2 to power 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. */
137
/* out: first power of 2 which is >= n */
138
ulint n) /* in: number != 0 */
139
__attribute__((const));
141
/* Determine how many bytes (groups of 8 bits) are needed to
142
store the given number of bits. */
143
#define UT_BITS_IN_BYTES(b) (((b) + 7) / 8)
145
/**************************************************************
146
Returns system time. We do not specify the format of the time returned:
147
the only way to manipulate it is to use the function ut_difftime. */
152
/**************************************************************
153
Returns system time. */
158
ulint* sec, /* out: seconds since the Epoch */
159
ulint* ms); /* out: microseconds since the Epoch+*sec */
161
/**************************************************************
162
Returns the number of microseconds since epoch. Similar to
163
time(3), the return value is also stored in *tloc, provided
164
that tloc is non-NULL. */
169
/* out: us since epoch */
170
ullint* tloc); /* out: us since epoch, if non-NULL */
172
/**************************************************************
173
Returns the difference of two times in seconds. */
178
/* out: time2 - time1 expressed in seconds */
179
ib_time_t time2, /* in: time */
180
ib_time_t time1); /* in: time */
181
/**************************************************************
182
Prints a timestamp to a file. */
187
FILE* file); /* in: file where to print */
188
/**************************************************************
189
Sprintfs a timestamp to a buffer, 13..14 chars plus terminating NUL. */
192
ut_sprintf_timestamp(
193
/*=================*/
194
char* buf); /* in: buffer where to sprintf */
195
/**************************************************************
196
Sprintfs a timestamp to a buffer with no spaces and with ':' characters
200
ut_sprintf_timestamp_without_extra_chars(
201
/*=====================================*/
202
char* buf); /* in: buffer where to sprintf */
203
/**************************************************************
204
Returns current year, month, day. */
207
ut_get_year_month_day(
208
/*==================*/
209
ulint* year, /* out: current year */
210
ulint* month, /* out: month */
211
ulint* day); /* out: day */
212
/*****************************************************************
213
Runs an idle loop on CPU. The argument gives the desired delay
214
in microseconds on 100 MHz Pentium + Visual C++. */
219
/* out: dummy value */
220
ulint delay); /* in: delay in microseconds on 100 MHz Pentium */
221
/*****************************************************************
222
Prints the contents of a memory buffer in hex and ascii. */
227
FILE* file, /* in: file where to print */
228
const void* buf, /* in: memory buffer */
229
ulint len); /* in: length of the buffer */
231
/**************************************************************************
232
Outputs a NUL-terminated file name, quoted with apostrophes. */
237
FILE* f, /* in: output stream */
238
const char* name); /* in: name to print */
240
/* Forward declaration of transaction handle */
243
/**************************************************************************
244
Outputs a fixed-length string, quoted as an SQL identifier.
245
If the string contains a slash '/', the string will be
246
output as two identifiers separated by a period (.),
247
as in SQL database_name.identifier. */
252
FILE* f, /* in: output stream */
253
struct trx_struct*trx, /* in: transaction */
254
ibool table_id,/* in: TRUE=print a table name,
255
FALSE=print other identifier */
256
const char* name); /* in: name to print */
258
/**************************************************************************
259
Outputs a fixed-length string, quoted as an SQL identifier.
260
If the string contains a slash '/', the string will be
261
output as two identifiers separated by a period (.),
262
as in SQL database_name.identifier. */
267
FILE* f, /* in: output stream */
268
struct trx_struct*trx, /* in: transaction (NULL=no quotes) */
269
ibool table_id,/* in: TRUE=print a table name,
270
FALSE=print other identifier */
271
const char* name, /* in: name to print */
272
ulint namelen);/* in: length of name */
274
/**************************************************************************
280
FILE* dest, /* in: output file */
281
FILE* src); /* in: input file to be appended to output */
283
/**************************************************************************
289
/* out: number of characters that would
290
have been printed if the size were
291
unlimited, not including the terminating
293
char* str, /* out: string */
294
size_t size, /* in: str size */
295
const char* fmt, /* in: format */
296
...); /* in: format values */
298
#define ut_snprintf snprintf