drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
ut0ut.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (C) 1994, 2010, Innobase Oy. All Rights Reserved.
4Copyright (C) 2009 Sun Microsystems, Inc.
5
6Portions of this file contain modifications contributed and copyrighted by
7Sun Microsystems, Inc. Those modifications are gratefully acknowledged and
8are described briefly in the InnoDB documentation. The contributions by
9Sun Microsystems are incorporated with their permission, and subject to the
10conditions contained in the file COPYING.Sun_Microsystems.
11
12This program is free software; you can redistribute it and/or modify it under
13the terms of the GNU General Public License as published by the Free Software
14Foundation; version 2 of the License.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License along with
21this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
22St, Fifth Floor, Boston, MA 02110-1301 USA
23
24*****************************************************************************/
25
26/******************************************************************/
32
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'
53#define TEMP_INDEX_PREFIX_STR "\377"
54
56typedef 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) \
87do { \
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/********************************************************/
103UNIV_INTERN
104ulint
106/*==========*/
107 ulint a);
108/******************************************************/
111UNIV_INLINE
112ulint
114/*===*/
115 ulint n1,
116 ulint n2);
117/******************************************************/
120UNIV_INLINE
121ulint
123/*===*/
124 ulint n1,
125 ulint n2);
126/****************************************************************/
128UNIV_INLINE
129void
131/*========*/
132 ulint* a,
133 ulint* b,
134 ulint a1,
135 ulint b1,
136 ulint a2,
137 ulint b2);
138/******************************************************/
141UNIV_INLINE
142int
144/*=========*/
145 ulint a,
146 ulint b);
147/*******************************************************/
150UNIV_INLINE
151int
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))
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/*************************************************************/
192UNIV_INLINE
193ulint
195/*=====*/
196 ulint n);
197/*************************************************************/
200UNIV_INLINE
201ulint
203/*=====*/
204 ulint n);
205/*************************************************************/
208UNIV_INTERN
209ulint
211/*==========*/
212 ulint n)
213 __attribute__((const));
214
219#define UT_BITS_IN_BYTES(b) (((b) + 7) / 8)
220
221/**********************************************************/
225UNIV_INTERN
227ut_time(void);
228/*=========*/
229#ifndef UNIV_HOTBACKUP
230/**********************************************************/
236UNIV_INTERN
237int
239/*========*/
240 ulint* sec,
241 ulint* ms);
242
243/**********************************************************/
248UNIV_INTERN
249ullint
251/*=======*/
252 ullint* tloc);
253/**********************************************************/
258UNIV_INTERN
259ulint
260ut_time_ms(void);
261/*============*/
262#endif /* !UNIV_HOTBACKUP */
263
264/**********************************************************/
267UNIV_INTERN
268double
270/*========*/
271 ib_time_t time2,
272 ib_time_t time1);
273/**********************************************************/
275UNIV_INTERN
276void
278/*===============*/
279 FILE* file);
280/**********************************************************/
282UNIV_INTERN
283void
285/*=================*/
286 char* buf);
287#ifdef UNIV_HOTBACKUP
288/**********************************************************/
291UNIV_INTERN
292void
293ut_sprintf_timestamp_without_extra_chars(
294/*=====================================*/
295 char* buf);
296/**********************************************************/
298UNIV_INTERN
299void
300ut_get_year_month_day(
301/*==================*/
302 ulint* year,
303 ulint* month,
304 ulint* day);
305#else /* UNIV_HOTBACKUP */
306/*************************************************************/
310UNIV_INTERN
311ulint
313/*=====*/
314 ulint delay);
315#endif /* UNIV_HOTBACKUP */
316/*************************************************************/
318UNIV_INTERN
319void
321/*=========*/
322 FILE* file,
323 const void* buf,
324 ulint len);
325
326/**********************************************************************/
328UNIV_INTERN
329void
331/*==============*/
332 FILE* f,
333 const char* name);
334
335#ifndef UNIV_HOTBACKUP
336/* Forward declaration of transaction handle */
337struct trx_struct;
338
339/**********************************************************************/
344UNIV_INTERN
345void
347/*==========*/
348 FILE* f,
349 struct trx_struct*trx,
350 ibool table_id,
352 const char* name);
353
354/**********************************************************************/
359UNIV_INTERN
360void
362/*===========*/
363 FILE* f,
364 struct trx_struct*trx,
365 ibool table_id,
367 const char* name,
368 ulint namelen);
369
370/**********************************************************************/
372UNIV_INTERN
373void
375/*=========*/
376 FILE* dest,
377 FILE* src);
378#endif /* !UNIV_HOTBACKUP */
379
380#ifdef __WIN__
381/**********************************************************************/
386UNIV_INTERN
387int
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/*************************************************************/
405UNIV_INTERN
406const char*
408/*======*/
409 enum db_err num);
410
411#ifndef UNIV_NONINL
412#include "ut0ut.ic"
413#endif
414
415#endif
416
db_err
Definition db0err.h:31
table_id_t table_id
Definition trx0trx.h:556
UNIV_INTERN ulint ut_2_power_up(ulint n) __attribute__((const))
UNIV_INTERN ulint ut_time_ms(void)
Definition ut0ut.cc:211
UNIV_INTERN ib_time_t ut_time(void)
Definition ut0ut.cc:130
UNIV_INTERN void ut_print_buf(FILE *file, const void *buf, ulint len)
Definition ut0ut.cc:436
UNIV_INLINE ulint ut_min(ulint n1, ulint n2)
UNIV_INTERN int ut_usectime(ulint *sec, ulint *ms)
Definition ut0ut.cc:145
UNIV_INTERN void ut_print_timestamp(FILE *file)
Definition ut0ut.cc:239
UNIV_INTERN void ut_print_name(FILE *f, struct trx_struct *trx, ibool table_id, const char *name)
Definition ut0ut.cc:520
UNIV_INTERN ulint ut_delay(ulint delay)
Definition ut0ut.cc:411
UNIV_INLINE int ut_pair_cmp(ulint a1, ulint a2, ulint b1, ulint b2)
#define ut_snprintf
Definition ut0ut.h:398
UNIV_INLINE void ut_pair_min(ulint *a, ulint *b, ulint a1, ulint b1, ulint a2, ulint b2)
UNIV_INTERN void ut_sprintf_timestamp(char *buf)
Definition ut0ut.cc:282
UNIV_INTERN void ut_copy_file(FILE *dest, FILE *src)
Definition ut0ut.cc:565
UNIV_INTERN void ut_print_namel(FILE *f, struct trx_struct *trx, ibool table_id, const char *name, ulint namelen)
Definition ut0ut.cc:538
UNIV_INTERN ulint ut_get_high32(ulint a)
Definition ut0ut.cc:111
UNIV_INLINE ulint ut_max(ulint n1, ulint n2)
UNIV_INLINE ulint ut_2_log(ulint n)
UNIV_INLINE ulint ut_2_exp(ulint n)
UNIV_INTERN void ut_print_filename(FILE *f, const char *name)
Definition ut0ut.cc:491
UNIV_INTERN ullint ut_time_us(ullint *tloc)
Definition ut0ut.cc:186
UNIV_INLINE int ut_ulint_cmp(ulint a, ulint b)
UNIV_INTERN const char * ut_strerr(enum db_err num)
Definition ut0ut.cc:636
UNIV_INTERN double ut_difftime(ib_time_t time2, ib_time_t time1)
Definition ut0ut.cc:227
time_t ib_time_t
Definition ut0ut.h:56