Drizzled Public API Documentation

ut0ut.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003 Copyright (C) 1994, 2010, Innobase Oy. All Rights Reserved.
00004 Copyright (C) 2009 Sun Microsystems, Inc.
00005 
00006 Portions of this file contain modifications contributed and copyrighted by
00007 Sun Microsystems, Inc. Those modifications are gratefully acknowledged and
00008 are described briefly in the InnoDB documentation. The contributions by
00009 Sun Microsystems are incorporated with their permission, and subject to the
00010 conditions contained in the file COPYING.Sun_Microsystems.
00011 
00012 This program is free software; you can redistribute it and/or modify it under
00013 the terms of the GNU General Public License as published by the Free Software
00014 Foundation; version 2 of the License.
00015 
00016 This program is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License along with
00021 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
00022 St, Fifth Floor, Boston, MA 02110-1301 USA
00023 
00024 *****************************************************************************/
00025 
00026 /******************************************************************/
00033 #pragma once
00034 #ifndef ut0ut_h
00035 #define ut0ut_h
00036 
00037 #include "univ.i"
00038 
00039 #include "db0err.h"
00040 
00041 #ifndef UNIV_HOTBACKUP
00042 # include "os0sync.h" /* for HAVE_ATOMIC_BUILTINS */
00043 #endif /* UNIV_HOTBACKUP */
00044 
00045 #include <time.h>
00046 #ifndef MYSQL_SERVER
00047 #include <ctype.h>
00048 #endif
00049 
00051 #define TEMP_INDEX_PREFIX '\377'
00052 
00053 #define TEMP_INDEX_PREFIX_STR "\377"
00054 
00056 typedef time_t  ib_time_t;
00057 
00058 #ifndef UNIV_HOTBACKUP
00059 #if defined(HAVE_IB_PAUSE_INSTRUCTION)
00060 #  ifdef WIN32
00061      /* In the Win32 API, the x86 PAUSE instruction is executed by calling
00062      the YieldProcessor macro defined in WinNT.h. It is a CPU architecture-
00063      independent way by using YieldProcessor.*/
00064 #    define UT_RELAX_CPU() YieldProcessor()
00065 #  else
00066      /* According to the gcc info page, asm volatile means that the
00067      instruction has important side-effects and must not be removed.
00068      Also asm volatile may trigger a memory barrier (spilling all registers
00069      to memory). */
00070 #    define UT_RELAX_CPU() __asm__ __volatile__ ("pause")
00071 #  endif
00072 #elif defined(HAVE_ATOMIC_BUILTINS)
00073 #  define UT_RELAX_CPU() do { \
00074      volatile lint  volatile_var; \
00075      if (os_compare_and_swap_lint(&volatile_var, 0, 1)) ((void)0); \
00076    } while (0)
00077 #else
00078 #  define UT_RELAX_CPU() ((void)0) /* avoid warning for an empty statement */
00079 #endif
00080 
00081 /*********************************************************************/
00086 #define UT_WAIT_FOR(cond, max_wait_us)        \
00087 do {                \
00088   ullint  start_us;         \
00089   start_us = ut_time_us(NULL);        \
00090   while (!(cond)            \
00091          && ut_time_us(NULL) - start_us < (max_wait_us)) {\
00092                 \
00093     os_thread_sleep(2000 /* 2 ms */);   \
00094   }             \
00095 } while (0)
00096 #endif /* !UNIV_HOTBACKUP */
00097 
00098 /********************************************************/
00103 UNIV_INTERN
00104 ulint
00105 ut_get_high32(
00106 /*==========*/
00107   ulint a); 
00108 /******************************************************/
00111 UNIV_INLINE
00112 ulint
00113 ut_min(
00114 /*===*/
00115   ulint  n1,  
00116   ulint  n2); 
00117 /******************************************************/
00120 UNIV_INLINE
00121 ulint
00122 ut_max(
00123 /*===*/
00124   ulint  n1,  
00125   ulint  n2); 
00126 /****************************************************************/
00128 UNIV_INLINE
00129 void
00130 ut_pair_min(
00131 /*========*/
00132   ulint*  a,  
00133   ulint*  b,  
00134   ulint a1, 
00135   ulint b1, 
00136   ulint a2, 
00137   ulint b2);  
00138 /******************************************************/
00141 UNIV_INLINE
00142 int
00143 ut_ulint_cmp(
00144 /*=========*/
00145   ulint a,  
00146   ulint b); 
00147 /*******************************************************/
00150 UNIV_INLINE
00151 int
00152 ut_pair_cmp(
00153 /*========*/
00154   ulint a1, 
00155   ulint a2, 
00156   ulint b1, 
00157   ulint b2);  
00158 /*************************************************************/
00162 #define ut_is_2pow(n) UNIV_LIKELY(!((n) & ((n) - 1)))
00163 /*************************************************************/
00168 #define ut_2pow_remainder(n, m) ((n) & ((m) - 1))
00169 /*************************************************************/
00175 #define ut_2pow_round(n, m) ((n) & ~((m) - 1))
00176 
00180 #define ut_calc_align_down(n, m) ut_2pow_round(n, m)
00181 /********************************************************/
00187 #define ut_calc_align(n, m) (((n) + ((m) - 1)) & ~((m) - 1))
00188 /*************************************************************/
00192 UNIV_INLINE
00193 ulint
00194 ut_2_log(
00195 /*=====*/
00196   ulint n); 
00197 /*************************************************************/
00200 UNIV_INLINE
00201 ulint
00202 ut_2_exp(
00203 /*=====*/
00204   ulint n); 
00205 /*************************************************************/
00208 UNIV_INTERN
00209 ulint
00210 ut_2_power_up(
00211 /*==========*/
00212   ulint n)  
00213   __attribute__((const));
00214 
00219 #define UT_BITS_IN_BYTES(b) (((b) + 7) / 8)
00220 
00221 /**********************************************************/
00225 UNIV_INTERN
00226 ib_time_t
00227 ut_time(void);
00228 /*=========*/
00229 #ifndef UNIV_HOTBACKUP
00230 /**********************************************************/
00236 UNIV_INTERN
00237 int
00238 ut_usectime(
00239 /*========*/
00240   ulint*  sec,  
00241   ulint*  ms);  
00243 /**********************************************************/
00248 UNIV_INTERN
00249 ullint
00250 ut_time_us(
00251 /*=======*/
00252   ullint* tloc);  
00253 /**********************************************************/
00258 UNIV_INTERN
00259 ulint
00260 ut_time_ms(void);
00261 /*============*/
00262 #endif /* !UNIV_HOTBACKUP */
00263 
00264 /**********************************************************/
00267 UNIV_INTERN
00268 double
00269 ut_difftime(
00270 /*========*/
00271   ib_time_t time2,  
00272   ib_time_t time1); 
00273 /**********************************************************/
00275 UNIV_INTERN
00276 void
00277 ut_print_timestamp(
00278 /*===============*/
00279   FILE*  file); 
00280 /**********************************************************/
00282 UNIV_INTERN
00283 void
00284 ut_sprintf_timestamp(
00285 /*=================*/
00286   char* buf); 
00287 #ifdef UNIV_HOTBACKUP
00288 /**********************************************************/
00291 UNIV_INTERN
00292 void
00293 ut_sprintf_timestamp_without_extra_chars(
00294 /*=====================================*/
00295   char* buf); 
00296 /**********************************************************/
00298 UNIV_INTERN
00299 void
00300 ut_get_year_month_day(
00301 /*==================*/
00302   ulint*  year, 
00303   ulint*  month,  
00304   ulint*  day); 
00305 #else /* UNIV_HOTBACKUP */
00306 /*************************************************************/
00310 UNIV_INTERN
00311 ulint
00312 ut_delay(
00313 /*=====*/
00314   ulint delay); 
00315 #endif /* UNIV_HOTBACKUP */
00316 /*************************************************************/
00318 UNIV_INTERN
00319 void
00320 ut_print_buf(
00321 /*=========*/
00322   FILE*   file, 
00323   const void* buf,  
00324   ulint   len); 
00326 /**********************************************************************/
00328 UNIV_INTERN
00329 void
00330 ut_print_filename(
00331 /*==============*/
00332   FILE*   f,  
00333   const char* name);  
00335 #ifndef UNIV_HOTBACKUP
00336 /* Forward declaration of transaction handle */
00337 struct trx_struct;
00338 
00339 /**********************************************************************/
00344 UNIV_INTERN
00345 void
00346 ut_print_name(
00347 /*==========*/
00348   FILE*   f,  
00349   struct trx_struct*trx,  
00350   ibool   table_id,
00352   const char* name);  
00354 /**********************************************************************/
00359 UNIV_INTERN
00360 void
00361 ut_print_namel(
00362 /*===========*/
00363   FILE*   f,  
00364   struct trx_struct*trx,  
00365   ibool   table_id,
00367   const char* name, 
00368   ulint   namelen);
00370 /**********************************************************************/
00372 UNIV_INTERN
00373 void
00374 ut_copy_file(
00375 /*=========*/
00376   FILE* dest, 
00377   FILE* src); 
00378 #endif /* !UNIV_HOTBACKUP */
00379 
00380 #ifdef __WIN__
00381 /**********************************************************************/
00386 UNIV_INTERN
00387 int
00388 ut_snprintf(
00389 /*========*/
00390   char*   str,  
00391   size_t    size, 
00392   const char* fmt,  
00393   ...);     
00394 #else
00395 /**********************************************************************/
00398 # define ut_snprintf  snprintf
00399 #endif /* __WIN__ */
00400 
00401 /*************************************************************/
00405 UNIV_INTERN
00406 const char*
00407 ut_strerr(
00408 /*======*/
00409   enum db_err num); 
00411 #ifndef UNIV_NONINL
00412 #include "ut0ut.ic"
00413 #endif
00414 
00415 #endif
00416