PostgreSQL Source Code  git master
procsignal.c File Reference
#include "postgres.h"
#include <signal.h>
#include <unistd.h>
#include "access/parallel.h"
#include "commands/async.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "replication/walsender.h"
#include "storage/ipc.h"
#include "storage/latch.h"
#include "storage/proc.h"
#include "storage/shmem.h"
#include "storage/sinval.h"
#include "tcop/tcopprot.h"
Include dependency graph for procsignal.c:

Go to the source code of this file.

Data Structures

struct  ProcSignalSlot
 
struct  ProcSignalHeader
 

Macros

#define NumProcSignalSlots   (MaxBackends + NUM_AUXPROCTYPES)
 
#define BARRIER_SHOULD_CHECK(flags, type)   (((flags) & (((uint32) 1) << (uint32) (type))) != 0)
 

Functions

static bool CheckProcSignal (ProcSignalReason reason)
 
static void CleanupProcSignalState (int status, Datum arg)
 
static void ProcessBarrierPlaceholder (void)
 
Size ProcSignalShmemSize (void)
 
void ProcSignalShmemInit (void)
 
void ProcSignalInit (int pss_idx)
 
int SendProcSignal (pid_t pid, ProcSignalReason reason, BackendId backendId)
 
uint64 EmitProcSignalBarrier (ProcSignalBarrierType type)
 
void WaitForProcSignalBarrier (uint64 generation)
 
void ProcessProcSignalBarrier (void)
 
static bool CheckProcSignalBarrier (void)
 
void procsignal_sigusr1_handler (SIGNAL_ARGS)
 

Variables

static ProcSignalHeaderProcSignal = NULL
 
static volatile ProcSignalSlotMyProcSignalSlot = NULL
 

Macro Definition Documentation

◆ BARRIER_SHOULD_CHECK

#define BARRIER_SHOULD_CHECK (   flags,
  type 
)    (((flags) & (((uint32) 1) << (uint32) (type))) != 0)

Definition at line 87 of file procsignal.c.

Referenced by ProcessProcSignalBarrier().

◆ NumProcSignalSlots

Function Documentation

◆ CheckProcSignal()

static bool CheckProcSignal ( ProcSignalReason  reason)
static

Definition at line 491 of file procsignal.c.

References MyProcSignalSlot, and ProcSignalSlot::pss_signalFlags.

Referenced by procsignal_sigusr1_handler().

492 {
493  volatile ProcSignalSlot *slot = MyProcSignalSlot;
494 
495  if (slot != NULL)
496  {
497  /* Careful here --- don't clear flag if we haven't seen it set */
498  if (slot->pss_signalFlags[reason])
499  {
500  slot->pss_signalFlags[reason] = false;
501  return true;
502  }
503  }
504 
505  return false;
506 }
sig_atomic_t pss_signalFlags[NUM_PROCSIGNALS]
Definition: procsignal.c:62
static volatile ProcSignalSlot * MyProcSignalSlot
Definition: procsignal.c:91

◆ CheckProcSignalBarrier()

static bool CheckProcSignalBarrier ( void  )
static

Definition at line 512 of file procsignal.c.

References MyProcSignalSlot, pg_atomic_read_u64(), ProcSignalHeader::psh_barrierGeneration, and ProcSignalSlot::pss_barrierGeneration.

Referenced by procsignal_sigusr1_handler().

513 {
514  volatile ProcSignalSlot *slot = MyProcSignalSlot;
515 
516  if (slot != NULL)
517  {
518  uint64 mygen;
519  uint64 curgen;
520 
523  return (mygen != curgen);
524  }
525 
526  return false;
527 }
pg_atomic_uint64 psh_barrierGeneration
Definition: procsignal.c:75
pg_atomic_uint64 pss_barrierGeneration
Definition: procsignal.c:63
static ProcSignalHeader * ProcSignal
Definition: procsignal.c:90
static uint64 pg_atomic_read_u64(volatile pg_atomic_uint64 *ptr)
Definition: atomics.h:429
static volatile ProcSignalSlot * MyProcSignalSlot
Definition: procsignal.c:91

