PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
bgworker.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  BackgroundWorker
 

Macros

#define BGWORKER_SHMEM_ACCESS   0x0001
 
#define BGWORKER_BACKEND_DATABASE_CONNECTION   0x0002
 
#define BGWORKER_CLASS_PARALLEL   0x0010
 
#define BGW_DEFAULT_RESTART_INTERVAL   60
 
#define BGW_NEVER_RESTART   -1
 
#define BGW_MAXLEN   64
 
#define BGW_EXTRALEN   128
 

Typedefs

typedef void(* bgworker_main_type )(Datum main_arg)
 
typedef struct BackgroundWorker BackgroundWorker
 
typedef enum BgwHandleStatus BgwHandleStatus
 
typedef struct
BackgroundWorkerHandle 
BackgroundWorkerHandle
 

Enumerations

enum  BgWorkerStartTime { BgWorkerStart_PostmasterStart, BgWorkerStart_ConsistentState, BgWorkerStart_RecoveryFinished }
 
enum  BgwHandleStatus { BGWH_STARTED, BGWH_NOT_YET_STARTED, BGWH_STOPPED, BGWH_POSTMASTER_DIED }
 

Functions

void RegisterBackgroundWorker (BackgroundWorker *worker)
 
bool RegisterDynamicBackgroundWorker (BackgroundWorker *worker, BackgroundWorkerHandle **handle)
 
BgwHandleStatus GetBackgroundWorkerPid (BackgroundWorkerHandle *handle, pid_t *pidp)
 
BgwHandleStatus WaitForBackgroundWorkerStartup (BackgroundWorkerHandle *handle, pid_t *pid)
 
BgwHandleStatus WaitForBackgroundWorkerShutdown (BackgroundWorkerHandle *)
 
void TerminateBackgroundWorker (BackgroundWorkerHandle *handle)
 
void BackgroundWorkerInitializeConnection (char *dbname, char *username)
 
void BackgroundWorkerInitializeConnectionByOid (Oid dboid, Oid useroid)
 
void BackgroundWorkerBlockSignals (void)
 
void BackgroundWorkerUnblockSignals (void)
 

Variables

PGDLLIMPORT BackgroundWorkerMyBgworkerEntry
 

Macro Definition Documentation

#define BGW_DEFAULT_RESTART_INTERVAL   60

Definition at line 83 of file bgworker.h.

#define BGW_EXTRALEN   128

Definition at line 86 of file bgworker.h.

Referenced by BackgroundWorkerStateChange(), and LaunchParallelWorkers().

#define BGWORKER_CLASS_PARALLEL   0x0010

Typedef Documentation

typedef void(* bgworker_main_type)(Datum main_arg)

Definition at line 71 of file bgworker.h.

Enumeration Type Documentation

Enumerator
BGWH_STARTED 
BGWH_NOT_YET_STARTED 
BGWH_STOPPED 
BGWH_POSTMASTER_DIED 

Definition at line 102 of file bgworker.h.

