自旋锁
标签(空格分隔): innodb
简介
Innodb中大量使用自旋锁来避免锁等待时的上下文切换,影响性能的问题。自旋锁分为加锁和解锁两个过程,其中加锁分为尝试加锁与自旋的过程。
数据结构解析
其上层调用方式一般为如下:
mutex_enter(&trx->undo_mutex);
mutex_enter宏定义如下
#define mutex_enter(M) (M)->enter( \
srv_n_spin_wait_rounds, \
srv_spin_wait_delay, \
__FILE__, __LINE__)
所以根据不同的mutex类型,有不同的实现。有点类似与C++中的多态。
而如上示例中的undo_mutex定义如下
UndoMutex undo_mutex; /*!< mutex protecting the fields in this
section (down to undo_no_arr), EXCEPT
last_sql_stat_start, which can be
accessed only when we know that there
cannot be any activity in the undo
logs! */
UndoMutex的声明为
typedef ib

本文介绍了InnoDB存储引擎中自旋锁的使用,以避免锁等待时的上下文切换,提高性能。详细解析了自旋锁的数据结构,包括mutex_enter宏、UndoMutex、ib_mutex_t等,并探讨了try_lock和spin_lock的调用流程,特别是TAS宏和原子操作在加锁过程中的作用。
订阅专栏 解锁全文
207

被折叠的 条评论
为什么被折叠?