◆ CleanupProcSignalState()

static void CleanupProcSignalState ( int  status,
Datum  arg 
)
static

Definition at line 202 of file procsignal.c.

References Assert, DatumGetInt32, elog, LOG, MyProcPid, pg_atomic_write_u64(), PG_UINT64_MAX, ProcSignalHeader::psh_slot, ProcSignalSlot::pss_barrierGeneration, and ProcSignalSlot::pss_pid.

Referenced by ProcSignalInit().

203 {
204  int pss_idx = DatumGetInt32(arg);
205  volatile ProcSignalSlot *slot;
206 
207  slot = &ProcSignal->psh_slot[pss_idx - 1];
208  Assert(slot == MyProcSignalSlot);
209 
210  /*
211  * Clear MyProcSignalSlot, so that a SIGUSR1 received after this point
212  * won't try to access it after it's no longer ours (and perhaps even
213  * after we've unmapped the shared memory segment).
214  */
215  MyProcSignalSlot = NULL;
216 
217  /* sanity check */
218  if (slot->pss_pid != MyProcPid)
219  {
220  /*
221  * don't ERROR here. We're exiting anyway, and don't want to get into
222  * infinite loop trying to exit
223  */
224  elog(LOG, "process %d releasing ProcSignal slot %d, but it contains %d",
225  MyProcPid, pss_idx, (int) slot->pss_pid);
226  return; /* XXX better to zero the slot anyway? */
227  }
228 
229  /*
230  * Make this slot look like it's absorbed all possible barriers, so that
231  * no barrier waits block on it.
232  */
234 
235  slot->pss_pid = 0;
236 }
int MyProcPid
Definition: globals.c:40
#define PG_UINT64_MAX
Definition: c.h:454
#define DatumGetInt32(X)
Definition: postgres.h:472
#define LOG
Definition: elog.h:26
pg_atomic_uint64 pss_barrierGeneration
Definition: procsignal.c:63
static void pg_atomic_write_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:438
ProcSignalSlot psh_slot[FLEXIBLE_ARRAY_MEMBER]
Definition: procsignal.c:76
static ProcSignalHeader * ProcSignal
Definition: procsignal.c:90
#define Assert(condition)
Definition: c.h:738
#define elog(elevel,...)
Definition: elog.h:214
void * arg
static volatile ProcSignalSlot * MyProcSignalSlot
Definition: procsignal.c:91

◆ EmitProcSignalBarrier()

uint64 EmitProcSignalBarrier ( ProcSignalBarrierType  type)

Definition at line 321 of file procsignal.c.

References i, kill, NumProcSignalSlots, pg_atomic_add_fetch_u64(), pg_atomic_fetch_or_u32(), ProcSignalHeader::psh_barrierGeneration, ProcSignalHeader::psh_slot, ProcSignalSlot::pss_barrierCheckMask, ProcSignalSlot::pss_pid, and SIGUSR1.