103 {
104  BGWH_STARTED, /* worker is running */
105  BGWH_NOT_YET_STARTED, /* worker hasn't been started yet */
106  BGWH_STOPPED, /* worker has exited */
107  BGWH_POSTMASTER_DIED /* postmaster died; worker status unclear */
BgwHandleStatus
Definition: bgworker.h:102
Enumerator
BgWorkerStart_PostmasterStart 
BgWorkerStart_ConsistentState 
BgWorkerStart_RecoveryFinished 

Definition at line 76 of file bgworker.h.

Function Documentation

void BackgroundWorkerBlockSignals ( void  )

Definition at line 5498 of file postmaster.c.

References BlockSig, and PG_SETMASK.

5499 {
5500  PG_SETMASK(&BlockSig);
5501 }
#define PG_SETMASK(mask)
Definition: pqsignal.h:19
sigset_t BlockSig
Definition: pqsignal.c:22
void BackgroundWorkerInitializeConnection ( char *  dbname,
char *  username 
)

Definition at line 5452 of file postmaster.c.

References BackgroundWorker::bgw_flags, BGWORKER_BACKEND_DATABASE_CONNECTION, ereport, errcode(), errmsg(), ERROR, FATAL, InitPostgres(), InvalidOid, IsInitProcessingMode, MyBgworkerEntry, NormalProcessing, NULL, and SetProcessingMode.

Referenced by ApplyLauncherMain().

5453 {
5455 
5456  /* XXX is this the right errcode? */
5458  ereport(FATAL,
5459  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
5460  errmsg("database connection requirement not indicated during registration")));
5461 
5463 
5464  /* it had better not gotten out of "init" mode yet */
5465  if (!IsInitProcessingMode())
5466  ereport(ERROR,
5467  (errmsg("invalid processing mode in background worker")));
5469 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define SetProcessingMode(mode)
Definition: miscadmin.h:371
BackgroundWorker * MyBgworkerEntry
Definition: postmaster.c:189
#define ERROR
Definition: elog.h:43
#define FATAL
Definition: elog.h:52
#define ereport(elevel, rest)
Definition: elog.h:122
static char * username
Definition: initdb.c:131
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:229
#define BGWORKER_BACKEND_DATABASE_CONNECTION
Definition: bgworker.h:59
char * dbname
Definition: streamutil.c:38
void InitPostgres(const char *in_dbname, Oid dboid, const char *username, Oid useroid, char *out_dbname)
Definition: postinit.c:558
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define IsInitProcessingMode()
Definition: miscadmin.h:366
void BackgroundWorkerInitializeConnectionByOid ( Oid  dboid,
Oid  useroid 
)

Definition at line 5475 of file postmaster.c.

References BackgroundWorker::bgw_flags, BGWORKER_BACKEND_DATABASE_CONNECTION, ereport, errcode(), errmsg(), ERROR, FATAL, InitPostgres(), IsInitProcessingMode, MyBgworkerEntry, NormalProcessing, NULL, and SetProcessingMode.

Referenced by ApplyWorkerMain(), and ParallelWorkerMain().

5476 {
5478 
5479  /* XXX is this the right errcode? */
5481  ereport(FATAL,
5482  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
5483  errmsg("database connection requirement not indicated during registration")));
5484 
5485  InitPostgres(NULL, dboid, NULL, useroid, NULL);
5486 
5487  /* it had better not gotten out of "init" mode yet */
5488  if (!IsInitProcessingMode())
5489  ereport(ERROR,
5490  (errmsg("invalid processing mode in background worker")));
5492 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define SetProcessingMode(mode)
Definition: miscadmin.h:371
BackgroundWorker * MyBgworkerEntry
Definition: postmaster.c:189
#define ERROR
Definition: elog.h:43
#define FATAL
Definition: elog.h:52
#define ereport(elevel, rest)
Definition: elog.h:122
#define NULL
Definition: c.h:229
#define BGWORKER_BACKEND_DATABASE_CONNECTION
Definition: bgworker.h:59
void InitPostgres(const char *in_dbname, Oid dboid, const char *username, Oid useroid, char *out_dbname)
Definition: postinit.c:558
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define IsInitProcessingMode()
Definition: miscadmin.h:366
void BackgroundWorkerUnblockSignals ( void  )

Definition at line 5504 of file postmaster.c.

References PG_SETMASK, and UnBlockSig.

Referenced by ApplyLauncherMain(), ApplyWorkerMain(), ParallelWorkerMain(), and test_shm_mq_main().

5505 {
5507 }
#define PG_SETMASK(mask)
Definition: pqsignal.h:19
sigset_t UnBlockSig
Definition: pqsignal.c:22
BgwHandleStatus GetBackgroundWorkerPid ( BackgroundWorkerHandle handle,
pid_t *  pidp 
)

Definition at line 1004 of file bgworker.c.

References Assert, BGWH_NOT_YET_STARTED, BGWH_STARTED, BGWH_STOPPED, BackgroundWorkerSlot::generation, BackgroundWorkerHandle::generation, InvalidPid, LW_SHARED, LWLockAcquire(), LWLockRelease(), max_worker_processes, BackgroundWorkerSlot::pid, BackgroundWorkerArray::slot, and BackgroundWorkerHandle::slot.

Referenced by check_worker_status(), shm_mq_counterparty_gone(), shm_mq_wait_internal(), WaitForBackgroundWorkerShutdown(), WaitForBackgroundWorkerStartup(), and WaitForReplicationWorkerAttach().

1005 {
1006  BackgroundWorkerSlot *slot;
1007  pid_t pid;
1008 
1009  Assert(handle->slot < max_worker_processes);
1010  slot = &BackgroundWorkerData->slot[handle->slot];
1011 
1012  /*
1013  * We could probably arrange to synchronize access to data using memory
1014  * barriers only, but for now, let's just keep it simple and grab the
1015  * lock. It seems unlikely that there will be enough traffic here to
1016  * result in meaningful contention.
1017  */
1018  LWLockAcquire(BackgroundWorkerLock, LW_SHARED);
1019 
1020  /*
1021  * The generation number can't be concurrently changed while we hold the
1022  * lock. The pid, which is updated by the postmaster, can change at any
1023  * time, but we assume such changes are atomic. So the value we read
1024  * won't be garbage, but it might be out of date by the time the caller
1025  * examines it (but that's unavoidable anyway).
1026  */
1027  if (handle->generation != slot->generation)
1028  pid = 0;
1029  else
1030  pid = slot->pid;
1031 
1032  /* All done. */
1033  LWLockRelease(BackgroundWorkerLock);
1034 
1035  if (pid == 0)
1036  return BGWH_STOPPED;
1037  else if (pid == InvalidPid)
1038  return BGWH_NOT_YET_STARTED;
1039  *pidp = pid;
1040  return BGWH_STARTED;
1041 }
static BackgroundWorkerArray * BackgroundWorkerData
Definition: bgworker.c:109
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1715
#define Assert(condition)
Definition: c.h:675
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1111
int max_worker_processes
Definition: globals.c:124
BackgroundWorkerSlot slot[FLEXIBLE_ARRAY_MEMBER]
Definition: bgworker.c:100
#define InvalidPid
Definition: miscadmin.h:31
void RegisterBackgroundWorker ( BackgroundWorker worker)

Definition at line 805 of file bgworker.c.

References BackgroundWorker::bgw_main, BackgroundWorker::bgw_name, BackgroundWorker::bgw_notify_pid, DEBUG1, ereport, errcode(), errdetail_plural(), errhint(), errmsg(), i, InternalBGWorkers, IsUnderPostmaster, LOG, malloc, max_worker_processes, NULL, process_shared_preload_libraries_in_progress, RegisteredBgWorker::rw_backend, RegisteredBgWorker::rw_child_slot, RegisteredBgWorker::rw_crashed_at, RegisteredBgWorker::rw_lnode, RegisteredBgWorker::rw_pid, RegisteredBgWorker::rw_terminate, RegisteredBgWorker::rw_worker, SanityCheckBackgroundWorker(), and slist_push_head().

Referenced by _PG_init(), and ApplyLauncherRegister().

806 {
807  RegisteredBgWorker *rw;
808  static int numworkers = 0;
809  bool internal = false;
810  int i;
811 
812  if (!IsUnderPostmaster)
813  ereport(DEBUG1,
814  (errmsg("registering background worker \"%s\"", worker->bgw_name)));
815 
816  for (i = 0; InternalBGWorkers[i]; i++)
817  {
818  if (worker->bgw_main == InternalBGWorkers[i])
819  {
820  internal = true;
821  break;
822  }
823  }
824 
826  {
827  if (!IsUnderPostmaster)
828  ereport(LOG,
829  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
830  errmsg("background worker \"%s\": must be registered in shared_preload_libraries",
831  worker->bgw_name)));
832  return;
833  }
834 
835  if (!SanityCheckBackgroundWorker(worker, LOG))
836  return;
837 
838  if (worker->bgw_notify_pid != 0)
839  {
840  ereport(LOG,
841  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
842  errmsg("background worker \"%s\": only dynamic background workers can request notification",
843  worker->bgw_name)));
844  return;
845  }
846 
847  /*
848  * Enforce maximum number of workers. Note this is overly restrictive: we
849  * could allow more non-shmem-connected workers, because these don't count
850  * towards the MAX_BACKENDS limit elsewhere. For now, it doesn't seem
851  * important to relax this restriction.
852  */
853  if (++numworkers > max_worker_processes)
854  {
855  ereport(LOG,
856  (errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED),
857  errmsg("too many background workers"),
858  errdetail_plural("Up to %d background worker can be registered with the current settings.",
859  "Up to %d background workers can be registered with the current settings.",
862  errhint("Consider increasing the configuration parameter \"max_worker_processes\".")));
863  return;
864  }
865 
866  /*
867  * Copy the registration data into the registered workers list.
868  */
869  rw = malloc(sizeof(RegisteredBgWorker));
870  if (rw == NULL)
871  {
872  ereport(LOG,
873  (errcode(ERRCODE_OUT_OF_MEMORY),
874  errmsg("out of memory")));
875  return;
876  }
877 
878  rw->rw_worker = *worker;
879  rw->rw_backend = NULL;
880  rw->rw_pid = 0;
881  rw->rw_child_slot = 0;
882  rw->rw_crashed_at = 0;
883  rw->rw_terminate = false;
884 
886 }
struct bkend * rw_backend
#define DEBUG1
Definition: elog.h:25
int errhint(const char *fmt,...)
Definition: elog.c:987
bool process_shared_preload_libraries_in_progress
Definition: miscinit.c:1417
static void slist_push_head(slist_head *head, slist_node *node)
Definition: ilist.h:574
int errcode(int sqlerrcode)
Definition: elog.c:575
#define LOG
Definition: elog.h:26
static const bgworker_main_type InternalBGWorkers[]
Definition: bgworker.c:115
#define malloc(a)
Definition: header.h:50
bgworker_main_type bgw_main
Definition: bgworker.h:94
slist_head BackgroundWorkerList
Definition: bgworker.c:41
bool IsUnderPostmaster
Definition: globals.c:100
#define ereport(elevel, rest)
Definition: elog.h:122
static bool SanityCheckBackgroundWorker(BackgroundWorker *worker, int elevel)
Definition: bgworker.c:542
#define NULL
Definition: c.h:229
char bgw_name[BGW_MAXLEN]
Definition: bgworker.h:90
int errdetail_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:965
int errmsg(const char *fmt,...)
Definition: elog.c:797
pid_t bgw_notify_pid
Definition: bgworker.h:99
int i
int max_worker_processes
Definition: globals.c:124
BackgroundWorker rw_worker
bool RegisterDynamicBackgroundWorker ( BackgroundWorker worker,
BackgroundWorkerHandle **  handle 
)

Definition at line 899 of file bgworker.c.

References BackgroundWorker::bgw_flags, BGWORKER_CLASS_PARALLEL, ERROR, BackgroundWorkerSlot::generation, BackgroundWorkerSlot::in_use, InvalidPid, IsUnderPostmaster, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), max_parallel_workers, palloc(), BackgroundWorkerArray::parallel_register_count, BackgroundWorkerArray::parallel_terminate_count, pg_write_barrier, BackgroundWorkerSlot::pid, PMSIGNAL_BACKGROUND_WORKER_CHANGE, SanityCheckBackgroundWorker(), SendPostmasterSignal(), BackgroundWorkerArray::slot, success, BackgroundWorkerSlot::terminate, BackgroundWorkerArray::total_slots, and BackgroundWorkerSlot::worker.

Referenced by LaunchParallelWorkers(), logicalrep_worker_launch(), setup_background_workers(), and worker_spi_launch().

901 {
902  int slotno;
903  bool success = false;
904  bool parallel;
905  uint64 generation = 0;
906 
907  /*
908  * We can't register dynamic background workers from the postmaster. If
909  * this is a standalone backend, we're the only process and can't start
910  * any more. In a multi-process environment, it might be theoretically
911  * possible, but we don't currently support it due to locking
912  * considerations; see comments on the BackgroundWorkerSlot data
913  * structure.
914  */
915  if (!IsUnderPostmaster)
916  return false;
917 
918  if (!SanityCheckBackgroundWorker(worker, ERROR))
919  return false;
920 
921  parallel = (worker->bgw_flags & BGWORKER_CLASS_PARALLEL) != 0;
922 
923  LWLockAcquire(BackgroundWorkerLock, LW_EXCLUSIVE);
924 
925  /*
926  * If this is a parallel worker, check whether there are already too many
927  * parallel workers; if so, don't register another one. Our view of
928  * parallel_terminate_count may be slightly stale, but that doesn't really
929  * matter: we would have gotten the same result if we'd arrived here
930  * slightly earlier anyway. There's no help for it, either, since the
931  * postmaster must not take locks; a memory barrier wouldn't guarantee
932  * anything useful.
933  */
937  {
938  LWLockRelease(BackgroundWorkerLock);
939  return false;
940  }
941 
942  /*
943  * Look for an unused slot. If we find one, grab it.
944  */
945  for (slotno = 0; slotno < BackgroundWorkerData->total_slots; ++slotno)
946  {
948 
949  if (!slot->in_use)
950  {
951  memcpy(&slot->worker, worker, sizeof(BackgroundWorker));
952  slot->pid = InvalidPid; /* indicates not started yet */
953  slot->generation++;
954  slot->terminate = false;
955  generation = slot->generation;
956  if (parallel)
958 
959  /*
960  * Make sure postmaster doesn't see the slot as in use before it
961  * sees the new contents.
962  */
964 
965  slot->in_use = true;
966  success = true;
967  break;
968  }
969  }
970 
971  LWLockRelease(BackgroundWorkerLock);
972 
973  /* If we found a slot, tell the postmaster to notice the change. */
974  if (success)
976 
977  /*
978  * If we found a slot and the user has provided a handle, initialize it.
979  */
980  if (success && handle)
981  {
982  *handle = palloc(sizeof(BackgroundWorkerHandle));
983  (*handle)->slot = slotno;
984  (*handle)->generation = generation;
985  }
986 
987  return success;
988 }
int max_parallel_workers
Definition: globals.c:125
static BackgroundWorkerArray * BackgroundWorkerData
Definition: bgworker.c:109
#define BGWORKER_CLASS_PARALLEL
Definition: bgworker.h:67
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1715
#define ERROR
Definition: elog.h:43
static bool success
Definition: pg_basebackup.c:96
uint32 parallel_register_count
Definition: bgworker.c:98
bool IsUnderPostmaster
Definition: globals.c:100
static bool SanityCheckBackgroundWorker(BackgroundWorker *worker, int elevel)
Definition: bgworker.c:542
BackgroundWorker worker
Definition: bgworker.c:81
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1111
void * palloc(Size size)
Definition: mcxt.c:849
uint32 parallel_terminate_count
Definition: bgworker.c:99
#define pg_write_barrier()
Definition: atomics.h:161
void SendPostmasterSignal(PMSignalReason reason)
Definition: pmsignal.c:113
BackgroundWorkerSlot slot[FLEXIBLE_ARRAY_MEMBER]
Definition: bgworker.c:100
#define InvalidPid
Definition: miscadmin.h:31
void TerminateBackgroundWorker ( BackgroundWorkerHandle handle)

Definition at line 1134 of file bgworker.c.

References Assert, BackgroundWorkerSlot::generation, BackgroundWorkerHandle::generation, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), max_worker_processes, PMSIGNAL_BACKGROUND_WORKER_CHANGE, SendPostmasterSignal(), BackgroundWorkerArray::slot, BackgroundWorkerHandle::slot, and BackgroundWorkerSlot::terminate.

Referenced by cleanup_background_workers(), and DestroyParallelContext().

1135 {
1136  BackgroundWorkerSlot *slot;
1137  bool signal_postmaster = false;
1138 
1139  Assert(handle->slot < max_worker_processes);
1140  slot = &BackgroundWorkerData->slot[handle->slot];
1141 
1142  /* Set terminate flag in shared memory, unless slot has been reused. */
1143  LWLockAcquire(BackgroundWorkerLock, LW_EXCLUSIVE);
1144  if (handle->generation == slot->generation)
1145  {
1146  slot->terminate = true;
1147  signal_postmaster = true;
1148  }
1149  LWLockRelease(BackgroundWorkerLock);
1150 
1151  /* Make sure the postmaster notices the change to shared memory. */
1152  if (signal_postmaster)
1154 }
static BackgroundWorkerArray * BackgroundWorkerData
Definition: bgworker.c:109
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1715
#define Assert(condition)
Definition: c.h:675
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1111
int max_worker_processes
Definition: globals.c:124
void SendPostmasterSignal(PMSignalReason reason)
Definition: pmsignal.c:113
BackgroundWorkerSlot slot[FLEXIBLE_ARRAY_MEMBER]
Definition: bgworker.c:100
BgwHandleStatus WaitForBackgroundWorkerShutdown ( BackgroundWorkerHandle )

