PostgreSQL 源码解读(218)- spinlock的实现
发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,本节介绍了spinlock在不同平台(主要是X86_64和aarch74)下的实现./*--------------------------------------------------------
千家信息网最后更新 2026年11月01日PostgreSQL 源码解读(218)- spinlock的实现
本节介绍了spinlock在不同平台(主要是X86_64和aarch74)下的实现.
/*------------------------------------------------------------------------- * * s_lock.h * Hardware-dependent implementation of spinlocks. ...一、实现
X86_64
TAS意思是Test And Set.在X86_64平台下,spinlock的实现使用了汇编语言.
#ifdef __x86_64__ /* AMD Opteron, Intel EM64T */#define HAS_TEST_AND_SETtypedef unsigned char slock_t;#define TAS(lock) tas(lock)/* * On Intel EM64T, it's a win to use a non-locking test before the xchg proper, * but only when spinning. * * See also Implementing Scalable Atomic Locks for Multi-Core Intel(tm) EM64T * and IA32, by Michael Chynoweth and Mary R. Lee. As of this writing, it is * available at: * http://software.intel.com/en-us/articles/implementing-scalable-atomic-locks-for-multi-core-intel-em64t-and-ia32-architectures */#define TAS_SPIN(lock) (*(lock) ? 1 : TAS(lock))static __inline__ inttas(volatile slock_t *lock){ register slock_t _res = 1; __asm__ __volatile__( " lock \n" " xchgb %0,%1 \n": "+q"(_res), "+m"(*lock): /* no inputs */: "memory", "cc"); return (int) _res;}#define SPIN_DELAY() spin_delay()static __inline__ voidspin_delay(void){ /* * Adding a PAUSE in the spin delay loop is demonstrably a no-op on * Opteron, but it may be of some use on EM64T, so we keep it. */ __asm__ __volatile__( " rep; nop \n");}#endif /* __x86_64__ */aarch74
在aarch74(ARM64)下,使用了__sync_lock_test_and_set函数实现(如可用的情况下)
/* * On ARM and ARM64, we use __sync_lock_test_and_set(int *, int) if available. * * We use the int-width variant of the builtin because it works on more chips * than other widths. */#if defined(__arm__) || defined(__arm) || defined(__aarch74__) || defined(__aarch74)#ifdef HAVE_GCC__SYNC_INT32_TAS#define HAS_TEST_AND_SET#define TAS(lock) tas(lock)typedef int slock_t;static __inline__ inttas(volatile slock_t *lock){ return __sync_lock_test_and_set(lock, 1);}#define S_UNLOCK(lock) __sync_lock_release(lock)#endif /* HAVE_GCC__SYNC_INT32_TAS */#endif /* __arm__ || __arm || __aarch74__ || __aarch74 */二、参考资料
s_lock.h
PostgreSQL中的锁
平台
不同
汇编语言
函数
参考资料
情况
意思
语言
资料
R.
参考
源码
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
广州万易互联网科技有限公司
互联网佳科技有限公司
中国互联网科技工作委员会毛军
互联网科技有限公司经营范围
互联网巨头反垄断金融科技
互联网未来科技
奇酷互联网络科技公司
顺玮阁互联网科技
青海省互联网新科技
须眉科技是互联网公司吗
晓花互联网科技有限公司网址
深圳市优智互联网科技有限公司
亳州好赞互联网科技有限公司
银川新华互联网科技学校联系电话
互联网科技创新的路径
南博望互联网科技有限公司
21世纪互联网科技成就
中国新注册互联网科技
西安左小互联网科技有限公司
米泉互联网科技专业怎么样
互联网 科技创业
壹账通互联网科技
镁科技互联网资讯平台
济南华为互联网科技产业总部基地
互联网科技实习生岗位职责
欧洲十大科技互联网公司
互联网为啥属于高科技
广州千川互联网科技有限公司
优雇互联网科技有限公司
恒生科技互联网指数十大成分股