322 {
323  uint64 flagbit = UINT64CONST(1) << (uint64) type;
324  uint64 generation;
325 
326  /*
327  * Set all the flags.
328  *
329  * Note that pg_atomic_fetch_or_u32 has full barrier semantics, so this is
330  * totally ordered with respect to anything the caller did before, and
331  * anything that we do afterwards. (This is also true of the later call to
332  * pg_atomic_add_fetch_u64.)
333  */
334  for (int i = 0; i < NumProcSignalSlots; i++)
335  {
336  volatile ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
337 
339  }
340 
341  /*
342  * Increment the generation counter.
343  */
344  generation =
346 
347  /*
348  * Signal all the processes, so that they update their advertised barrier
349  * generation.
350  *
351  * Concurrency is not a problem here. Backends that have exited don't
352  * matter, and new backends that have joined since we entered this
353  * function must already have current state, since the caller is
354  * responsible for making sure that the relevant state is entirely visible
355  * before calling this function in the first place. We still have to wake
356  * them up - because we can't distinguish between such backends and older
357  * backends that need to update state - but they won't actually need to
358  * change any state.
359  */
360  for (int i = NumProcSignalSlots - 1; i >= 0; i--)
361  {
362  volatile ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
363  pid_t pid = slot->pss_pid;
364 
365  if (pid != 0)
366  kill(pid, SIGUSR1);
367  }
368 
369  return generation;
370 }
#define SIGUSR1
Definition: win32_port.h:165
pg_atomic_uint64 psh_barrierGeneration
Definition: procsignal.c:75
#define kill(pid, sig)
Definition: win32_port.h:426
ProcSignalSlot psh_slot[FLEXIBLE_ARRAY_MEMBER]
Definition: procsignal.c:76
pg_atomic_uint32 pss_barrierCheckMask
Definition: procsignal.c:64
static ProcSignalHeader * ProcSignal
Definition: procsignal.c:90
static uint64 pg_atomic_add_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 add_)
Definition: atomics.h:504
int i
#define NumProcSignalSlots
Definition: procsignal.c:84
static uint32 pg_atomic_fetch_or_u32(volatile pg_atomic_uint32 *ptr, uint32 or_)
Definition: atomics.h:372

◆ ProcessBarrierPlaceholder()

static void ProcessBarrierPlaceholder ( void  )
static

Definition at line 473 of file procsignal.c.

Referenced by ProcessProcSignalBarrier().

474 {
475  /*
476  * XXX. This is just a placeholder until the first real user of this
477  * machinery gets committed. Rename PROCSIGNAL_BARRIER_PLACEHOLDER to
478  * PROCSIGNAL_BARRIER_SOMETHING_ELSE where SOMETHING_ELSE is something
479  * appropriately descriptive. Get rid of this function and instead have
480  * ProcessBarrierSomethingElse. Most likely, that function should live in
481  * the file pertaining to that subsystem, rather than here.
482  */
483 }

◆ ProcessProcSignalBarrier()

void ProcessProcSignalBarrier ( void  )

Definition at line 429 of file procsignal.c.

References BARRIER_SHOULD_CHECK, pg_atomic_exchange_u32(), pg_atomic_read_u64(), pg_atomic_write_u64(), ProcessBarrierPlaceholder(), PROCSIGNAL_BARRIER_PLACEHOLDER, ProcSignalBarrierPending, ProcSignalHeader::psh_barrierGeneration, ProcSignalSlot::pss_barrierCheckMask, and ProcSignalSlot::pss_barrierGeneration.

Referenced by BufferSync(), CheckpointWriteDelay(), HandleAutoVacLauncherInterrupts(), HandleCheckpointerInterrupts(), HandleMainLoopInterrupts(), HandleStartupProcInterrupts(), and ProcessInterrupts().

430 {
431  uint64 generation;
432  uint32 flags;
433 
434  /* Exit quickly if there's no work to do. */
436  return;
437  ProcSignalBarrierPending = false;
438 
439  /*
440  * Read the current barrier generation, and then get the flags that are
441  * set for this backend. Note that pg_atomic_exchange_u32 is a full
442  * barrier, so we're guaranteed that the read of the barrier generation
443  * happens before we atomically extract the flags, and that any subsequent
444  * state changes happen afterward.
445  */
448 
449  /*
450  * Process each type of barrier. It's important that nothing we call from
451  * here throws an error, because pss_barrierCheckMask has already been
452  * cleared. If we jumped out of here before processing all barrier types,
453  * then we'd forget about the need to do so later.
454  *
455  * NB: It ought to be OK to call the barrier-processing functions
456  * unconditionally, but it's more efficient to call only the ones that
457  * might need us to do something based on the flags.
458  */
461 
462  /*
463  * State changes related to all types of barriers that might have been
464  * emitted have now been handled, so we can update our notion of the
465  * generation to the one we observed before beginning the updates. If
466  * things have changed further, it'll get fixed up when this function is
467  * next called.
468  */
470 }
pg_atomic_uint64 psh_barrierGeneration
Definition: procsignal.c:75
static void ProcessBarrierPlaceholder(void)
Definition: procsignal.c:473
pg_atomic_uint64 pss_barrierGeneration
Definition: procsignal.c:63
static void pg_atomic_write_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:438
static uint32 pg_atomic_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 newval)
Definition: atomics.h:292
pg_atomic_uint32 pss_barrierCheckMask
Definition: procsignal.c:64
unsigned int uint32
Definition: c.h:367
static ProcSignalHeader * ProcSignal
Definition: procsignal.c:90
volatile sig_atomic_t ProcSignalBarrierPending
Definition: globals.c:35
#define BARRIER_SHOULD_CHECK(flags, type)
Definition: procsignal.c:87
static uint64 pg_atomic_read_u64(volatile pg_atomic_uint64 *ptr)
Definition: atomics.h:429
static volatile ProcSignalSlot * MyProcSignalSlot
Definition: procsignal.c:91

◆ procsignal_sigusr1_handler()

void procsignal_sigusr1_handler ( SIGNAL_ARGS  )

Definition at line 533 of file procsignal.c.

References CheckProcSignal(), CheckProcSignalBarrier(), HandleCatchupInterrupt(), HandleNotifyInterrupt(), HandleParallelMessageInterrupt(), HandleWalSndInitStopping(), InterruptPending, latch_sigusr1_handler(), MyLatch, PROCSIG_CATCHUP_INTERRUPT, PROCSIG_NOTIFY_INTERRUPT, PROCSIG_PARALLEL_MESSAGE, PROCSIG_RECOVERY_CONFLICT_BUFFERPIN, PROCSIG_RECOVERY_CONFLICT_DATABASE, PROCSIG_RECOVERY_CONFLICT_LOCK, PROCSIG_RECOVERY_CONFLICT_SNAPSHOT, PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK, PROCSIG_RECOVERY_CONFLICT_TABLESPACE, PROCSIG_WALSND_INIT_STOPPING, ProcSignalBarrierPending, RecoveryConflictInterrupt(), and SetLatch().

Referenced by autoprewarm_main(), AutoVacLauncherMain(), AutoVacWorkerMain(), BackgroundWriterMain(), CheckpointerMain(), PostgresMain(), StartBackgroundWorker(), StartupProcessMain(), WalReceiverMain(), WalSndSignals(), and WalWriterMain().

534 {
535  int save_errno = errno;
536 
539 
542 
545 
548 
551 
554 
557 
560 
563 
566 
568  {
569  InterruptPending = true;
571  }
572 
573  SetLatch(MyLatch);
574 
576 
577  errno = save_errno;
578 }
void RecoveryConflictInterrupt(ProcSignalReason reason)
Definition: postgres.c:2896
void SetLatch(Latch *latch)
Definition: latch.c:457
void HandleWalSndInitStopping(void)
Definition: walsender.c:3015
static bool CheckProcSignal(ProcSignalReason reason)
Definition: procsignal.c:491
static bool CheckProcSignalBarrier(void)
Definition: procsignal.c:512
volatile sig_atomic_t ProcSignalBarrierPending
Definition: globals.c:35
volatile sig_atomic_t InterruptPending
Definition: globals.c:30
void HandleNotifyInterrupt(void)
Definition: async.c:1876
struct Latch * MyLatch
Definition: globals.c:54
void HandleParallelMessageInterrupt(void)
Definition: parallel.c:991
void latch_sigusr1_handler(void)
Definition: latch.c:1866
void HandleCatchupInterrupt(void)
Definition: sinval.c:156

◆ ProcSignalInit()

void ProcSignalInit ( int  pss_idx)

Definition at line 151 of file procsignal.c.