Definition at line 1095 of file bgworker.c.

References BGWH_POSTMASTER_DIED, BGWH_STOPPED, CHECK_FOR_INTERRUPTS, GetBackgroundWorkerPid(), MyProc, PGPROC::procLatch, ResetLatch(), status(), WAIT_EVENT_BGWORKER_SHUTDOWN, WaitLatch(), WL_LATCH_SET, and WL_POSTMASTER_DEATH.

Referenced by WaitForParallelWorkersToExit().

1096 {
1098  int rc;
1099 
1100  for (;;)
1101  {
1102  pid_t pid;
1103 
1105 
1106  status = GetBackgroundWorkerPid(handle, &pid);
1107  if (status == BGWH_STOPPED)
1108  break;
1109 
1110  rc = WaitLatch(&MyProc->procLatch,
1113 
1114  if (rc & WL_POSTMASTER_DEATH)
1115  {
1116  status = BGWH_POSTMASTER_DIED;
1117  break;
1118  }
1119 
1121  }
1122 
1123  return status;
1124 }
PGPROC * MyProc
Definition: proc.c:67
void ResetLatch(volatile Latch *latch)
Definition: latch.c:461
Latch procLatch
Definition: proc.h:103
int WaitLatch(volatile Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition: latch.c:300
BgwHandleStatus
Definition: bgworker.h:102
#define WL_POSTMASTER_DEATH
Definition: latch.h:128
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:97
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:224
#define WL_LATCH_SET
Definition: latch.h:124
BgwHandleStatus GetBackgroundWorkerPid(BackgroundWorkerHandle *handle, pid_t *pidp)
Definition: bgworker.c:1004
BgwHandleStatus WaitForBackgroundWorkerStartup ( BackgroundWorkerHandle handle,
pid_t *  pid 
)

Definition at line 1053 of file bgworker.c.

References BGWH_NOT_YET_STARTED, BGWH_POSTMASTER_DIED, BGWH_STARTED, CHECK_FOR_INTERRUPTS, GetBackgroundWorkerPid(), MyLatch, ResetLatch(), status(), WAIT_EVENT_BGWORKER_STARTUP, WaitLatch(), WL_LATCH_SET, and WL_POSTMASTER_DEATH.

Referenced by worker_spi_launch().

1054 {
1056  int rc;
1057 
1058  for (;;)
1059  {
1060  pid_t pid;
1061 
1063 
1064  status = GetBackgroundWorkerPid(handle, &pid);
1065  if (status == BGWH_STARTED)
1066  *pidp = pid;
1067  if (status != BGWH_NOT_YET_STARTED)
1068  break;
1069 
1070  rc = WaitLatch(MyLatch,
1073 
1074  if (rc & WL_POSTMASTER_DEATH)
1075  {
1076  status = BGWH_POSTMASTER_DIED;
1077  break;
1078  }
1079 
1081  }
1082 
1083  return status;
1084 }
void ResetLatch(volatile Latch *latch)
Definition: latch.c:461
int WaitLatch(volatile Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition: latch.c:300
BgwHandleStatus
Definition: bgworker.h:102
#define WL_POSTMASTER_DEATH
Definition: latch.h:128
struct Latch * MyLatch
Definition: globals.c:51
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:97
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:224
#define WL_LATCH_SET
Definition: latch.h:124
BgwHandleStatus GetBackgroundWorkerPid(BackgroundWorkerHandle *handle, pid_t *pidp)
Definition: bgworker.c:1004

Variable Documentation