您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

MySQL 源码中的 ut_a 、 ut_ad

bubuko 2022/1/25 20:09:52 mysql 字数 1899 阅读 1158 来源 http://www.bubuko.com/infolist-5-1.html

在 中,可以看到如下宏 可见, 是在开启 UNIV_DEBUG 下的 ,`ut_d` 是开启 UNIV_DEBUG 下才执行 EXPR;当 UNIV_DEBUG 关闭时, EXPR 均不执行。 例子如下,在开启 UNIV_DEBUG 时,会执行 和 ,并且会在其返回值为 0 时报错。 ...

ut0dbg.h 中,可以看到如下宏

#ifdef UNIV_DEBUG
/** Debug assertion. Does nothing unless UNIV_DEBUG is defined. */
#define ut_ad(EXPR) ut_a(EXPR)
/** Debug statement. Does nothing unless UNIV_DEBUG is defined. */
#define ut_d(EXPR) EXPR
#else
/** Debug assertion. Does nothing unless UNIV_DEBUG is defined. */
#define ut_ad(EXPR)
/** Debug statement. Does nothing unless UNIV_DEBUG is defined. */
#define ut_d(EXPR)
#endif

可见, ut_ad 是在开启 UNIV_DEBUG 下的 ut_aut_d 是开启 UNIV_DEBUG 下才执行 EXPR;当 UNIV_DEBUG 关闭时, EXPR 均不执行。

/** Abort execution if EXPR does not evaluate to nonzero.
@param EXPR assertion expression that should hold */
#define ut_a(EXPR)                                                 do {                                                               if (UNIV_UNLIKELY(!(ulint)(EXPR))) {                               ut_dbg_assertion_failed(#EXPR, __FILE__, (ulint)__LINE__);     }                                                              } while (0)
/* Tell the compiler that cond is unlikely to hold */
#define UNIV_UNLIKELY(cond) UNIV_EXPECT(cond, FALSE)

例子如下,在开启 UNIV_DEBUG 时,会执行 lock_mutex_own()trx_mutex_own(),并且会在其返回值为 0 时报错。

const trx_t *DeadlockChecker::check_and_resolve(const lock_t *lock,
                                                trx_t *trx) {
  ut_ad(lock_mutex_own());
  ut_ad(trx_mutex_own(trx));
  check_trx_state(trx);
  ut_ad(!srv_read_only_mode);

MySQL 源码中的 ut_a 、 ut_ad

原文:https://www.cnblogs.com/Forgenvueory/p/12372330.html


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