MySQL 源码中的 ut_a 、 ut_ad
在 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_a
,ut_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);
【推荐】100%开源!大型工业跨平台软件C++源码提供,建模,组态!
【推荐】AI 的力量,开发者的翅膀:欢迎使用 AI 原生开发工具 TRAE
【推荐】2025 HarmonyOS 鸿蒙创新赛正式启动,百万大奖等你挑战
【推荐】博客园的心动:当一群程序员决定开源共建一个真诚相亲平台
· 《C#高级GDI+实战:从零开发一个流程图》增加贝塞尔曲线
· AES 加密模式演进:从 ECB、CBC 到 GCM 的 C# 深度实践
· InnoDB为什么不用跳表,Redis为什么不用B+树?
· 记一次 C# 平台调用中因非托管 union 类型导致的内存访问越界
· [EF Core]聊聊“复合”属性
· 博客园众包:再次诚征3D影像景深延拓实时处理方案(预算8-15万,需求有调整)
· 扣子(Coze),开源了!Dify 天塌了
· 精选 5 款 .NET 开源、功能强大的工作流系统,告别重复造轮子!
· 从经典产品看大模型方向
· 终于有人讲明白了!解读Agent 4大协议:MCP/ACP/A2A/ANP