~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/ut0ut.h

  • Committer: Brian Aker
  • Date: 2008-11-04 15:39:09 UTC
  • mfrom: (575.1.2 devel)
  • Revision ID: brian@tangent.org-20081104153909-c72hn65udxs1ccal
Merge of Monty's work

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
#include "univ.i"
13
13
#include <time.h>
14
 
#ifndef DRIZZLE_SERVER
 
14
#ifndef MYSQL_SERVER
15
15
#include <ctype.h>
16
16
#endif
17
17
 
 
18
#define TEMP_INDEX_PREFIX       '\377'  /* Index name prefix in fast index
 
19
                                        creation */
 
20
 
18
21
typedef time_t  ib_time_t;
19
22
 
 
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. */
 
26
 
 
27
#define UT_WAIT_FOR(cond, max_wait_us)                          \
 
28
do {                                                            \
 
29
        ullint  start_us;                                       \
 
30
        start_us = ut_time_us(NULL);                            \
 
31
        while (!(cond)                                          \
 
32
               && ut_time_us(NULL) - start_us < (max_wait_us)) {\
 
33
                                                                \
 
34
                os_thread_sleep(2000 /* 2 ms */);               \
 
35
        }                                                       \
 
36
} while (0)
 
37
 
20
38
/************************************************************
21
39
Gets the high 32 bits in a ulint. That is makes a shift >> 32,
22
40
but since there seem to be compiler bugs in both gcc and Visual C++,
23
41
we do this by a special conversion. */
24
 
 
 
42
UNIV_INTERN
25
43
ulint
26
44
ut_get_high32(
27
45
/*==========*/
79
97
        ulint   b1,     /* in: more significant part of second pair */
80
98
        ulint   b2);    /* in: less significant part of second pair */
81
99
/*****************************************************************
82
 
Calculates fast the remainder when divided by a power of two. */
83
 
UNIV_INLINE
84
 
ulint
85
 
ut_2pow_remainder(
86
 
/*==============*/      /* out: remainder */
87
 
        ulint   n,      /* in: number to be divided */
88
 
        ulint   m);     /* in: divisor; power of 2 */
89
 
/*****************************************************************
90
 
Calculates fast value rounded to a multiple of a power of 2. */
91
 
UNIV_INLINE
92
 
ulint
93
 
ut_2pow_round(
94
 
/*==========*/          /* out: value of n rounded down to nearest
95
 
                        multiple of m */
96
 
        ulint   n,      /* in: number to be rounded */
97
 
        ulint   m);     /* in: divisor; power of 2 */
 
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))
98
114
/*****************************************************************
99
115
Calculates fast the 2-logarithm of a number, rounded upward to an
100
116
integer. */
114
130
        ulint   n);     /* in: number */
115
131
/*****************************************************************
116
132
Calculates fast the number rounded up to the nearest power of 2. */
117
 
 
 
133
UNIV_INTERN
118
134
ulint
119
135
ut_2_power_up(
120
136
/*==========*/
121
137
                        /* out: first power of 2 which is >= n */
122
138
        ulint   n)      /* in: number != 0 */
123
 
        __attribute__((const));
 
139
        __attribute__((__const__));
124
140
 
125
141
/* Determine how many bytes (groups of 8 bits) are needed to
126
142
store the given number of bits. */
127
143
#define UT_BITS_IN_BYTES(b) (((b) + 7) / 8)
128
144
 
129
 
/****************************************************************
130
 
Sort function for ulint arrays. */
131
 
 
132
 
void
133
 
ut_ulint_sort(ulint* arr, ulint* aux_arr, ulint low, ulint high);
134
 
/*============================================================*/
135
 
/************************************************************
136
 
The following function returns elapsed CPU time in milliseconds. */
137
 
 
138
 
ulint
139
 
ut_clock(void);
140
145
/**************************************************************
141
146
Returns system time. We do not specify the format of the time returned:
142
147
the only way to manipulate it is to use the function ut_difftime. */
143
 
 
 
148
UNIV_INTERN
144
149
ib_time_t
145
150
ut_time(void);
146
151
/*=========*/
147
152
/**************************************************************
148
153
Returns system time. */
149
 
 
 
154
UNIV_INTERN
150
155
void
151
156
ut_usectime(
152
157
/*========*/
153
158
        ulint*  sec,    /* out: seconds since the Epoch */
154
159
        ulint*  ms);    /* out: microseconds since the Epoch+*sec */
 
160
 
 
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. */
 
165
UNIV_INTERN
 
166
ullint
 
167
ut_time_us(
 
168
/*=======*/
 
169
                        /* out: us since epoch */
 
170
        ullint* tloc);  /* out: us since epoch, if non-NULL */
 
171
 
155
172
/**************************************************************
156
173
Returns the difference of two times in seconds. */
157
 
 
 
174
UNIV_INTERN
158
175
double
159
176
ut_difftime(
160
177
/*========*/
163
180
        ib_time_t       time1); /* in: time */
164
181
/**************************************************************
165
182
Prints a timestamp to a file. */
166
 
 
 
183
UNIV_INTERN
167
184
void
168
185
ut_print_timestamp(
169
186
/*===============*/
170
187
        FILE*  file); /* in: file where to print */
171
188
/**************************************************************
172
189
Sprintfs a timestamp to a buffer, 13..14 chars plus terminating NUL. */
173
 
 
 
190
UNIV_INTERN
174
191
void
175
192
ut_sprintf_timestamp(
176
193
/*=================*/
178
195
/**************************************************************
179
196
Sprintfs a timestamp to a buffer with no spaces and with ':' characters
180
197
replaced by '_'. */
181
 
 
 
198
UNIV_INTERN
182
199
void
183
200
ut_sprintf_timestamp_without_extra_chars(
184
201
/*=====================================*/
185
202
        char*   buf); /* in: buffer where to sprintf */
186
203
/**************************************************************
187
204
Returns current year, month, day. */
188
 
 
 
205
UNIV_INTERN
189
206
void
190
207
ut_get_year_month_day(
191
208
/*==================*/
195
212
/*****************************************************************
196
213
Runs an idle loop on CPU. The argument gives the desired delay
197
214
in microseconds on 100 MHz Pentium + Visual C++. */
198
 
 
 
215
UNIV_INTERN
199
216
ulint
200
217
ut_delay(
201
218
/*=====*/
203
220
        ulint   delay); /* in: delay in microseconds on 100 MHz Pentium */
204
221
/*****************************************************************
205
222
Prints the contents of a memory buffer in hex and ascii. */
206
 
 
 
223
UNIV_INTERN
207
224
void
208
225
ut_print_buf(
209
226
/*=========*/
213
230
 
214
231
/**************************************************************************
215
232
Outputs a NUL-terminated file name, quoted with apostrophes. */
216
 
 
 
233
UNIV_INTERN
217
234
void
218
235
ut_print_filename(
219
236
/*==============*/
228
245
If the string contains a slash '/', the string will be
229
246
output as two identifiers separated by a period (.),
230
247
as in SQL database_name.identifier. */
231
 
 
 
248
UNIV_INTERN
232
249
void
233
250
ut_print_name(
234
251
/*==========*/
243
260
If the string contains a slash '/', the string will be
244
261
output as two identifiers separated by a period (.),
245
262
as in SQL database_name.identifier. */
246
 
 
 
263
UNIV_INTERN
247
264
void
248
265
ut_print_namel(
249
266
/*===========*/
256
273
 
257
274
/**************************************************************************
258
275
Catenate files. */
259
 
 
 
276
UNIV_INTERN
260
277
void
261
278
ut_copy_file(
262
279
/*=========*/