References Assert, CleanupProcSignalState(), elog, Int32GetDatum, LOG, MemSet, MyProcPid, NUM_PROCSIGNALS, NumProcSignalSlots, on_shmem_exit(), pg_atomic_read_u64(), pg_atomic_write_u32(), pg_atomic_write_u64(), pg_memory_barrier, ProcSignalHeader::psh_barrierGeneration, ProcSignalHeader::psh_slot, ProcSignalSlot::pss_barrierCheckMask, ProcSignalSlot::pss_barrierGeneration, ProcSignalSlot::pss_pid, and ProcSignalSlot::pss_signalFlags.

Referenced by AuxiliaryProcessMain(), and InitPostgres().

152 {
153  volatile ProcSignalSlot *slot;
154  uint64 barrier_generation;
155 
156  Assert(pss_idx >= 1 && pss_idx <= NumProcSignalSlots);
157 
158  slot = &ProcSignal->psh_slot[pss_idx - 1];
159 
160  /* sanity check */
161  if (slot->pss_pid != 0)
162  elog(LOG, "process %d taking over ProcSignal slot %d, but it's not empty",
163  MyProcPid, pss_idx);
164 
165  /* Clear out any leftover signal reasons */
166  MemSet(slot->pss_signalFlags, 0, NUM_PROCSIGNALS * sizeof(sig_atomic_t));
167 
168  /*
169  * Initialize barrier state. Since we're a brand-new process, there
170  * shouldn't be any leftover backend-private state that needs to be
171  * updated. Therefore, we can broadcast the latest barrier generation and
172  * disregard any previously-set check bits.
173  *
174  * NB: This only works if this initialization happens early enough in the
175  * startup sequence that we haven't yet cached any state that might need
176  * to be invalidated. That's also why we have a memory barrier here, to be
177  * sure that any later reads of memory happen strictly after this.
178  */
180  barrier_generation =
182  pg_atomic_write_u64(&slot->pss_barrierGeneration, barrier_generation);
184 
185  /* Mark slot with my PID */
186  slot->pss_pid = MyProcPid;
187 
188  /* Remember slot location for CheckProcSignal */
189  MyProcSignalSlot = slot;
190 
191  /* Set up to release the slot on process exit */
193 }
int MyProcPid
Definition: globals.c:40
pg_atomic_uint64 psh_barrierGeneration
Definition: procsignal.c:75
#define MemSet(start, val, len)
Definition: c.h:971
#define LOG
Definition: elog.h:26
pg_atomic_uint64 pss_barrierGeneration
Definition: procsignal.c:63
static void pg_atomic_write_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:438
ProcSignalSlot psh_slot[FLEXIBLE_ARRAY_MEMBER]
Definition: procsignal.c:76
static void CleanupProcSignalState(int status, Datum arg)
Definition: procsignal.c:202
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:361
pg_atomic_uint32 pss_barrierCheckMask
Definition: procsignal.c:64
static ProcSignalHeader * ProcSignal
Definition: procsignal.c:90
#define pg_memory_barrier()
Definition: atomics.h:145
#define Assert(condition)
Definition: c.h:738
#define Int32GetDatum(X)
Definition: postgres.h:479
static uint64 pg_atomic_read_u64(volatile pg_atomic_uint64 *ptr)
Definition: atomics.h:429
#define elog(elevel,...)
Definition: elog.h:214
sig_atomic_t pss_signalFlags[NUM_PROCSIGNALS]
Definition: procsignal.c:62
static volatile ProcSignalSlot * MyProcSignalSlot
Definition: procsignal.c:91
#define NumProcSignalSlots
Definition: procsignal.c:84
static void pg_atomic_write_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:258

◆ ProcSignalShmemInit()

void ProcSignalShmemInit ( void  )

Definition at line 116 of file procsignal.c.

References i, MemSet, NumProcSignalSlots, pg_atomic_init_u32(), pg_atomic_init_u64(), PG_UINT64_MAX, ProcSignalShmemSize(), ProcSignalHeader::psh_barrierGeneration, ProcSignalHeader::psh_slot, ProcSignalSlot::pss_barrierCheckMask, ProcSignalSlot::pss_barrierGeneration, ProcSignalSlot::pss_pid, ProcSignalSlot::pss_signalFlags, and ShmemInitStruct().

