91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

PostgreSQL 源碼解讀(218)- spinlock的實現

發布時間:2020-08-11 08:46:41 來源:ITPUB博客 閱讀:146 作者:husthxd 欄目:關系型數據庫

本節介紹了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_SET
typedef 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__ int
tas(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__ void
spin_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__ int
tas(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中的鎖

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

平潭县| 临汾市| 禹州市| 息烽县| 云龙县| 清涧县| 奉新县| 内丘县| 田东县| 柏乡县| 临高县| 商城县| 花莲市| 诸城市| 平陆县| 九江县| 南江县| 阿克| 濉溪县| 瓮安县| 阳高县| 枣阳市| 沅陵县| 延川县| 昭苏县| 昌平区| 荃湾区| 旅游| 博湖县| 思茅市| 甘孜县| 德庆县| 永泰县| 朔州市| 岚皋县| 郴州市| 尚志市| 南木林县| 佛学| 始兴县| 山阴县|