Drizzled Public API Documentation

ut0ut.h File Reference
#include "univ.i"
#include "db0err.h"
#include "os0sync.h"
#include <time.h>
#include <ctype.h>

Go to the source code of this file.

Macros

#define ut0ut_h
#define TEMP_INDEX_PREFIX   '\377'
#define TEMP_INDEX_PREFIX_STR   "\377"
#define UT_RELAX_CPU()   ((void)0) /* avoid warning for an empty statement */
#define UT_WAIT_FOR(cond, max_wait_us)
#define ut_is_2pow(n)   UNIV_LIKELY(!((n) & ((n) - 1)))
#define ut_2pow_remainder(n, m)   ((n) & ((m) - 1))
#define ut_2pow_round(n, m)   ((n) & ~(typeof(n))((m) - 1))
#define ut_calc_align_down(n, m)   ut_2pow_round(n, m)
#define ut_calc_align(n, m)   (((n) + ((m) - 1)) & ~(typeof(n))((m) - 1))
#define UT_BITS_IN_BYTES(b)   (((b) + 7) / 8)
#define ut_snprintf   snprintf

Typedefs

typedef time_t ib_time_t

Functions

UNIV_INTERN ulint ut_get_high32 (ulint a)
UNIV_INLINE ulint ut_min (ulint n1, ulint n2)
UNIV_INLINE ulint ut_max (ulint n1, ulint n2)
UNIV_INLINE void ut_pair_min (ulint *a, ulint *b, ulint a1, ulint b1, ulint a2, ulint b2)
UNIV_INLINE int ut_ulint_cmp (ulint a, ulint b)
UNIV_INLINE int ut_pair_cmp (ulint a1, ulint a2, ulint b1, ulint b2)
UNIV_INLINE ulint ut_2_log (ulint n)
UNIV_INLINE ulint ut_2_exp (ulint n)
UNIV_INTERN ulint ut_2_power_up (ulint n) __attribute__((const ))
UNIV_INTERN ib_time_t ut_time (void)
UNIV_INTERN int ut_usectime (ulint *sec, ulint *ms)
UNIV_INTERN ullint ut_time_us (ullint *tloc)
UNIV_INTERN ulint ut_time_ms (void)
UNIV_INTERN double ut_difftime (ib_time_t time2, ib_time_t time1)
UNIV_INTERN void ut_print_timestamp (FILE *file)
UNIV_INTERN void ut_sprintf_timestamp (char *buf)
UNIV_INTERN ulint ut_delay (ulint delay)
UNIV_INTERN void ut_print_buf (FILE *file, const void *buf, ulint len)
UNIV_INTERN void ut_print_filename (FILE *f, const char *name)
UNIV_INTERN void ut_print_name (FILE *f, struct trx_struct *trx, ibool table_id, const char *name)
UNIV_INTERN void ut_print_namel (FILE *f, struct trx_struct *trx, ibool table_id, const char *name, ulint namelen)
UNIV_INTERN void ut_copy_file (FILE *dest, FILE *src)
UNIV_INTERN const char * ut_strerr (enum db_err num)

Detailed Description

Various utilities

Created 1/20/1994 Heikki Tuuri

Definition in file ut0ut.h.

Macro Definition Documentation

#define TEMP_INDEX_PREFIX   '\377'

Index name prefix in fast index creation

Definition at line 51 of file ut0ut.h.

Referenced by innobase_convert_name(), and lock_rec_insert_check_and_lock().

#define TEMP_INDEX_PREFIX_STR   "\377"

Index name prefix in fast index creation, as a string constant

Definition at line 53 of file ut0ut.h.

#define ut_2pow_remainder (   n,
 
)    ((n) & ((m) - 1))

Calculates fast the remainder of n/m when m is a power of two.

Parameters
nin: numerator
min: denominator, must be a power of two
Returns
the remainder of n/m

Definition at line 168 of file ut0ut.h.

#define ut_2pow_round (   n,
 
)    ((n) & ~(typeof(n))((m) - 1))

Calculates the biggest multiple of m that is not bigger than n when m is a power of two. In other words, rounds n down to m * k.

Parameters
nin: number to round down
min: alignment, must be a power of two
Returns
n rounded down to the biggest possible integer multiple of m

Definition at line 175 of file ut0ut.h.

Referenced by os_mem_alloc_large().

#define UT_BITS_IN_BYTES (   b)    (((b) + 7) / 8)
Determine how many bytes (groups of 8 bits) are needed to

