PostgreSQL Source Code git master
procsignal.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * procsignal.c
4 * Routines for interprocess signaling
5 *
6 *
7 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
9 *
10 * IDENTIFICATION
11 * src/backend/storage/ipc/procsignal.c
12 *
13 *-------------------------------------------------------------------------
14 */
15#include "postgres.h"
16
17#include <signal.h>
18#include <unistd.h>
19
20#include "access/parallel.h"
21#include "commands/async.h"
22#include "miscadmin.h"
23#include "pgstat.h"
24#include "port/pg_bitutils.h"
28#include "storage/ipc.h"
29#include "storage/latch.h"
30#include "storage/shmem.h"
31#include "storage/sinval.h"
32#include "storage/smgr.h"
33#include "tcop/tcopprot.h"
34#include "utils/memutils.h"
35
36/*
37 * The SIGUSR1 signal is multiplexed to support signaling multiple event
38 * types. The specific reason is communicated via flags in shared memory.
39 * We keep a boolean flag for each possible "reason", so that different
40 * reasons can be signaled to a process concurrently. (However, if the same
41 * reason is signaled more than once nearly simultaneously, the process may
42 * observe it only once.)
43 *
44 * Each process that wants to receive signals registers its process ID
45 * in the ProcSignalSlots array. The array is indexed by ProcNumber to make
46 * slot allocation simple, and to avoid having to search the array when you
47 * know the ProcNumber of the process you're signaling. (We do support
48 * signaling without ProcNumber, but it's a bit less efficient.)
49 *
50 * The fields in each slot are protected by a spinlock, pss_mutex. pss_pid can
51 * also be read without holding the spinlock, as a quick preliminary check
52 * when searching for a particular PID in the array.
53 *
54 * pss_signalFlags are intended to be set in cases where we don't need to
55 * keep track of whether or not the target process has handled the signal,
56 * but sometimes we need confirmation, as when making a global state change
57 * that cannot be considered complete until all backends have taken notice
58 * of it. For such use cases, we set a bit in pss_barrierCheckMask and then
59 * increment the current "barrier generation"; when the new barrier generation
60 * (or greater) appears in the pss_barrierGeneration flag of every process,
61 * we know that the message has been received everywhere.
62 */
63typedef struct
64{
66 int pss_cancel_key_len; /* 0 means no cancellation is possible */
67 char pss_cancel_key[MAX_CANCEL_KEY_LENGTH];
68 volatile sig_atomic_t pss_signalFlags[NUM_PROCSIGNALS];
69 slock_t pss_mutex; /* protects the above fields */
70
71 /* Barrier-related fields (not protected by pss_mutex) */
76
77/*
78 * Information that is global to the entire ProcSignal system can be stored
79 * here.
80 *
81 * psh_barrierGeneration is the highest barrier generation in existence.
82 */
84{
87};
88
89/*
90 * We reserve a slot for each possible ProcNumber, plus one for each
91 * possible auxiliary process type. (This scheme assumes there is not
92 * more than one of any auxiliary process type at a time.)
93 */
94#define NumProcSignalSlots (MaxBackends + NUM_AUXILIARY_PROCS)
95
96/* Check whether the relevant type bit is set in the flags. */
97#define BARRIER_SHOULD_CHECK(flags, type) \
98 (((flags) & (((uint32) 1) << (uint32) (type))) != 0)
99
100/* Clear the relevant type bit from the flags. */
101#define BARRIER_CLEAR_BIT(flags, type) \
102 ((flags) &= ~(((uint32) 1) << (uint32) (type)))
103
106
107static bool CheckProcSignal(ProcSignalReason reason);
108static void CleanupProcSignalState(int status, Datum arg);
109static void ResetProcSignalBarrierBits(uint32 flags);
110
111/*
112 * ProcSignalShmemSize
113 * Compute space needed for ProcSignal's shared memory
114 */
115Size
117{
118 Size size;
119
121 size = add_size(size, offsetof(ProcSignalHeader, psh_slot));
122 return size;
123}
124
125/*
126 * ProcSignalShmemInit
127 * Allocate and initialize ProcSignal's shared memory
128 */
129void
131{
132 Size size = ProcSignalShmemSize();
133 bool found;
134
136 ShmemInitStruct("ProcSignal", size, &found);
137
138 /* If we're first, initialize. */
139 if (!found)
140 {
141 int i;
142
144
145 for (i = 0; i < NumProcSignalSlots; ++i)
146 {
148
149 SpinLockInit(&slot->pss_mutex);
150 pg_atomic_init_u32(&slot->pss_pid, 0);
151 slot->pss_cancel_key_len = 0;
152 MemSet(slot->pss_signalFlags, 0, sizeof(slot->pss_signalFlags));
156 }
157 }
158}
159
160/*
161 * ProcSignalInit
162 * Register the current process in the ProcSignal array
163 */
164void
165ProcSignalInit(char *cancel_key, int cancel_key_len)
166{
167 ProcSignalSlot *slot;
168 uint64 barrier_generation;
169 uint32 old_pss_pid;
170
171 Assert(cancel_key_len >= 0 && cancel_key_len <= MAX_CANCEL_KEY_LENGTH);
172 if (MyProcNumber < 0)
173 elog(ERROR, "MyProcNumber not set");
175 elog(ERROR, "unexpected MyProcNumber %d in ProcSignalInit (max %d)", MyProcNumber, NumProcSignalSlots);
177
179
180 /* Value used for sanity check below */
181 old_pss_pid = pg_atomic_read_u32(&slot->pss_pid);
182
183 /* Clear out any leftover signal reasons */
184 MemSet(slot->pss_signalFlags, 0, NUM_PROCSIGNALS * sizeof(sig_atomic_t));
185
186 /*
187 * Initialize barrier state. Since we're a brand-new process, there
188 * shouldn't be any leftover backend-private state that needs to be
189 * updated. Therefore, we can broadcast the latest barrier generation and
190 * disregard any previously-set check bits.
191 *
192 * NB: This only works if this initialization happens early enough in the
193 * startup sequence that we haven't yet cached any state that might need
194 * to be invalidated. That's also why we have a memory barrier here, to be
195 * sure that any later reads of memory happen strictly after this.
196 */
198 barrier_generation =
200 pg_atomic_write_u64(&slot->pss_barrierGeneration, barrier_generation);
201
202 if (cancel_key_len > 0)
203 memcpy(slot->pss_cancel_key, cancel_key, cancel_key_len);
204 slot->pss_cancel_key_len = cancel_key_len;
206
208
209 /* Spinlock is released, do the check */
210 if (old_pss_pid != 0)
211 elog(LOG, "process %d taking over ProcSignal slot %d, but it's not empty",
213
214 /* Remember slot location for CheckProcSignal */
215 MyProcSignalSlot = slot;
216
217 /* Set up to release the slot on process exit */
219}
220
221/*
222 * CleanupProcSignalState
223 * Remove current process from ProcSignal mechanism
224 *
225 * This function is called via on_shmem_exit() during backend shutdown.
226 */
227static void
229{
230 pid_t old_pid;
232
233 /*
234 * Clear MyProcSignalSlot, so that a SIGUSR1 received after this point
235 * won't try to access it after it's no longer ours (and perhaps even
236 * after we've unmapped the shared memory segment).
237 */
238 Assert(MyProcSignalSlot != NULL);
239 MyProcSignalSlot = NULL;
240
241 /* sanity check */
243 old_pid = pg_atomic_read_u32(&slot->pss_pid);
244 if (old_pid != MyProcPid)
245 {
246 /*
247 * don't ERROR here. We're exiting anyway, and don't want to get into
248 * infinite loop trying to exit
249 */
251 elog(LOG, "process %d releasing ProcSignal slot %d, but it contains %d",
252 MyProcPid, (int) (slot - ProcSignal->psh_slot), (int) old_pid);
253 return; /* XXX better to zero the slot anyway? */
254 }
255
256 /* Mark the slot as unused */
257 pg_atomic_write_u32(&slot->pss_pid, 0);
258 slot->pss_cancel_key_len = 0;
259
260 /*
261 * Make this slot look like it's absorbed all possible barriers, so that
262 * no barrier waits block on it.
263 */
265
267
269}
270
271/*
272 * SendProcSignal
273 * Send a signal to a Postgres process
274 *
275 * Providing procNumber is optional, but it will speed up the operation.
276 *
277 * On success (a signal was sent), zero is returned.
278 * On error, -1 is returned, and errno is set (typically to ESRCH or EPERM).
279 *
280 * Not to be confused with ProcSendSignal
281 */
282int
283SendProcSignal(pid_t pid, ProcSignalReason reason, ProcNumber procNumber)
284{
285 volatile ProcSignalSlot *slot;
286
287 if (procNumber != INVALID_PROC_NUMBER)
288 {
289 Assert(procNumber < NumProcSignalSlots);
290 slot = &ProcSignal->psh_slot[procNumber];
291
293 if (pg_atomic_read_u32(&slot->pss_pid) == pid)
294 {
295 /* Atomically set the proper flag */
296 slot->pss_signalFlags[reason] = true;
298 /* Send signal */
299 return kill(pid, SIGUSR1);
300 }
302 }
303 else
304 {
305 /*
306 * procNumber not provided, so search the array using pid. We search
307 * the array back to front so as to reduce search overhead. Passing
308 * INVALID_PROC_NUMBER means that the target is most likely an
309 * auxiliary process, which will have a slot near the end of the
310 * array.
311 */
312 int i;
313
314 for (i = NumProcSignalSlots - 1; i >= 0; i--)
315 {
316 slot = &ProcSignal->psh_slot[i];
317
318 if (pg_atomic_read_u32(&slot->pss_pid) == pid)
319 {
321 if (pg_atomic_read_u32(&slot->pss_pid) == pid)
322 {
323 /* Atomically set the proper flag */
324 slot->pss_signalFlags[reason] = true;
326 /* Send signal */
327 return kill(pid, SIGUSR1);
328 }
330 }
331 }
332 }
333
334 errno = ESRCH;
335 return -1;
336}
337
338/*
339 * EmitProcSignalBarrier
340 * Send a signal to every Postgres process
341 *
342 * The return value of this function is the barrier "generation" created
343 * by this operation. This value can be passed to WaitForProcSignalBarrier
344 * to wait until it is known that every participant in the ProcSignal
345 * mechanism has absorbed the signal (or started afterwards).
346 *
347 * Note that it would be a bad idea to use this for anything that happens
348 * frequently, as interrupting every backend could cause a noticeable
349 * performance hit.
350 *
351 * Callers are entitled to assume that this function will not throw ERROR
352 * or FATAL.
353 */
354uint64
356{
357 uint32 flagbit = 1 << (uint32) type;
358 uint64 generation;
359
360 /*
361 * Set all the flags.
362 *
363 * Note that pg_atomic_fetch_or_u32 has full barrier semantics, so this is
364 * totally ordered with respect to anything the caller did before, and
365 * anything that we do afterwards. (This is also true of the later call to
366 * pg_atomic_add_fetch_u64.)
367 */
368 for (int i = 0; i < NumProcSignalSlots; i++)
369 {
370 volatile ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
371
373 }
374
375 /*
376 * Increment the generation counter.
377 */
378 generation =
380
381 /*
382 * Signal all the processes, so that they update their advertised barrier
383 * generation.
384 *
385 * Concurrency is not a problem here. Backends that have exited don't
386 * matter, and new backends that have joined since we entered this
387 * function must already have current state, since the caller is
388 * responsible for making sure that the relevant state is entirely visible
389 * before calling this function in the first place. We still have to wake
390 * them up - because we can't distinguish between such backends and older
391 * backends that need to update state - but they won't actually need to
392 * change any state.
393 */
394 for (int i = NumProcSignalSlots - 1; i >= 0; i--)
395 {
396 volatile ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
397 pid_t pid = pg_atomic_read_u32(&slot->pss_pid);
398
399 if (pid != 0)
400 {
402 pid = pg_atomic_read_u32(&slot->pss_pid);
403 if (pid != 0)
404 {
405 /* see SendProcSignal for details */
406 slot->pss_signalFlags[PROCSIG_BARRIER] = true;
408 kill(pid, SIGUSR1);
409 }
410 else
412 }
413 }
414
415 return generation;
416}
417
418/*
419 * WaitForProcSignalBarrier - wait until it is guaranteed that all changes
420 * requested by a specific call to EmitProcSignalBarrier() have taken effect.
421 */
422void
424{
426
427 elog(DEBUG1,
428 "waiting for all backends to process ProcSignalBarrier generation "
430 generation);
431
432 for (int i = NumProcSignalSlots - 1; i >= 0; i--)
433 {
435 uint64 oldval;
436
437 /*
438 * It's important that we check only pss_barrierGeneration here and
439 * not pss_barrierCheckMask. Bits in pss_barrierCheckMask get cleared
440 * before the barrier is actually absorbed, but pss_barrierGeneration
441 * is updated only afterward.
442 */
444 while (oldval < generation)
445 {
447 5000,
448 WAIT_EVENT_PROC_SIGNAL_BARRIER))
449 ereport(LOG,
450 (errmsg("still waiting for backend with PID %d to accept ProcSignalBarrier",
451 (int) pg_atomic_read_u32(&slot->pss_pid))));
453 }
455 }
456
457 elog(DEBUG1,
458 "finished waiting for all backends to process ProcSignalBarrier generation "
460 generation);
461
462 /*
463 * The caller is probably calling this function because it wants to read
464 * the shared state or perform further writes to shared state once all
465 * backends are known to have absorbed the barrier. However, the read of
466 * pss_barrierGeneration was performed unlocked; insert a memory barrier
467 * to separate it from whatever follows.
468 */
470}
471
472/*
473 * Handle receipt of an interrupt indicating a global barrier event.
474 *
475 * All the actual work is deferred to ProcessProcSignalBarrier(), because we
476 * cannot safely access the barrier generation inside the signal handler as
477 * 64bit atomics might use spinlock based emulation, even for reads. As this
478 * routine only gets called when PROCSIG_BARRIER is sent that won't cause a
479 * lot of unnecessary work.
480 */
481static void
483{
484 InterruptPending = true;
486 /* latch will be set by procsignal_sigusr1_handler */
487}
488
489/*
490 * Perform global barrier related interrupt checking.
491 *
492 * Any backend that participates in ProcSignal signaling must arrange to
493 * call this function periodically. It is called from CHECK_FOR_INTERRUPTS(),
494 * which is enough for normal backends, but not necessarily for all types of
495 * background processes.
496 */
497void
499{
500 uint64 local_gen;
501 uint64 shared_gen;
502 volatile uint32 flags;
503
505
506 /* Exit quickly if there's no work to do. */
508 return;
510
511 /*
512 * It's not unlikely to process multiple barriers at once, before the
513 * signals for all the barriers have arrived. To avoid unnecessary work in
514 * response to subsequent signals, exit early if we already have processed
515 * all of them.
516 */
519
520 Assert(local_gen <= shared_gen);
521
522 if (local_gen == shared_gen)
523 return;
524
525 /*
526 * Get and clear the flags that are set for this backend. Note that
527 * pg_atomic_exchange_u32 is a full barrier, so we're guaranteed that the
528 * read of the barrier generation above happens before we atomically
529 * extract the flags, and that any subsequent state changes happen
530 * afterward.
531 *
532 * NB: In order to avoid race conditions, we must zero
533 * pss_barrierCheckMask first and only afterwards try to do barrier
534 * processing. If we did it in the other order, someone could send us
535 * another barrier of some type right after we called the
536 * barrier-processing function but before we cleared the bit. We would
537 * have no way of knowing that the bit needs to stay set in that case, so
538 * the need to call the barrier-processing function again would just get
539 * forgotten. So instead, we tentatively clear all the bits and then put
540 * back any for which we don't manage to successfully absorb the barrier.
541 */
543
544 /*
545 * If there are no flags set, then we can skip doing any real work.
546 * Otherwise, establish a PG_TRY block, so that we don't lose track of
547 * which types of barrier processing are needed if an ERROR occurs.
548 */
549 if (flags != 0)
550 {
551 bool success = true;
552
553 PG_TRY();
554 {
555 /*
556 * Process each type of barrier. The barrier-processing functions
557 * should normally return true, but may return false if the
558 * barrier can't be absorbed at the current time. This should be
559 * rare, because it's pretty expensive. Every single
560 * CHECK_FOR_INTERRUPTS() will return here until we manage to
561 * absorb the barrier, and that cost will add up in a hurry.
562 *
563 * NB: It ought to be OK to call the barrier-processing functions
564 * unconditionally, but it's more efficient to call only the ones
565 * that might need us to do something based on the flags.
566 */
567 while (flags != 0)
568 {
570 bool processed = true;
571
573 switch (type)
574 {
576 processed = ProcessBarrierSmgrRelease();
577 break;
578 }
579
580 /*
581 * To avoid an infinite loop, we must always unset the bit in
582 * flags.
583 */
584 BARRIER_CLEAR_BIT(flags, type);
585
586 /*
587 * If we failed to process the barrier, reset the shared bit
588 * so we try again later, and set a flag so that we don't bump
589 * our generation.
590 */
591 if (!processed)
592 {
594 success = false;
595 }
596 }
597 }
598 PG_CATCH();
599 {
600 /*
601 * If an ERROR occurred, we'll need to try again later to handle
602 * that barrier type and any others that haven't been handled yet
603 * or weren't successfully absorbed.
604 */
606 PG_RE_THROW();
607 }
608 PG_END_TRY();
609
610 /*
611 * If some barrier types were not successfully absorbed, we will have
612 * to try again later.
613 */
614 if (!success)
615 return;
616 }
617
618 /*
619 * State changes related to all types of barriers that might have been
620 * emitted have now been handled, so we can update our notion of the
621 * generation to the one we observed before beginning the updates. If
622 * things have changed further, it'll get fixed up when this function is
623 * next called.
624 */
627}
628
629/*
630 * If it turns out that we couldn't absorb one or more barrier types, either
631 * because the barrier-processing functions returned false or due to an error,
632 * arrange for processing to be retried later.
633 */
634static void
636{
639 InterruptPending = true;
640}
641
642/*
643 * CheckProcSignal - check to see if a particular reason has been
644 * signaled, and clear the signal flag. Should be called after receiving
645 * SIGUSR1.
646 */
647static bool
649{
650 volatile ProcSignalSlot *slot = MyProcSignalSlot;
651
652 if (slot != NULL)
653 {
654 /*
655 * Careful here --- don't clear flag if we haven't seen it set.
656 * pss_signalFlags is of type "volatile sig_atomic_t" to allow us to
657 * read it here safely, without holding the spinlock.
658 */
659 if (slot->pss_signalFlags[reason])
660 {
661 slot->pss_signalFlags[reason] = false;
662 return true;
663 }
664 }
665
666 return false;
667}
668
669/*
670 * procsignal_sigusr1_handler - handle SIGUSR1 signal.
671 */
672void
674{
677
680
683
686
689
692
695
698
701
704
707
710
713
716
719
721}
722
723/*
724 * Send a query cancellation signal to backend.
725 *
726 * Note: This is called from a backend process before authentication. We
727 * cannot take LWLocks yet, but that's OK; we rely on atomic reads of the
728 * fields in the ProcSignal slots.
729 */
730void
731SendCancelRequest(int backendPID, char *cancel_key, int cancel_key_len)
732{
733 Assert(backendPID != 0);
734
735 /*
736 * See if we have a matching backend. Reading the pss_pid and
737 * pss_cancel_key fields is racy, a backend might die and remove itself
738 * from the array at any time. The probability of the cancellation key
739 * matching wrong process is miniscule, however, so we can live with that.
740 * PIDs are reused too, so sending the signal based on PID is inherently
741 * racy anyway, although OS's avoid reusing PIDs too soon.
742 */
743 for (int i = 0; i < NumProcSignalSlots; i++)
744 {
746 bool match;
747
748 if (pg_atomic_read_u32(&slot->pss_pid) != backendPID)
749 continue;
750
751 /* Acquire the spinlock and re-check */
753 if (pg_atomic_read_u32(&slot->pss_pid) != backendPID)
754 {
756 continue;
757 }
758 else
759 {
760 match = slot->pss_cancel_key_len == cancel_key_len &&
761 timingsafe_bcmp(slot->pss_cancel_key, cancel_key, cancel_key_len) == 0;
762
764
765 if (match)
766 {
767 /* Found a match; signal that backend to cancel current op */
769 (errmsg_internal("processing cancel request: sending SIGINT to process %d",
770 backendPID)));
771
772 /*
773 * If we have setsid(), signal the backend's whole process
774 * group
775 */
776#ifdef HAVE_SETSID
777 kill(-backendPID, SIGINT);
778#else
779 kill(backendPID, SIGINT);
780#endif
781 }
782 else
783 {
784 /* Right PID, wrong key: no way, Jose */
785 ereport(LOG,
786 (errmsg("wrong key in cancel request for process %d",
787 backendPID)));
788 }
789 return;
790 }
791 }
792
793 /* No matching backend */
794 ereport(LOG,
795 (errmsg("PID %d in cancel request did not match any process",
796 backendPID)));
797}
void HandleParallelApplyMessageInterrupt(void)
void HandleNotifyInterrupt(void)
Definition: async.c:1804
static void pg_atomic_write_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:485
static uint32 pg_atomic_fetch_or_u32(volatile pg_atomic_uint32 *ptr, uint32 or_)
Definition: atomics.h:410
#define pg_memory_barrier()
Definition: atomics.h:143
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:221
static void pg_atomic_write_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:276
static uint32 pg_atomic_read_u32(volatile pg_atomic_uint32 *ptr)
Definition: atomics.h:239
static uint64 pg_atomic_add_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 add_)
Definition: atomics.h:559
static uint32 pg_atomic_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 newval)
Definition: atomics.h:330
static void pg_atomic_init_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:453
static uint64 pg_atomic_read_u64(volatile pg_atomic_uint64 *ptr)
Definition: atomics.h:467
void HandleParallelMessageInterrupt(void)
Definition: parallel.c:1037
#define SIGNAL_ARGS
Definition: c.h:1320
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:434
#define UINT64_FORMAT
Definition: c.h:521
uint64_t uint64
Definition: c.h:503
uint32_t uint32
Definition: c.h:502
#define PG_UINT64_MAX
Definition: c.h:564
#define MemSet(start, val, len)
Definition: c.h:991
size_t Size
Definition: c.h:576
bool ConditionVariableCancelSleep(void)
bool ConditionVariableTimedSleep(ConditionVariable *cv, long timeout, uint32 wait_event_info)
void ConditionVariableBroadcast(ConditionVariable *cv)
void ConditionVariableInit(ConditionVariable *cv)
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1158
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define LOG
Definition: elog.h:31
#define PG_RE_THROW()
Definition: elog.h:404
#define PG_TRY(...)
Definition: elog.h:371
#define DEBUG2
Definition: elog.h:29
#define PG_END_TRY(...)
Definition: elog.h:396
#define DEBUG1
Definition: elog.h:30
#define ERROR
Definition: elog.h:39
#define PG_CATCH(...)
Definition: elog.h:381
#define elog(elevel,...)
Definition: elog.h:225
#define ereport(elevel,...)
Definition: elog.h:149
volatile sig_atomic_t ProcSignalBarrierPending
Definition: globals.c:40
volatile sig_atomic_t InterruptPending
Definition: globals.c:32
int MyProcPid
Definition: globals.c:48
ProcNumber MyProcNumber
Definition: globals.c:91
struct Latch * MyLatch
Definition: globals.c:64
Assert(PointerIsAligned(start, uint64))
static bool success
Definition: initdb.c:187
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:365
int i
Definition: isn.c:77
void SetLatch(Latch *latch)
Definition: latch.c:288
void HandleGetMemoryContextInterrupt(void)
Definition: mcxt.c:1367
void HandleLogMemoryContextInterrupt(void)
Definition: mcxt.c:1351
void * arg
static int pg_rightmost_one_pos32(uint32 word)
Definition: pg_bitutils.h:111
int timingsafe_bcmp(const void *b1, const void *b2, size_t len)
void HandleRecoveryConflictInterrupt(ProcSignalReason reason)
Definition: postgres.c:3091
uintptr_t Datum
Definition: postgres.h:69
#define NON_EXEC_STATIC
Definition: postgres.h:581
#define INVALID_PROC_NUMBER
Definition: procnumber.h:26
int ProcNumber
Definition: procnumber.h:24
static void CleanupProcSignalState(int status, Datum arg)
Definition: procsignal.c:228
int SendProcSignal(pid_t pid, ProcSignalReason reason, ProcNumber procNumber)
Definition: procsignal.c:283
void ProcSignalShmemInit(void)
Definition: procsignal.c:130
#define NumProcSignalSlots
Definition: procsignal.c:94
static bool CheckProcSignal(ProcSignalReason reason)
Definition: procsignal.c:648
void ProcessProcSignalBarrier(void)
Definition: procsignal.c:498
void WaitForProcSignalBarrier(uint64 generation)
Definition: procsignal.c:423
NON_EXEC_STATIC ProcSignalHeader * ProcSignal
Definition: procsignal.c:104
static void ResetProcSignalBarrierBits(uint32 flags)
Definition: procsignal.c:635
void SendCancelRequest(int backendPID, char *cancel_key, int cancel_key_len)
Definition: procsignal.c:731
uint64 EmitProcSignalBarrier(ProcSignalBarrierType type)
Definition: procsignal.c:355
Size ProcSignalShmemSize(void)
Definition: procsignal.c:116
static void HandleProcSignalBarrierInterrupt(void)
Definition: procsignal.c:482
static ProcSignalSlot * MyProcSignalSlot
Definition: procsignal.c:105
#define BARRIER_CLEAR_BIT(flags, type)
Definition: procsignal.c:101
void procsignal_sigusr1_handler(SIGNAL_ARGS)
Definition: procsignal.c:673
void ProcSignalInit(char *cancel_key, int cancel_key_len)
Definition: procsignal.c:165
#define NUM_PROCSIGNALS
Definition: procsignal.h:53
ProcSignalReason
Definition: procsignal.h:31
@ PROCSIG_GET_MEMORY_CONTEXT
Definition: procsignal.h:38
@ PROCSIG_PARALLEL_MESSAGE
Definition: procsignal.h:34
@ PROCSIG_RECOVERY_CONFLICT_BUFFERPIN
Definition: procsignal.h:48
@ PROCSIG_CATCHUP_INTERRUPT
Definition: procsignal.h:32
@ PROCSIG_RECOVERY_CONFLICT_LOCK
Definition: procsignal.h:45
@ PROCSIG_LOG_MEMORY_CONTEXT
Definition: procsignal.h:37
@ PROCSIG_RECOVERY_CONFLICT_LOGICALSLOT
Definition: procsignal.h:47
@ PROCSIG_BARRIER
Definition: procsignal.h:36
@ PROCSIG_RECOVERY_CONFLICT_DATABASE
Definition: procsignal.h:43
@ PROCSIG_WALSND_INIT_STOPPING
Definition: procsignal.h:35
@ PROCSIG_PARALLEL_APPLY_MESSAGE
Definition: procsignal.h:39
@ PROCSIG_RECOVERY_CONFLICT_SNAPSHOT
Definition: procsignal.h:46
@ PROCSIG_NOTIFY_INTERRUPT
Definition: procsignal.h:33
@ PROCSIG_RECOVERY_CONFLICT_TABLESPACE
Definition: procsignal.h:44
@ PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK
Definition: procsignal.h:49
ProcSignalBarrierType
Definition: procsignal.h:56
@ PROCSIGNAL_BARRIER_SMGRRELEASE
Definition: procsignal.h:57
#define MAX_CANCEL_KEY_LENGTH
Definition: procsignal.h:68
Size add_size(Size s1, Size s2)
Definition: shmem.c:493
Size mul_size(Size s1, Size s2)
Definition: shmem.c:510
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:387
void HandleCatchupInterrupt(void)
Definition: sinval.c:154
bool ProcessBarrierSmgrRelease(void)
Definition: smgr.c:1018
#define SpinLockInit(lock)
Definition: spin.h:57
#define SpinLockRelease(lock)
Definition: spin.h:61
#define SpinLockAcquire(lock)
Definition: spin.h:59
ProcSignalSlot psh_slot[FLEXIBLE_ARRAY_MEMBER]
Definition: procsignal.c:86
pg_atomic_uint64 psh_barrierGeneration
Definition: procsignal.c:85
ConditionVariable pss_barrierCV
Definition: procsignal.c:74
pg_atomic_uint64 pss_barrierGeneration
Definition: procsignal.c:72
volatile sig_atomic_t pss_signalFlags[NUM_PROCSIGNALS]
Definition: procsignal.c:68
char pss_cancel_key[MAX_CANCEL_KEY_LENGTH]
Definition: procsignal.c:67
slock_t pss_mutex
Definition: procsignal.c:69
pg_atomic_uint32 pss_pid
Definition: procsignal.c:65
int pss_cancel_key_len
Definition: procsignal.c:66
pg_atomic_uint32 pss_barrierCheckMask
Definition: procsignal.c:73
const char * type
void HandleWalSndInitStopping(void)
Definition: walsender.c:3589
#define kill(pid, sig)
Definition: win32_port.h:493
#define SIGUSR1
Definition: win32_port.h:170