Referenced by CreateSharedMemoryAndSemaphores().

117 {
118  Size size = ProcSignalShmemSize();
119  bool found;
120 
122  ShmemInitStruct("ProcSignal", size, &found);
123 
124  /* If we're first, initialize. */
125  if (!found)
126  {
127  int i;
128 
130 
131  for (i = 0; i < NumProcSignalSlots; ++i)
132  {
133  ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
134 
135  slot->pss_pid = 0;
136  MemSet(slot->pss_signalFlags, 0, sizeof(slot->pss_signalFlags));
139  }
140  }
141 }
#define PG_UINT64_MAX
Definition: c.h:454
pg_atomic_uint64 psh_barrierGeneration
Definition: procsignal.c:75
#define MemSet(start, val, len)
Definition: c.h:971
pg_atomic_uint64 pss_barrierGeneration
Definition: procsignal.c:63
ProcSignalSlot psh_slot[FLEXIBLE_ARRAY_MEMBER]
Definition: procsignal.c:76
static void pg_atomic_init_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:415
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:392
pg_atomic_uint32 pss_barrierCheckMask
Definition: procsignal.c:64
Size ProcSignalShmemSize(void)
Definition: procsignal.c:102
static ProcSignalHeader * ProcSignal
Definition: procsignal.c:90
size_t Size
Definition: c.h:466
int i
sig_atomic_t pss_signalFlags[NUM_PROCSIGNALS]
Definition: procsignal.c:62
#define NumProcSignalSlots
Definition: procsignal.c:84
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:223

◆ ProcSignalShmemSize()

Size ProcSignalShmemSize ( void  )

Definition at line 102 of file procsignal.c.

References add_size(), mul_size(), NumProcSignalSlots, and offsetof.

Referenced by CreateSharedMemoryAndSemaphores(), and ProcSignalShmemInit().

103 {
104  Size size;
105 
106  size = mul_size(NumProcSignalSlots, sizeof(ProcSignalSlot));
107  size = add_size(size, offsetof(ProcSignalHeader, psh_slot));
108  return size;
109 }
Size mul_size(Size s1, Size s2)
Definition: shmem.c:515
Size add_size(Size s1, Size s2)
Definition: shmem.c:498
size_t Size
Definition: c.h:466
#define NumProcSignalSlots
Definition: procsignal.c:84
#define offsetof(type, field)
Definition: c.h:661

◆ SendProcSignal()

int SendProcSignal ( pid_t  pid,
ProcSignalReason  reason,
BackendId  backendId 
)

Definition at line 250 of file procsignal.c.

References i, InvalidBackendId, kill, NumProcSignalSlots, ProcSignalHeader::psh_slot, ProcSignalSlot::pss_pid, ProcSignalSlot::pss_signalFlags, and SIGUSR1.

Referenced by CancelDBBackends(), CancelVirtualTransaction(), mq_putmessage(), ParallelWorkerShutdown(), SICleanupQueue(), SignalBackends(), and WalSndInitStopping().

