95#define LW_FLAG_HAS_WAITERS ((uint32) 1 << 31)
96#define LW_FLAG_WAKE_IN_PROGRESS ((uint32) 1 << 30)
97#define LW_FLAG_LOCKED ((uint32) 1 << 29)
99#define LW_FLAG_MASK (((1<<LW_FLAG_BITS)-1)<<(32-LW_FLAG_BITS))
102#define LW_VAL_EXCLUSIVE (MAX_BACKENDS + 1)
103#define LW_VAL_SHARED 1
106#define LW_SHARED_MASK MAX_BACKENDS
107#define LW_LOCK_MASK (MAX_BACKENDS | LW_VAL_EXCLUSIVE)
111 "MAX_BACKENDS + 1 needs to be a power of 2");
114 "MAX_BACKENDS and LW_FLAG_MASK overlap");
117 "LW_VAL_EXCLUSIVE and LW_FLAG_MASK overlap");
137#define PG_LWLOCK(id, lockname) [id] = CppAsString(lockname),
138#define PG_LWLOCKTRANCHE(id, lockname) [LWTRANCHE_##id] = CppAsString(lockname),
141#undef PG_LWLOCKTRANCHE
146 "missing entries in BuiltinTrancheNames[]");
169#define MAX_SIMUL_LWLOCKS 200
205#define MAX_NAMED_TRANCHES 256
212#define T_NAME(lock) \
213 GetLWTrancheName((lock)->tranche)
250 errmsg_internal(
"%d: %s(%s %p): excl %u shared %u haswaiters %u waiters %u waking %d",
271 T_NAME(lock), lock, msg)));
276#define PRINT_LWDEBUG(a,b,c) ((void)0)
277#define LOG_LWDEBUG(a,b,c) ((void)0)
335 "PID %d lwlock %s %p: shacq %u exacq %u blk %u spindelay %u dequeue self %u\n",
361 MemSet(&key, 0,
sizeof(key));
370 lwstats->dequeue_self_count = 0;
541 for (
j = 0;
j <
request->num_lwlocks;
j++, lock++)
587 elog(
ERROR,
"requested tranche is not registered");
604 errmsg(
"tranche name cannot be NULL")));
609 errmsg(
"tranche name too long"),
610 errdetail(
"LWLock tranche names must be no longer than %d bytes.",
623 (
errmsg(
"maximum number of tranches already registered"),
624 errdetail(
"No more than %d tranches may be registered.",
628 result = (*LWLockCounter)++;
656 elog(
FATAL,
"cannot request additional LWLocks outside shmem_request_hook");
661 errmsg(
"tranche name cannot be NULL")));
666 errmsg(
"tranche name too long"),
667 errdetail(
"LWLock tranche names must be no longer than %d bytes.",
691 request->num_lwlocks = num_lwlocks;
907 lwstats->spin_delay_count += delays;
1020 LOG_LWDEBUG(
"LWLockRelease", lock,
"release waiter");
1053 elog(
PANIC,
"cannot wait without a PGPROC structure");
1056 elog(
PANIC,
"queueing for lock while waiting on another one");
1097 lwstats->dequeue_self_count++;
1246 LOG_LWDEBUG(
"LWLockAcquire", lock,
"immediately acquired lock");
1270 LOG_LWDEBUG(
"LWLockAcquire", lock,
"acquired, undoing queue");
1375 LOG_LWDEBUG(
"LWLockConditionalAcquire", lock,
"failed");
1449 LOG_LWDEBUG(
"LWLockAcquireOrWait", lock,
"waiting");
1479 LOG_LWDEBUG(
"LWLockAcquireOrWait", lock,
"awakened");
1483 LOG_LWDEBUG(
"LWLockAcquireOrWait", lock,
"acquired, undoing queue");
1505 LOG_LWDEBUG(
"LWLockAcquireOrWait", lock,
"failed");
1511 LOG_LWDEBUG(
"LWLockAcquireOrWait", lock,
"succeeded");
1598 bool result =
false;
1653 LOG_LWDEBUG(
"LWLockWaitForVar", lock,
"free, undoing queue");
1698 LOG_LWDEBUG(
"LWLockWaitForVar", lock,
"awakened");
1853 LOG_LWDEBUG(
"LWLockRelease", lock,
"releasing waiters");
1937 begin = (
char *) lock;
1938 end = begin + nlocks *
stride;
static uint32 pg_atomic_fetch_and_u32(volatile pg_atomic_uint32 *ptr, uint32 and_)
static bool pg_atomic_compare_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 *expected, uint32 newval)
static uint32 pg_atomic_fetch_or_u32(volatile pg_atomic_uint32 *ptr, uint32 or_)
static uint32 pg_atomic_sub_fetch_u32(volatile pg_atomic_uint32 *ptr, int32 sub_)
static uint32 pg_atomic_fetch_sub_u32(volatile pg_atomic_uint32 *ptr, int32 sub_)
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
#define pg_write_barrier()
static uint32 pg_atomic_fetch_add_u32(volatile pg_atomic_uint32 *ptr, int32 add_)
static uint32 pg_atomic_read_u32(volatile pg_atomic_uint32 *ptr)
static uint64 pg_atomic_read_u64(volatile pg_atomic_uint64 *ptr)
static uint64 pg_atomic_exchange_u64(volatile pg_atomic_uint64 *ptr, uint64 newval)
#define PG_USED_FOR_ASSERTS_ONLY
#define Assert(condition)
#define MemSet(start, val, len)
#define StaticAssertDecl(condition, errmessage)
#define fprintf(file, fmt, msg)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, int64 nelem, const HASHCTL *info, int flags)
void * hash_seq_search(HASH_SEQ_STATUS *status)
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
int errcode(int sqlerrcode)
int int errhidestmt(bool hide_stmt)
int errdetail(const char *fmt,...) pg_attribute_printf(1
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
int errhidecontext(bool hide_ctx)
#define ereport(elevel,...)
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
void LWLockUpdateVar(LWLock *lock, pg_atomic_uint64 *valptr, uint64 val)
static void LWLockWakeup(LWLock *lock)
bool LWLockHeldByMe(LWLock *lock)
static int LocalLWLockCounter
static LWLockHandle held_lwlocks[MAX_SIMUL_LWLOCKS]
void LWLockReleaseClearVar(LWLock *lock, pg_atomic_uint64 *valptr, uint64 val)
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
int LWLockNewTrancheId(const char *name)
static bool LWLockAttemptLock(LWLock *lock, LWLockMode mode)
static void LWLockWaitListLock(LWLock *lock)
LWLockPadded * GetNamedLWLockTranche(const char *tranche_name)
bool LWLockHeldByMeInMode(LWLock *lock, LWLockMode mode)
static void LWLockReportWaitEnd(void)
char ** LWLockTrancheNames
bool LWLockWaitForVar(LWLock *lock, pg_atomic_uint64 *valptr, uint64 oldval, uint64 *newval)
static const char * GetLWTrancheName(uint16 trancheId)
int NamedLWLockTrancheRequests
void RequestNamedLWLockTranche(const char *tranche_name, int num_lwlocks)
#define LW_FLAG_HAS_WAITERS
#define MAX_SIMUL_LWLOCKS
static int NumLWLocksForNamedTranches(void)
void LWLockRelease(LWLock *lock)
static NamedLWLockTrancheRequest * LocalNamedLWLockTrancheRequestArray
static int num_held_lwlocks
void LWLockReleaseAll(void)
static void InitializeLWLocks(void)
void LWLockInitialize(LWLock *lock, int tranche_id)
static const char *const BuiltinTrancheNames[]
NamedLWLockTrancheRequest * NamedLWLockTrancheRequestArray
static void LWLockWaitListUnlock(LWLock *lock)
#define LOG_LWDEBUG(a, b, c)
bool LWLockConditionalAcquire(LWLock *lock, LWLockMode mode)
bool LWLockAcquireOrWait(LWLock *lock, LWLockMode mode)
static void LWLockQueueSelf(LWLock *lock, LWLockMode mode)
#define PRINT_LWDEBUG(a, b, c)
static void LWLockReportWaitStart(LWLock *lock)
LWLockPadded * MainLWLockArray
#define LW_FLAG_WAKE_IN_PROGRESS
const char * GetLWLockIdentifier(uint32 classId, uint16 eventId)
static void LWLockDequeueSelf(LWLock *lock)
Size LWLockShmemSize(void)
bool LWLockAnyHeldByMe(LWLock *lock, int nlocks, size_t stride)
#define MAX_NAMED_TRANCHES
static bool LWLockConflictsWithVar(LWLock *lock, pg_atomic_uint64 *valptr, uint64 oldval, uint64 *newval, bool *result)
void InitLWLockAccess(void)
#define LWLOCK_PADDED_SIZE
#define BUFFER_MAPPING_LWLOCK_OFFSET
#define NUM_LOCK_PARTITIONS
@ LWTRANCHE_FIRST_USER_DEFINED
#define LOCK_MANAGER_LWLOCK_OFFSET
#define NUM_BUFFER_PARTITIONS
#define PREDICATELOCK_MANAGER_LWLOCK_OFFSET
#define NUM_FIXED_LWLOCKS
#define NUM_PREDICATELOCK_PARTITIONS
void * MemoryContextAlloc(MemoryContext context, Size size)
void * repalloc(void *pointer, Size size)
MemoryContext TopMemoryContext
void MemoryContextDelete(MemoryContext context)
void MemoryContextAllowInCriticalSection(MemoryContext context, bool allow)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define RESUME_INTERRUPTS()
#define HOLD_INTERRUPTS()
bool process_shmem_requests_in_progress
static uint32 pg_nextpower2_32(uint32 num)
static PgChecksumMode mode
size_t strlcpy(char *dst, const char *src, size_t siz)
void PGSemaphoreUnlock(PGSemaphore sema)
void PGSemaphoreLock(PGSemaphore sema)
#define GetPGProcByNumber(n)
#define proclist_delete(list, procno, link_member)
static void proclist_init(proclist_head *list)
#define proclist_push_tail(list, procno, link_member)
#define proclist_push_head(list, procno, link_member)
#define proclist_foreach_modify(iter, lhead, link_member)
static bool proclist_is_empty(const proclist_head *list)
void perform_spin_delay(SpinDelayStatus *status)
void finish_spin_delay(SpinDelayStatus *status)
#define init_local_spin_delay(status)
Size add_size(Size s1, Size s2)
Size mul_size(Size s1, Size s2)
void * ShmemAlloc(Size size)
static void SpinLockRelease(volatile slock_t *lock)
static void SpinLockAcquire(volatile slock_t *lock)
char tranche_name[NAMEDATALEN]
static void pgstat_report_wait_start(uint32 wait_event_info)
static void pgstat_report_wait_end(void)
static TimestampTz wakeup[NUM_WALRCV_WAKEUPS]