store the given number of bits.

Parameters
bin: bits
Returns
number of bytes (octets) needed to represent b

Definition at line 219 of file ut0ut.h.

Referenced by dict_index_calc_min_rec_len(), ibuf_bitmap_page_init(), rec_convert_dtuple_to_rec_comp(), rec_copy_prefix_to_buf(), rec_get_converted_size_comp_prefix(), rec_get_n_extern_new(), rec_get_offsets_reverse(), and rec_init_offsets_comp_ordinary().

#define ut_calc_align (   n,
 
)    (((n) + ((m) - 1)) & ~(typeof(n))((m) - 1))

Calculates the smallest multiple of m that is not smaller than n when m is a power of two. In other words, rounds n up to m * k.

Parameters
nin: number to round up
min: alignment, must be a power of two
Returns
n rounded up to the smallest possible integer multiple of m

Definition at line 187 of file ut0ut.h.

Referenced by log_write_up_to().

#define ut_calc_align_down (   n,
 
)    ut_2pow_round(n, m)
Align a number down to a multiple of a power of two.
Parameters
nin: number to round down
min: alignment, must be a power of two
Returns
n rounded down to the biggest possible integer multiple of m

Definition at line 180 of file ut0ut.h.

Referenced by log_write_up_to().

#define ut_is_2pow (   n)    UNIV_LIKELY(!((n) & ((n) - 1)))

Determines if a number is zero or a power of two.

Parameters
nin: number
Returns
nonzero if n is zero or a power of two; zero otherwise

Definition at line 162 of file ut0ut.h.

Referenced by buf_flush_init_for_writing(), buf_page_get_gen(), fil_io(), fil_reset_too_high_lsns(), ha_create_func(), hash_create_mutexes_func(), ibuf_bitmap_page_init(), ibuf_insert(), mem_area_free(), os_mem_alloc_large(), and row_ext_create().

#define ut_snprintf   snprintf

A wrapper for snprintf(3), formatted output conversion into a limited buffer.

Definition at line 398 of file ut0ut.h.

Referenced by row_raw_format(), and trx_i_s_create_lock_id().

#define UT_WAIT_FOR (   cond,
  max_wait_us 
)
Value:
do { \
ullint start_us; \
start_us = ut_time_us(NULL); \
while (!(cond) \
&& ut_time_us(NULL) - start_us < (max_wait_us)) {\
\
os_thread_sleep(2000 /* 2 ms */); \
} \
} while (0)

Delays execution for at most max_wait_us microseconds or returns earlier if cond becomes true.

Parameters
condin: condition to wait for; evaluated every 2 ms
max_wait_usin: maximum delay to wait, in microseconds

Definition at line 86 of file ut0ut.h.

Referenced by srv_conc_enter_innodb().

Typedef Documentation

typedef time_t ib_time_t

Time stamp

Definition at line 56 of file ut0ut.h.

Function Documentation

UNIV_INLINE ulint ut_2_exp ( ulint  n)

Calculates 2 to power n.

Returns
2 to power n in: number

Referenced by mem_area_alloc(), mem_area_free(), mem_pool_create(), mem_pool_print_info(), and mem_pool_validate().

UNIV_INLINE ulint ut_2_log ( ulint  n)

Calculates fast the 2-logarithm of a number, rounded upward to an integer.

Returns
logarithm in the base 2, rounded upward in: number

Referenced by mem_area_alloc(), mem_area_free(), and mem_pool_create().

UNIV_INTERN ulint ut_2_power_up ( ulint  n) const

Calculates fast the number rounded up to the nearest power of 2.

Returns
first power of 2 which is >= n
Parameters
nin: number != 0
UNIV_INTERN void ut_copy_file ( FILE *  dest,
FILE *  src 
)

Catenate files. in: input file to be appended to output

Catenate files.

Parameters
destin: output file
srcin: input file to be appended to output

Definition at line 580 of file ut0ut.cc.

References ut_copy_file().

Referenced by lock_print_info_summary(), srv_printf_innodb_monitor(), and ut_copy_file().

UNIV_INTERN ulint ut_delay ( ulint  delay)

Runs an idle loop on CPU. The argument gives the desired delay in microseconds on 100 MHz Pentium + Visual C++.

Returns
dummy value in: delay in microseconds on 100 MHz Pentium

Runs an idle loop on CPU. The argument gives the desired delay in microseconds on 100 MHz Pentium + Visual C++.

Returns
dummy value
Parameters
delayin: delay in microseconds on 100 MHz Pentium

Definition at line 426 of file ut0ut.cc.

References ut_delay().

Referenced by rw_lock_x_lock_func(), and ut_delay().

UNIV_INTERN double ut_difftime ( ib_time_t  time2,
ib_time_t  time1 
)

Returns the difference of two times in seconds.

Returns
time2 - time1 expressed in seconds in: time

Returns the difference of two times in seconds.

Returns
time2 - time1 expressed in seconds
Parameters
time2in: time
time1in: time

Definition at line 242 of file ut0ut.cc.

References ut_difftime().

Referenced by srv_lock_timeout_thread(), srv_suspend_mysql_thread(), and ut_difftime().

UNIV_INTERN ulint ut_get_high32 ( ulint  a)

Gets the high 32 bits in a ulint. That is makes a shift >> 32, but since there seem to be compiler bugs in both gcc and Visual C++, we do this by a special conversion.

Returns
a >> 32 in: ulint

Gets the high 32 bits in a ulint. That is makes a shift >> 32, but since there seem to be compiler bugs in both gcc and Visual C++, we do this by a special conversion.

Returns
a >> 32
Parameters
ain: ulint

Definition at line 126 of file ut0ut.cc.

References ut_get_high32().

Referenced by ut_get_high32().

UNIV_INLINE ulint ut_max ( ulint  n1,
ulint  n2 
)

Calculates the maximum of two ulints.

Returns
maximum in: second number
Parameters
n1in: first number

Referenced by mem_area_alloc(), and row_create_index_for_mysql().

UNIV_INLINE ulint ut_min ( ulint  n1,
ulint  n2 
)

Calculates the minimum of two ulints.

Returns
minimum in: second number
Parameters
n1in: first number

Referenced by buf_read_ahead_linear(), fil_extend_space_to_desired_size(), ha_create_func(), ibuf_init_at_db_start(), os_file_set_size(), row_raw_format(), srv_master_thread(), srv_purge_thread(), ut_strlcpy(), and ut_strlcpy_rev().

UNIV_INLINE int ut_pair_cmp ( ulint  a1,
ulint  a2,
ulint  b1,
ulint  b2 
)

Compares two pairs of ulints.

Returns
-1 if a < b, 0 if a == b, 1 if a > b in: less significant part of second pair
Parameters
a1in: more significant part of first pair
a2in: less significant part of first pair
b1in: more significant part of second pair
UNIV_INLINE void ut_pair_min ( ulint *  a,
ulint *  b,
ulint  a1,
ulint  b1,
ulint  a2,
ulint  b2 
)

Calculates minimum of two ulint-pairs. in: less significant part of second pair

Parameters
aout: more significant part of minimum
bout: less significant part of minimum
a1in: more significant part of first pair
b1in: less significant part of first pair
a2in: more significant part of second pair

Referenced by page_cur_search_with_match().

UNIV_INTERN void ut_print_buf ( FILE *  file,
const void *  buf,
ulint  len 
)

Prints the contents of a memory buffer in hex and ascii. in: length of the buffer

Prints the contents of a memory buffer in hex and ascii.

Parameters
filein: file where to print
bufin: memory buffer
lenin: length of the buffer

Definition at line 451 of file ut0ut.cc.

References ut_print_buf().

Referenced by btr_pcur_restore_position_func(), buf_flush_init_for_writing(), buf_flush_ready_for_replace(), buf_page_print(), ha_innobase::doInsertRecord(), mem_analyze_corruption(), os_fast_mutex_free(), page_cur_parse_insert_rec(), rec_print_comp(), rec_print_old(), row_fetch_print(), row_sel_convert_mysql_key_to_innobase(), trx_free(), trx_undo_prev_version_build(), and ut_print_buf().

UNIV_INTERN void ut_print_filename ( FILE *  f,
const char *  name 
)

Outputs a NUL-terminated file name, quoted with apostrophes. in: name to print

Outputs a NUL-terminated file name, quoted with apostrophes.

Parameters
fin: output stream
namein: name to print

Definition at line 506 of file ut0ut.cc.

References ut_print_filename().

Referenced by dict_check_tablespaces_and_store_max_id(), dict_load_table(), dict_load_table_low(), dict_table_rename_in_cache(), fil_create_new_single_table_tablespace(), fil_delete_tablespace(), fil_load_single_table_tablespaces(), fil_node_create(), fil_open_single_table_tablespace(), fil_rename_tablespace(), fil_reset_too_high_lsns(), fil_space_create(), fil_space_for_table_exists_in_mem(), and ut_print_filename().