251 {
252  volatile ProcSignalSlot *slot;
253 
254  if (backendId != InvalidBackendId)
255  {
256  slot = &ProcSignal->psh_slot[backendId - 1];
257 
258  /*
259  * Note: Since there's no locking, it's possible that the target
260  * process detaches from shared memory and exits right after this
261  * test, before we set the flag and send signal. And the signal slot
262  * might even be recycled by a new process, so it's remotely possible
263  * that we set a flag for a wrong process. That's OK, all the signals
264  * are such that no harm is done if they're mistakenly fired.
265  */
266  if (slot->pss_pid == pid)
267  {
268  /* Atomically set the proper flag */
269  slot->pss_signalFlags[reason] = true;
270  /* Send signal */
271  return kill(pid, SIGUSR1);
272  }
273  }
274  else
275  {
276  /*
277  * BackendId not provided, so search the array using pid. We search
278  * the array back to front so as to reduce search overhead. Passing
279  * InvalidBackendId means that the target is most likely an auxiliary
280  * process, which will have a slot near the end of the array.
281  */
282  int i;
283 
284  for (i = NumProcSignalSlots - 1; i >= 0; i--)
285  {
286  slot = &ProcSignal->psh_slot[i];
287 
288  if (slot->pss_pid == pid)
289  {
290  /* the above note about race conditions applies here too */
291 
292  /* Atomically set the proper flag */
293  slot->pss_signalFlags[reason] = true;
294  /* Send signal */
295  return kill(pid, SIGUSR1);
296  }
297  }
298  }
299 
300  errno = ESRCH;
301  return -1;
302 }
#define SIGUSR1
Definition: win32_port.h:165
#define kill(pid, sig)
Definition: win32_port.h:426
ProcSignalSlot psh_slot[FLEXIBLE_ARRAY_MEMBER]
Definition: procsignal.c:76
#define InvalidBackendId
Definition: backendid.h:23
static ProcSignalHeader * ProcSignal
Definition: procsignal.c:90
int i
sig_atomic_t pss_signalFlags[NUM_PROCSIGNALS]
Definition: procsignal.c:62
#define NumProcSignalSlots
Definition: procsignal.c:84

◆ WaitForProcSignalBarrier()

void WaitForProcSignalBarrier ( uint64  generation)

Definition at line 382 of file procsignal.c.

References CHECK_FOR_INTERRUPTS, i, Min, MyLatch, NumProcSignalSlots, pg_atomic_read_u64(), pg_memory_barrier, ProcSignalHeader::psh_slot, ProcSignalSlot::pss_barrierGeneration, ResetLatch(), WAIT_EVENT_PROC_SIGNAL_BARRIER, WaitLatch(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, and WL_TIMEOUT.

383 {
384  long timeout = 125L;
385 
386  for (int i = NumProcSignalSlots - 1; i >= 0; i--)
387  {
388  volatile ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
389  uint64 oldval;
390 
391  oldval = pg_atomic_read_u64(&slot->pss_barrierGeneration);
392  while (oldval < generation)
393  {
394  int events;
395 
397 
398  events =
403 
404  oldval = pg_atomic_read_u64(&slot->pss_barrierGeneration);
405  if (events & WL_TIMEOUT)
406  timeout = Min(timeout * 2, 1000L);
407  }
408  }
409 
410  /*
411  * The caller is probably calling this function because it wants to read
412  * the shared state or perform further writes to shared state once all
413  * backends are known to have absorbed the barrier. However, the read of
414  * pss_barrierGeneration was performed unlocked; insert a memory barrier
415  * to separate it from whatever follows.
416  */
418 }
#define WL_TIMEOUT
Definition: latch.h:127
#define Min(x, y)
Definition: c.h:920
pg_atomic_uint64 pss_barrierGeneration
Definition: procsignal.c:63
void ResetLatch(Latch *latch)
Definition: latch.c:540
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition: latch.c:365
ProcSignalSlot psh_slot[FLEXIBLE_ARRAY_MEMBER]
Definition: procsignal.c:76
static ProcSignalHeader * ProcSignal
Definition: procsignal.c:90
#define pg_memory_barrier()
Definition: atomics.h:145
static uint64 pg_atomic_read_u64(volatile pg_atomic_uint64 *ptr)
Definition: atomics.h:429
int i
#define NumProcSignalSlots
Definition: procsignal.c:84
struct Latch * MyLatch
Definition: globals.c:54
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:99
#define WL_LATCH_SET
Definition: latch.h:124
#define WL_EXIT_ON_PM_DEATH
Definition: latch.h:129

Variable Documentation

◆ MyProcSignalSlot

volatile ProcSignalSlot* MyProcSignalSlot = NULL
static

Definition at line 91 of file procsignal.c.

Referenced by CheckProcSignal(), and CheckProcSignalBarrier().

◆ ProcSignal

ProcSignalHeader* ProcSignal = NULL
static

Definition at line 90 of file procsignal.c.