/* * Allocate and initialize walsender-related shared memory. */ void ReplicationSlotsShmemInit(void) { bool found; if (max_replication_slots == 0) return; ReplicationSlotCtl = (ReplicationSlotCtlData *) ShmemInitStruct("ReplicationSlot Ctl", ReplicationSlotsShmemSize(), &found); LWLockRegisterTranche(LWTRANCHE_REPLICATION_SLOT_IO_IN_PROGRESS, "replication_slot_io"); if (!found) { int i; /* First time through, so initialize */ MemSet(ReplicationSlotCtl, 0, ReplicationSlotsShmemSize()); for (i = 0; i < max_replication_slots; i++) { ReplicationSlot *slot = &ReplicationSlotCtl->replication_slots[i]; /* everything else is zeroed by the memset above */ SpinLockInit(&slot->mutex); LWLockInitialize(&slot->io_in_progress_lock, LWTRANCHE_REPLICATION_SLOT_IO_IN_PROGRESS); ConditionVariableInit(&slot->active_cv); } } }
/* ---------------------------------------------------------------- * ExecBitmapHeapInitializeDSM * * Set up a parallel bitmap heap scan descriptor. * ---------------------------------------------------------------- */ void ExecBitmapHeapInitializeDSM(BitmapHeapScanState *node, ParallelContext *pcxt) { ParallelBitmapHeapState *pstate; EState *estate = node->ss.ps.state; dsa_area *dsa = node->ss.ps.state->es_query_dsa; /* If there's no DSA, there are no workers; initialize nothing. */ if (dsa == NULL) return; pstate = shm_toc_allocate(pcxt->toc, node->pscan_len); pstate->tbmiterator = 0; pstate->prefetch_iterator = 0; /* Initialize the mutex */ SpinLockInit(&pstate->mutex); pstate->prefetch_pages = 0; pstate->prefetch_target = 0; pstate->state = BM_INITIAL; ConditionVariableInit(&pstate->cv); SerializeSnapshot(estate->es_snapshot, pstate->phs_snapshot_data); shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, pstate); node->pstate = pstate; }
/* * btinitparallelscan -- initialize BTParallelScanDesc for parallel btree scan */ void btinitparallelscan(void *target) { BTParallelScanDesc bt_target = (BTParallelScanDesc) target; SpinLockInit(&bt_target->btps_mutex); bt_target->btps_scanPage = InvalidBlockNumber; bt_target->btps_pageStatus = BTPARALLEL_NOT_INITIALIZED; bt_target->btps_arrayKeyCount = 0; ConditionVariableInit(&bt_target->btps_cv); }
/* * Initialize this barrier. To use a static party size, provide the number of * participants to wait for at each phase indicating that that number of * backends is implicitly attached. To use a dynamic party size, specify zero * here and then use BarrierAttach() and * BarrierDetach()/BarrierArriveAndDetach() to register and deregister * participants explicitly. */ void BarrierInit(Barrier *barrier, int participants) { SpinLockInit(&barrier->mutex); barrier->participants = participants; barrier->arrived = 0; barrier->phase = 0; barrier->elected = 0; barrier->static_party = participants > 0; ConditionVariableInit(&barrier->condition_variable); }
/* ---------------------------------------------------------------- * ExecBitmapHeapInitializeDSM * * Set up a parallel bitmap heap scan descriptor. * ---------------------------------------------------------------- */ void ExecBitmapHeapInitializeDSM(BitmapHeapScanState *node, ParallelContext *pcxt) { ParallelBitmapHeapState *pstate; EState *estate = node->ss.ps.state; pstate = shm_toc_allocate(pcxt->toc, node->pscan_len); pstate->tbmiterator = 0; pstate->prefetch_iterator = 0; /* Initialize the mutex */ SpinLockInit(&pstate->mutex); pstate->prefetch_pages = 0; pstate->prefetch_target = 0; pstate->state = BM_INITIAL; ConditionVariableInit(&pstate->cv); SerializeSnapshot(estate->es_snapshot, pstate->phs_snapshot_data); shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, pstate); node->pstate = pstate; }