UNIV_INTERN void ut_print_name ( FILE *  f,
trx_t trx,
ibool  table_id,
const char *  name 
)

Outputs a fixed-length string, quoted as an SQL identifier. If the string contains a slash '/', the string will be output as two identifiers separated by a period (.), as in SQL database_name.identifier. in: name to print

Outputs a fixed-length string, quoted as an SQL identifier. If the string contains a slash '/', the string will be output as two identifiers separated by a period (.), as in SQL database_name.identifier.

Parameters
fin: output stream
trxin: transaction
table_idin: TRUE=print a table name, FALSE=print other identifier
namein: name to print

Definition at line 535 of file ut0ut.cc.

References ut_print_name(), and ut_print_namel().

Referenced by ha_innobase::check(), dict_foreign_parse_drop_constraints(), dict_index_name_print(), dict_print_info_on_foreign_key_in_create_format(), dict_print_info_on_foreign_keys(), dict_table_remove_from_cache(), dict_table_rename_in_cache(), innobase_rename_table(), lock_table_print(), row_build_row_ref_in_tuple(), row_create_index_for_mysql(), row_create_table_for_mysql(), row_discard_tablespace_for_mysql(), row_drop_database_for_mysql(), row_drop_table_for_mysql(), row_drop_tables_for_mysql_in_background(), row_import_tablespace_for_mysql(), row_ins_check_foreign_constraint(), row_insert_for_mysql(), row_prebuilt_free(), row_rename_table_for_mysql(), row_search_for_mysql(), row_truncate_table_for_mysql(), row_update_for_mysql(), row_update_prebuilt_trx(), trx_rollback_to_savepoint_for_mysql(), trx_undo_update_rec_get_update(), and ut_print_name().

UNIV_INTERN void ut_print_namel ( FILE *  f,
trx_t trx,
ibool  table_id,
const char *  name,
ulint  namelen 
)

Outputs a fixed-length string, quoted as an SQL identifier. If the string contains a slash '/', the string will be output as two identifiers separated by a period (.), as in SQL database_name.identifier. in: length of name

Outputs a fixed-length string, quoted as an SQL identifier. If the string contains a slash '/', the string will be output as two identifiers separated by a period (.), as in SQL database_name.identifier.

Parameters
fin: output stream
trxin: transaction (NULL=no quotes)
table_idin: TRUE=print a table name, FALSE=print other identifier
namein: name to print
namelenin: length of name

Definition at line 553 of file ut0ut.cc.

References innobase_convert_name(), trx_struct::mysql_thd, and ut_print_namel().

Referenced by ut_print_name(), and ut_print_namel().

UNIV_INTERN void ut_print_timestamp ( FILE *  file)

Prints a timestamp to a file. in: file where to print

Prints a timestamp to a file.

Parameters
filein: file where to print

Definition at line 254 of file ut0ut.cc.

References ut_print_timestamp().

Referenced by btr_search_drop_page_hash_index(), buf_flush_init_for_writing(), buf_flush_ready_for_replace(), buf_LRU_file_restore(), buf_LRU_get_free_block(), buf_page_io_complete(), buf_page_is_corrupted(), buf_page_print(), buf_read_ahead_linear(), buf_read_page(), buf_read_page_low(), buf_zip_decompress(), dict_check_tablespaces_and_store_max_id(), dict_foreign_parse_drop_constraints(), dict_load_table(), dict_load_table_low(), dict_print(), dict_table_rename_in_cache(), dict_truncate_index_tree(), dict_update_statistics(), fil_assign_new_space_id(), fil_create_new_single_table_tablespace(), fil_delete_tablespace(), fil_io(), fil_node_create(), fil_open_single_table_tablespace(), fil_rename_tablespace(), fil_reset_too_high_lsns(), fil_space_create(), fil_space_for_table_exists_in_mem(), ha_innobase::innobase_initialize_autoinc(), ha_innobase::innobase_peek_autoinc(), lock_check_trx_id_sanity(), lock_rec_unlock(), log_close(), logs_empty_and_mark_files_at_shutdown(), os_fast_mutex_free(), os_file_create_func(), os_file_create_tmpfile(), os_file_flush_func(), os_file_get_last_error(), os_file_set_nocache(), os_file_write_func(), page_copy_rec_list_end_no_locks(), recv_apply_hashed_log_recs(), row_check_index_for_mysql(), row_create_index_for_mysql(), row_create_table_for_mysql(), row_discard_tablespace_for_mysql(), row_drop_database_for_mysql(), row_drop_table_for_mysql(), row_drop_tables_for_mysql_in_background(), row_import_tablespace_for_mysql(), row_ins_check_foreign_constraint(), row_insert_for_mysql(), row_rename_table_for_mysql(), row_search_for_mysql(), row_sel_convert_mysql_key_to_innobase(), row_truncate_table_for_mysql(), row_update_for_mysql(), srv_conc_enter_innodb(), srv_monitor_thread(), srv_printf_innodb_monitor(), srv_suspend_mysql_thread(), trx_free(), trx_recover_for_mysql(), trx_rollback_or_clean_recovered(), trx_rollback_to_savepoint_for_mysql(), ut_dbg_assertion_failed(), ut_malloc_low(), ut_print_timestamp(), ut_test_malloc(), and ut_usectime().

