MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ut0ut.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1994, 2012, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free Software
7 Foundation; version 2 of the License.
8 
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along with
14 this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16 
17 *****************************************************************************/
18 
19 /******************************************************************/
26 #ifndef ut0ut_h
27 #define ut0ut_h
28 
29 #include "univ.i"
30 
31 #ifndef UNIV_INNOCHECKSUM
32 
33 #include "db0err.h"
34 
35 #ifndef UNIV_HOTBACKUP
36 # include "os0sync.h" /* for HAVE_ATOMIC_BUILTINS */
37 #endif /* UNIV_HOTBACKUP */
38 
39 #include <time.h>
40 #ifndef MYSQL_SERVER
41 #include <ctype.h>
42 #endif
43 
44 #include <stdarg.h> /* for va_list */
45 
47 #define TEMP_INDEX_PREFIX '\377'
48 
49 #define TEMP_INDEX_PREFIX_STR "\377"
50 
52 typedef time_t ib_time_t;
53 
54 #ifndef UNIV_HOTBACKUP
55 # if defined(HAVE_PAUSE_INSTRUCTION)
56  /* According to the gcc info page, asm volatile means that the
57  instruction has important side-effects and must not be removed.
58  Also asm volatile may trigger a memory barrier (spilling all registers
59  to memory). */
60 # ifdef __SUNPRO_CC
61 # define UT_RELAX_CPU() asm ("pause" )
62 # else
63 # define UT_RELAX_CPU() __asm__ __volatile__ ("pause")
64 # endif /* __SUNPRO_CC */
65 
66 # elif defined(HAVE_FAKE_PAUSE_INSTRUCTION)
67 # define UT_RELAX_CPU() __asm__ __volatile__ ("rep; nop")
68 # elif defined(HAVE_ATOMIC_BUILTINS)
69 # define UT_RELAX_CPU() do { \
70  volatile lint volatile_var; \
71  os_compare_and_swap_lint(&volatile_var, 0, 1); \
72  } while (0)
73 # elif defined(HAVE_WINDOWS_ATOMICS)
74  /* In the Win32 API, the x86 PAUSE instruction is executed by calling
75  the YieldProcessor macro defined in WinNT.h. It is a CPU architecture-
76  independent way by using YieldProcessor. */
77 # define UT_RELAX_CPU() YieldProcessor()
78 # else
79 # define UT_RELAX_CPU() ((void)0) /* avoid warning for an empty statement */
80 # endif
81 
82 /*********************************************************************/
87 #define UT_WAIT_FOR(cond, max_wait_us) \
88 do { \
89  ullint start_us; \
90  start_us = ut_time_us(NULL); \
91  while (!(cond) \
92  && ut_time_us(NULL) - start_us < (max_wait_us)) {\
93  \
94  os_thread_sleep(2000 /* 2 ms */); \
95  } \
96 } while (0)
97 #endif /* !UNIV_HOTBACKUP */
98 
99 template <class T> T ut_min(T a, T b) { return(a < b ? a : b); }
100 template <class T> T ut_max(T a, T b) { return(a > b ? a : b); }
101 
102 /******************************************************/
105 UNIV_INLINE
106 ulint
107 ut_min(
108 /*===*/
109  ulint n1,
110  ulint n2);
111 /******************************************************/
114 UNIV_INLINE
115 ulint
116 ut_max(
117 /*===*/
118  ulint n1,
119  ulint n2);
120 /****************************************************************/
122 UNIV_INLINE
123 void
125 /*========*/
126  ulint* a,
127  ulint* b,
128  ulint a1,
129  ulint b1,
130  ulint a2,
131  ulint b2);
132 /******************************************************/
135 UNIV_INLINE
136 int
138 /*=========*/
139  ulint a,
140  ulint b);
141 /*******************************************************/
144 UNIV_INLINE
145 int
147 /*========*/
148  ulint a1,
149  ulint a2,
150  ulint b1,
151  ulint b2);
152 /*************************************************************/
156 #define ut_is_2pow(n) UNIV_LIKELY(!((n) & ((n) - 1)))
157 /*************************************************************/
162 #define ut_2pow_remainder(n, m) ((n) & ((m) - 1))
163 /*************************************************************/
169 #define ut_2pow_round(n, m) ((n) & ~((m) - 1))
170 
174 #define ut_calc_align_down(n, m) ut_2pow_round(n, m)
175 /********************************************************/
181 #define ut_calc_align(n, m) (((n) + ((m) - 1)) & ~((m) - 1))
182 /*************************************************************/
186 UNIV_INLINE
187 ulint
188 ut_2_log(
189 /*=====*/
190  ulint n);
191 /*************************************************************/
194 UNIV_INLINE
195 ulint
196 ut_2_exp(
197 /*=====*/
198  ulint n);
199 /*************************************************************/
202 UNIV_INTERN
203 ulint
205 /*==========*/
206  ulint n)
207  __attribute__((const));
208 
213 #define UT_BITS_IN_BYTES(b) (((b) + 7) / 8)
214 
215 /**********************************************************/
219 UNIV_INTERN
220 ib_time_t
221 ut_time(void);
222 /*=========*/
223 #ifndef UNIV_HOTBACKUP
224 /**********************************************************/
230 UNIV_INTERN
231 int
233 /*========*/
234  ulint* sec,
235  ulint* ms);
237 /**********************************************************/
242 UNIV_INTERN
243 ullint
244 ut_time_us(
245 /*=======*/
246  ullint* tloc);
247 /**********************************************************/
252 UNIV_INTERN
253 ulint
254 ut_time_ms(void);
255 /*============*/
256 #endif /* !UNIV_HOTBACKUP */
257 
258 /**********************************************************/
263 UNIV_INTERN
264 ulint
265 ut_time_ms(void);
266 /*============*/
267 
268 /**********************************************************/
271 UNIV_INTERN
272 double
274 /*========*/
275  ib_time_t time2,
276  ib_time_t time1);
278 #endif /* !UNIV_INNOCHECKSUM */
279 
280 /**********************************************************/
282 UNIV_INTERN
283 void
285 /*===============*/
286  FILE* file)
287  UNIV_COLD __attribute__((nonnull));
288 
289 #ifndef UNIV_INNOCHECKSUM
290 
291 /**********************************************************/
293 UNIV_INTERN
294 void
296 /*=================*/
297  char* buf);
298 #ifdef UNIV_HOTBACKUP
299 /**********************************************************/
302 UNIV_INTERN
303 void
304 ut_sprintf_timestamp_without_extra_chars(
305 /*=====================================*/
306  char* buf);
307 /**********************************************************/
309 UNIV_INTERN
310 void
311 ut_get_year_month_day(
312 /*==================*/
313  ulint* year,
314  ulint* month,
315  ulint* day);
316 #else /* UNIV_HOTBACKUP */
317 /*************************************************************/
321 UNIV_INTERN
322 ulint
323 ut_delay(
324 /*=====*/
325  ulint delay);
326 #endif /* UNIV_HOTBACKUP */
327 /*************************************************************/
329 UNIV_INTERN
330 void
332 /*=========*/
333  FILE* file,
334  const void* buf,
335  ulint len);
337 /**********************************************************************/
339 UNIV_INTERN
340 void
342 /*==============*/
343  FILE* f,
344  const char* name);
346 #ifndef UNIV_HOTBACKUP
347 /* Forward declaration of transaction handle */
348 struct trx_t;
349 
350 /**********************************************************************/
355 UNIV_INTERN
356 void
358 /*==========*/
359  FILE* f,
360  const trx_t* trx,
361  ibool table_id,
363  const char* name);
365 /**********************************************************************/
370 UNIV_INTERN
371 void
373 /*===========*/
374  FILE* f,
375  const trx_t* trx,
376  ibool table_id,
378  const char* name,
379  ulint namelen);
381 /**********************************************************************/
386 UNIV_INTERN
387 char*
389 /*===========*/
390  const char* name,
392  ibool is_table,
394  char* formatted,
396  ulint formatted_size);
399 /**********************************************************************/
401 UNIV_INTERN
402 void
404 /*=========*/
405  FILE* dest,
406  FILE* src);
407 #endif /* !UNIV_HOTBACKUP */
408 
409 #ifdef __WIN__
410 /**********************************************************************/
417 UNIV_INTERN
418 void
420 /*=========*/
421  char* str,
422  size_t size,
423  const char* fmt,
424  va_list ap);
426 /**********************************************************************/
431 UNIV_INTERN
432 int
434 /*========*/
435  char* str,
436  size_t size,
437  const char* fmt,
438  ...);
439 #else
440 /**********************************************************************/
447 # define ut_vsnprintf(buf, size, fmt, ap) \
448  ((void) vsnprintf(buf, size, fmt, ap))
449 /**********************************************************************/
452 # define ut_snprintf snprintf
453 #endif /* __WIN__ */
454 
455 /*************************************************************/
459 UNIV_INTERN
460 const char*
461 ut_strerr(
462 /*======*/
463  dberr_t num);
465 /****************************************************************
466 Sort function for ulint arrays. */
467 UNIV_INTERN
468 void
470 /*==========*/
471  ulint* arr,
472  ulint* aux_arr,
473  ulint low,
474  ulint high)
475  __attribute__((nonnull));
476 
477 #ifndef UNIV_NONINL
478 #include "ut0ut.ic"
479 #endif
480 
481 #endif /* !UNIV_INNOCHECKSUM */
482 
483 #endif
484