nginx › src ›
crypto.c ›
ngx_crypto_spin_wait()
80/* 自旋等待:x86 用 PAUSE 降低流水线开销 */
81
82static ngx_int_t
83ngx_crypto_spin_wait(ngx_atomic_t *lock, ngx_uint_t spin)
84{
85 for ( ;; ) {
86 while (spin--) {
87 _mm_pause();
87 __asm__ volatile("yield" ::: "memory");
88 }
89
90 if (ngx_atomic_cmp_set(lock, 0, 1)) {
91 return NGX_OK;
92 }
93 }
94}
仅高亮变化的 token —— 一眼看出"到底动了什么"
Impact Compatibility Fixed · Perf +3%