⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spin.c

📁 PostgreSQL7.4.6 for Linux
💻 C
字号:
/*------------------------------------------------------------------------- * * spin.c *	   Hardware-independent implementation of spinlocks. * * * For machines that have test-and-set (TAS) instructions, s_lock.h/.c * define the spinlock implementation.	This file contains only a stub * implementation for spinlocks using PGSemaphores.  Unless semaphores * are implemented in a way that doesn't involve a kernel call, this * is too slow to be very useful :-( * * * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * * IDENTIFICATION *	  $Header: /cvsroot/pgsql/src/backend/storage/lmgr/spin.c,v 1.11 2003/08/04 02:40:03 momjian Exp $ * *------------------------------------------------------------------------- */#include "postgres.h"#include "storage/lwlock.h"#include "storage/pg_sema.h"#include "storage/spin.h"#ifdef HAS_TEST_AND_SET/* * Report number of semaphores needed to support spinlocks. */intSpinlockSemas(void){	return 0;}#else							/* !HAS_TEST_AND_SET *//* * No TAS, so spinlocks are implemented as PGSemaphores. *//* * Report number of semaphores needed to support spinlocks. */intSpinlockSemas(void){	/*	 * It would be cleaner to distribute this logic into the affected	 * modules, similar to the way shmem space estimation is handled.	 *	 * For now, though, we just need a few spinlocks (10 should be plenty)	 * plus one for each LWLock.	 */	return NumLWLocks() + 10;}/* * s_lock.h hardware-spinlock emulation */voids_init_lock_sema(volatile slock_t *lock){	PGSemaphoreCreate((PGSemaphore) lock);}voids_unlock_sema(volatile slock_t *lock){	PGSemaphoreUnlock((PGSemaphore) lock);}bools_lock_free_sema(volatile slock_t *lock){	/* We don't currently use S_LOCK_FREE anyway */	elog(ERROR, "spin.c does not support S_LOCK_FREE()");	return false;}inttas_sema(volatile slock_t *lock){	/* Note that TAS macros return 0 if *success* */	return !PGSemaphoreTryLock((PGSemaphore) lock);}#endif   /* !HAS_TEST_AND_SET */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -