Drizzled Public API Documentation

ut0ut.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (C) 1994, 2010, Innobase Oy. All Rights Reserved.
4 Copyright (C) 2009 Sun Microsystems, Inc.
5 
6 Portions of this file contain modifications contributed and copyrighted by
7 Sun Microsystems, Inc. Those modifications are gratefully acknowledged and
8 are described briefly in the InnoDB documentation. The contributions by
9 Sun Microsystems are incorporated with their permission, and subject to the
10 conditions contained in the file COPYING.Sun_Microsystems.
11 
12 This program is free software; you can redistribute it and/or modify it under
13 the terms of the GNU General Public License as published by the Free Software
14 Foundation; version 2 of the License.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License along with
21 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
22 St, Fifth Floor, Boston, MA 02110-1301 USA
23 
24 *****************************************************************************/
25 
26 /******************************************************************/
33 #pragma once
34 #ifndef ut0ut_h
35 #define ut0ut_h
36 
37 #include "univ.i"
38 
39 #include "db0err.h"
40 
41 #ifndef UNIV_HOTBACKUP
42 # include "os0sync.h" /* for HAVE_ATOMIC_BUILTINS */
43 #endif /* UNIV_HOTBACKUP */
44 
45 #include <time.h>
46 #ifndef MYSQL_SERVER
47 #include <ctype.h>
48 #endif
49 
51 #define TEMP_INDEX_PREFIX '\377'
52 
53 #define TEMP_INDEX_PREFIX_STR "\377"
54 
56 typedef time_t ib_time_t;
57 
58 #ifndef UNIV_HOTBACKUP
59 #if defined(HAVE_PAUSE_INSTRUCTION)
60  /* According to the gcc info page, asm volatile means that the
61  instruction has important side-effects and must not be removed.
62  Also asm volatile may trigger a memory barrier (spilling all registers
63  to memory). */
64 # define UT_RELAX_CPU() __asm__ __volatile__ ("pause")
65 #elif defined(HAVE_FAKE_PAUSE_INSTRUCTION)
66 # define UT_RELAX_CPU() __asm__ __volatile__ ("rep; nop")
67 #elif defined(HAVE_ATOMIC_BUILTINS)
68 # define UT_RELAX_CPU() do { \
69  volatile lint volatile_var; \
70  if (os_compare_and_swap_lint(&volatile_var, 0, 1)) ((void)0); \
71  } while (0)
72 #elif defined(HAVE_WINDOWS_ATOMICS)
73  /* In the Win32 API, the x86 PAUSE instruction is executed by calling
74  the YieldProcessor macro defined in WinNT.h. It is a CPU architecture-
75  independent way by using YieldProcessor. */
76 # define UT_RELAX_CPU() YieldProcessor()
77 #else
78 # define UT_RELAX_CPU() ((void)0) /* avoid warning for an empty statement */
79 #endif
80 
81 /*********************************************************************/
86 #define UT_WAIT_FOR(cond, max_wait_us) \
87 do { \
88  ullint start_us; \
89  start_us = ut_time_us(NULL); \
90  while (!(cond) \
91  && ut_time_us(NULL) - start_us < (max_wait_us)) {\
92  \
93  os_thread_sleep(2000 /* 2 ms */); \
94  } \
95 } while (0)
96 #endif /* !UNIV_HOTBACKUP */
97 
98 /********************************************************/
103 UNIV_INTERN
104 ulint
106 /*==========*/
107  ulint a);
108 /******************************************************/
111 UNIV_INLINE
112 ulint
113 ut_min(
114 /*===*/
115  ulint n1,
116  ulint n2);
117 /******************************************************/
120 UNIV_INLINE
121 ulint
122 ut_max(
123 /*===*/
124  ulint n1,
125  ulint n2);
126 /****************************************************************/
128 UNIV_INLINE
129 void
131 /*========*/
132  ulint* a,
133  ulint* b,
134  ulint a1,
135  ulint b1,
136  ulint a2,
137  ulint b2);
138 /******************************************************/
141 UNIV_INLINE
142 int
144 /*=========*/
145  ulint a,
146  ulint b);
147 /*******************************************************/
150 UNIV_INLINE
151 int
153 /*========*/
154  ulint a1,
155  ulint a2,
156  ulint b1,
157  ulint b2);
158 /*************************************************************/
162 #define ut_is_2pow(n) UNIV_LIKELY(!((n) & ((n) - 1)))
163 /*************************************************************/
168 #define ut_2pow_remainder(n, m) ((n) & ((m) - 1))
169 /*************************************************************/
175 #define ut_2pow_round(n, m) ((n) & ~(typeof(n))((m) - 1))
176 
180 #define ut_calc_align_down(n, m) ut_2pow_round(n, m)
181 /********************************************************/
187 #define ut_calc_align(n, m) (((n) + ((m) - 1)) & ~(typeof(n))((m) - 1))
188 /*************************************************************/
192 UNIV_INLINE
193 ulint
194 ut_2_log(
195 /*=====*/
196  ulint n);
197 /*************************************************************/
200 UNIV_INLINE
201 ulint
202 ut_2_exp(
203 /*=====*/
204  ulint n);
205 /*************************************************************/
208 UNIV_INTERN
209 ulint
211 /*==========*/
212  ulint n)
213  __attribute__((const));
214 
219 #define UT_BITS_IN_BYTES(b) (((b) + 7) / 8)
220 
221 /**********************************************************/
225 UNIV_INTERN
226 ib_time_t
227 ut_time(void);
228 /*=========*/
229 #ifndef UNIV_HOTBACKUP
230 /**********************************************************/
236 UNIV_INTERN
237 int
239 /*========*/
240  ulint* sec,
241  ulint* ms);
243 /**********************************************************/
248 UNIV_INTERN
249 ullint
250 ut_time_us(
251 /*=======*/
252  ullint* tloc);
253 /**********************************************************/
258 UNIV_INTERN
259 ulint
260 ut_time_ms(void);
261 /*============*/
262 #endif /* !UNIV_HOTBACKUP */
263 
264 /**********************************************************/
267 UNIV_INTERN
268 double
270 /*========*/
271  ib_time_t time2,
272  ib_time_t time1);
273 /**********************************************************/
275 UNIV_INTERN
276 void
278 /*===============*/
279  FILE* file);
280 /**********************************************************/
282 UNIV_INTERN
283 void
285 /*=================*/
286  char* buf);
287 #ifdef UNIV_HOTBACKUP
288 /**********************************************************/
291 UNIV_INTERN
292 void
293 ut_sprintf_timestamp_without_extra_chars(
294 /*=====================================*/
295  char* buf);
296 /**********************************************************/
298 UNIV_INTERN
299 void
300 ut_get_year_month_day(
301 /*==================*/
302  ulint* year,
303  ulint* month,
304  ulint* day);
305 #else /* UNIV_HOTBACKUP */
306 /*************************************************************/
310 UNIV_INTERN
311 ulint
312 ut_delay(
313 /*=====*/
314  ulint delay);
315 #endif /* UNIV_HOTBACKUP */
316 /*************************************************************/
318 UNIV_INTERN
319 void
321 /*=========*/
322  FILE* file,
323  const void* buf,
324  ulint len);
326 /**********************************************************************/
328 UNIV_INTERN
329 void
331 /*==============*/
332  FILE* f,
333  const char* name);
335 #ifndef UNIV_HOTBACKUP
336 /* Forward declaration of transaction handle */
337 struct trx_struct;
338 
339 /**********************************************************************/
344 UNIV_INTERN
345 void
347 /*==========*/
348  FILE* f,
349  struct trx_struct*trx,
350  ibool table_id,
352  const char* name);
354 /**********************************************************************/
359 UNIV_INTERN
360 void
362 /*===========*/
363  FILE* f,
364  struct trx_struct*trx,
365  ibool table_id,
367  const char* name,
368  ulint namelen);
370 /**********************************************************************/
372 UNIV_INTERN
373 void
375 /*=========*/
376  FILE* dest,
377  FILE* src);
378 #endif /* !UNIV_HOTBACKUP */
379 
380 #ifdef __WIN__
381 /**********************************************************************/
386 UNIV_INTERN
387 int
389 /*========*/
390  char* str,
391  size_t size,
392  const char* fmt,
393  ...);
394 #else
395 /**********************************************************************/
398 # define ut_snprintf snprintf
399 #endif /* __WIN__ */
400 
401 /*************************************************************/
405 UNIV_INTERN
406 const char*
407 ut_strerr(
408 /*======*/
409  enum db_err num);
411 #ifndef UNIV_NONINL
412 #include "ut0ut.ic"
413 #endif
414 
415 #endif
416 
UNIV_INLINE ulint ut_2_exp(ulint n)
UNIV_INTERN ulint ut_time_ms(void)
Definition: ut0ut.cc:219
time_t ib_time_t
Definition: ut0ut.h:56
UNIV_INTERN void ut_print_namel(FILE *f, struct trx_struct *trx, ibool table_id, const char *name, ulint namelen)
Definition: ut0ut.cc:546
table_id_t table_id
Definition: trx0trx.h:556
UNIV_INTERN ib_time_t ut_time(void)
Definition: ut0ut.cc:138
UNIV_INTERN void ut_print_filename(FILE *f, const char *name)
Definition: ut0ut.cc:499
UNIV_INTERN ulint ut_get_high32(ulint a)
Definition: ut0ut.cc:119
#define ut_snprintf
Definition: ut0ut.h:398
UNIV_INTERN void ut_print_buf(FILE *file, const void *buf, ulint len)
Definition: ut0ut.cc:444
UNIV_INTERN ulint ut_2_power_up(ulint n) __attribute__((const ))
UNIV_INLINE void ut_pair_min(ulint *a, ulint *b, ulint a1, ulint b1, ulint a2, ulint b2)
UNIV_INTERN ullint ut_time_us(ullint *tloc)
Definition: ut0ut.cc:194
UNIV_INLINE ulint ut_min(ulint n1, ulint n2)
db_err
Definition: db0err.h:31
UNIV_INTERN const char * ut_strerr(enum db_err num)
Definition: ut0ut.cc:644
UNIV_INLINE ulint ut_max(ulint n1, ulint n2)
UNIV_INTERN void ut_print_name(FILE *f, struct trx_struct *trx, ibool table_id, const char *name)
Definition: ut0ut.cc:528
UNIV_INTERN void ut_sprintf_timestamp(char *buf)
Definition: ut0ut.cc:290
UNIV_INTERN ulint ut_delay(ulint delay)
Definition: ut0ut.cc:419
UNIV_INTERN int ut_usectime(ulint *sec, ulint *ms)
Definition: ut0ut.cc:153
UNIV_INLINE ulint ut_2_log(ulint n)
UNIV_INTERN void ut_print_timestamp(FILE *file)
Definition: ut0ut.cc:247
UNIV_INLINE int ut_ulint_cmp(ulint a, ulint b)
UNIV_INTERN void ut_copy_file(FILE *dest, FILE *src)
Definition: ut0ut.cc:573
UNIV_INLINE int ut_pair_cmp(ulint a1, ulint a2, ulint b1, ulint b2)
UNIV_INTERN double ut_difftime(ib_time_t time2, ib_time_t time1)
Definition: ut0ut.cc:235