UNIV_INTERN void ut_sprintf_timestamp ( char *  buf)

Sprintfs a timestamp to a buffer, 13..14 chars plus terminating NUL. in: buffer where to sprintf

Sprintfs a timestamp to a buffer, 13..14 chars plus terminating NUL.

Parameters
bufin: buffer where to sprintf

Definition at line 297 of file ut0ut.cc.

References ut_sprintf_timestamp().

Referenced by ut_sprintf_timestamp().

UNIV_INTERN const char* ut_strerr ( enum db_err  num)

Convert an error number to a human readable text message. The returned string is static and should not be freed or modified.

Returns
string, describing the error in: error number

Convert an error number to a human readable text message. The returned string is static and should not be freed or modified.

Returns
string, describing the error
Parameters
numin: error number

Definition at line 651 of file ut0ut.cc.

References DB_SUCCESS_LOCKED_REC, ut_error, and ut_strerr().

Referenced by ut_strerr().

UNIV_INTERN ib_time_t ut_time ( void  )

Returns system time. We do not specify the format of the time returned: the only way to manipulate it is to use the function ut_difftime.

Returns
system time

Definition at line 145 of file ut0ut.cc.

References ut_time().

Referenced by buf_refresh_io_stats(), srv_lock_timeout_thread(), srv_monitor_thread(), srv_suspend_mysql_thread(), and ut_time().

UNIV_INTERN ulint ut_time_ms ( void  )

Returns the number of milliseconds since some epoch. The value may wrap around. It should only be used for heuristic purposes.

Returns
ms since epoch

Definition at line 226 of file ut0ut.cc.

References ut_time_ms().

Referenced by buf_page_create(), buf_page_get_known_nowait(), srv_master_thread(), srv_purge_thread(), and ut_time_ms().

UNIV_INTERN ullint ut_time_us ( ullint *  tloc)

Returns the number of microseconds since epoch. Similar to time(3), the return value is also stored in *tloc, provided that tloc is non-NULL.

Returns
us since epoch out: us since epoch, if non-NULL

Returns the number of microseconds since epoch. Similar to time(3), the return value is also stored in *tloc, provided that tloc is non-NULL.

Returns
us since epoch
Parameters
tlocout: us since epoch, if non-NULL

Definition at line 201 of file ut0ut.cc.

References ut_time_us().

Referenced by trx_i_s_cache_end_read(), and ut_time_us().

UNIV_INLINE int ut_ulint_cmp ( ulint  a,
ulint  b 
)

Compares two ulints.

Returns
1 if a > b, 0 if a == b, -1 if a < b in: ulint
Parameters
ain: ulint

Referenced by buf_read_ahead_linear().

UNIV_INTERN int ut_usectime ( ulint *  sec,
ulint *  ms 
)

Returns system time. Upon successful completion, the value 0 is returned; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

Returns
0 on success, -1 otherwise out: microseconds since the Epoch+*sec

Returns system time. Upon successful completion, the value 0 is returned; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

Returns
0 on success, -1 otherwise
Parameters
secout: seconds since the Epoch
msout: microseconds since the Epoch+*sec

Definition at line 160 of file ut0ut.cc.

References os_thread_sleep(), ut_print_timestamp(), and ut_usectime().

Referenced by os_event_wait_time_low(), srv_suspend_mysql_thread(), and ut_usectime().