/* Pointer to this process's PGPROC struct, if any */
PGPROC *MyProc = NULL;
-/*
- * This spinlock protects the freelist of recycled PGPROC structures.
- * We cannot use an LWLock because the LWLock manager depends on already
- * having a PGPROC and a wait semaphore! But these structures are touched
- * relatively infrequently (only at backend startup or shutdown) and not for
- * very long, so a spinlock is okay.
- */
-NON_EXEC_STATIC slock_t *ProcStructLock = NULL;
-
/* Pointers to shared-memory structures */
PROC_HDR *ProcGlobal = NULL;
NON_EXEC_STATIC PGPROC *AuxiliaryProcs = NULL;
* Initialize the data structures.
*/
ProcGlobal->spins_per_delay = DEFAULT_SPINS_PER_DELAY;
+ SpinLockInit(&ProcGlobal->freeProcsLock);
dlist_init(&ProcGlobal->freeProcs);
dlist_init(&ProcGlobal->autovacFreeProcs);
dlist_init(&ProcGlobal->bgworkerFreeProcs);
*/
AuxiliaryProcs = &procs[MaxBackends];
PreparedXactProcs = &procs[MaxBackends + NUM_AUXILIARY_PROCS];
-
- /* Create ProcStructLock spinlock, too */
- ProcStructLock = (slock_t *) ShmemInitStruct("ProcStructLock spinlock",
- sizeof(slock_t),
- &found);
- SpinLockInit(ProcStructLock);
}
/*
* Try to get a proc struct from the appropriate free list. If this
* fails, we must be out of PGPROC structures (not to mention semaphores).
*
- * While we are holding the ProcStructLock, also copy the current shared
+ * While we are holding the spinlock, also copy the current shared
* estimate of spins_per_delay to local storage.
*/
- SpinLockAcquire(ProcStructLock);
+ SpinLockAcquire(&ProcGlobal->freeProcsLock);
set_spins_per_delay(ProcGlobal->spins_per_delay);
if (!dlist_is_empty(procgloballist))
{
MyProc = dlist_container(PGPROC, links, dlist_pop_head_node(procgloballist));
- SpinLockRelease(ProcStructLock);
+ SpinLockRelease(&ProcGlobal->freeProcsLock);
}
else
{
* error message. XXX do we need to give a different failure message
* in the autovacuum case?
*/
- SpinLockRelease(ProcStructLock);
+ SpinLockRelease(&ProcGlobal->freeProcsLock);
if (AmWalSenderProcess())
ereport(FATAL,
(errcode(ERRCODE_TOO_MANY_CONNECTIONS),
RegisterPostmasterChildActive();
/*
- * We use the ProcStructLock to protect assignment and releasing of
+ * We use the freeProcsLock to protect assignment and releasing of
* AuxiliaryProcs entries.
*
- * While we are holding the ProcStructLock, also copy the current shared
+ * While we are holding the spinlock, also copy the current shared
* estimate of spins_per_delay to local storage.
*/
- SpinLockAcquire(ProcStructLock);
+ SpinLockAcquire(&ProcGlobal->freeProcsLock);
set_spins_per_delay(ProcGlobal->spins_per_delay);
}
if (proctype >= NUM_AUXILIARY_PROCS)
{
- SpinLockRelease(ProcStructLock);
+ SpinLockRelease(&ProcGlobal->freeProcsLock);
elog(FATAL, "all AuxiliaryProcs are in use");
}
/* use volatile pointer to prevent code rearrangement */
((volatile PGPROC *) auxproc)->pid = MyProcPid;
- SpinLockRelease(ProcStructLock);
+ SpinLockRelease(&ProcGlobal->freeProcsLock);
MyProc = auxproc;
MyProcNumber = GetNumberFromPGProc(MyProc);
Assert(n > 0);
Assert(nfree);
- SpinLockAcquire(ProcStructLock);
+ SpinLockAcquire(&ProcGlobal->freeProcsLock);
*nfree = 0;
dlist_foreach(iter, &ProcGlobal->freeProcs)
break;
}
- SpinLockRelease(ProcStructLock);
+ SpinLockRelease(&ProcGlobal->freeProcsLock);
return (*nfree == n);
}
procgloballist = leader->procgloballist;
/* Leader exited first; return its PGPROC. */
- SpinLockAcquire(ProcStructLock);
+ SpinLockAcquire(&ProcGlobal->freeProcsLock);
dlist_push_head(procgloballist, &leader->links);
- SpinLockRelease(ProcStructLock);
+ SpinLockRelease(&ProcGlobal->freeProcsLock);
}
}
else if (leader != MyProc)
proc->vxid.lxid = InvalidTransactionId;
procgloballist = proc->procgloballist;
- SpinLockAcquire(ProcStructLock);
+ SpinLockAcquire(&ProcGlobal->freeProcsLock);
/*
* If we're still a member of a locking group, that means we're a leader
/* Update shared estimate of spins_per_delay */
ProcGlobal->spins_per_delay = update_spins_per_delay(ProcGlobal->spins_per_delay);
- SpinLockRelease(ProcStructLock);
+ SpinLockRelease(&ProcGlobal->freeProcsLock);
}
/*
MyProcNumber = INVALID_PROC_NUMBER;
DisownLatch(&proc->procLatch);
- SpinLockAcquire(ProcStructLock);
+ SpinLockAcquire(&ProcGlobal->freeProcsLock);
/* Mark auxiliary proc no longer in use */
proc->pid = 0;
/* Update shared estimate of spins_per_delay */
ProcGlobal->spins_per_delay = update_spins_per_delay(ProcGlobal->spins_per_delay);
- SpinLockRelease(ProcStructLock);
+ SpinLockRelease(&ProcGlobal->freeProcsLock);
}
/*