postgresql/src
Heikki Linnakangas 3c0fd64fec Split ProcSleep function into JoinWaitQueue and ProcSleep
Split ProcSleep into two functions: JoinWaitQueue and ProcSleep.
JoinWaitQueue is called while holding the partition lock, and inserts
the current process to the wait queue, while ProcSleep() does the
actual sleeping. ProcSleep() is now called without holding the
partition lock, and it no longer re-acquires the partition lock before
returning. That makes the wakeup a little cheaper. Once upon a time,
re-acquiring the partition lock was needed to prevent a signal handler
from longjmping out at a bad time, but these days our signal handlers
just set flags, and longjmping can only happen at points where we
explicitly run CHECK_FOR_INTERRUPTS().

If JoinWaitQueue detects an "early deadlock" before even joining the
wait queue, it returns without changing the shared lock entry, leaving
the cleanup of the shared lock entry to the caller. This makes the
handling of an early deadlock the same as the dontWait=true case.

One small user-visible side-effect of this refactoring is that we now
only set the 'ps' title to say "waiting" when we actually enter the
sleep, not when the lock is skipped because dontWait=true, or when a
deadlock is detected early before entering the sleep.

This eliminates the 'lockAwaited' global variable in proc.c, which was
largely redundant with 'awaitedLock' in lock.c

Note: Updating the local lock table is now the caller's responsibility.
JoinWaitQueue and ProcSleep are now only responsible for modifying the
shared state. Seems a little nicer that way.

Based on Thomas Munro's earlier patch and observation that ProcSleep
doesn't really need to re-acquire the partition lock.

Reviewed-by: Maxim Orlov
Discussion: https://www.postgresql.org/message-id/7c2090cd-a72a-4e34-afaa-6dd2ef31440e@iki.fi
2024-11-04 17:59:24 +02:00
..
backend Split ProcSleep function into JoinWaitQueue and ProcSleep 2024-11-04 17:59:24 +02:00
bin pg_combinebackup: Error if incremental file exists in full backup. 2024-11-04 10:11:05 -05:00
common Optimize sifting down in binaryheap. 2024-10-30 11:28:34 -05:00
fe_utils pg_verifybackup: Verify tar-format backups. 2024-09-27 08:40:24 -04:00
include Split ProcSleep function into JoinWaitQueue and ProcSleep 2024-11-04 17:59:24 +02:00
interfaces Fix incorrect struct reference in comment 2024-10-23 16:13:28 +02:00
makefiles Add -Wmissing-variable-declarations to the standard compilation flags 2024-08-03 11:51:02 +02:00
pl Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
port Fix overflow in bsearch_arg() with more than INT_MAX elements 2024-10-28 14:07:38 +02:00
template thread-safety: gmtime_r(), localtime_r() 2024-08-23 07:43:04 +02:00
test Add PG_TEST_EXTRA configure option to the Make builds 2024-11-04 14:09:38 +02:00
timezone Update time zone data files to tzdata release 2024b. 2024-10-29 11:49:38 -04:00
tools Make PG_TEST_EXTRA env var override the "meson setup" option 2024-11-04 14:09:25 +02:00
tutorial
.gitignore
DEVELOPERS
Makefile
Makefile.global.in Add PG_TEST_EXTRA configure option to the Make builds 2024-11-04 14:09:38 +02:00
Makefile.shlib Remove AIX support 2024-02-28 15:17:23 +04:00
meson.build
nls-global.mk