/* * Release semaphores at shutdown or shmem reinitialization * * (called as an on_shmem_exit callback, hence funny argument list) */ static void ReleaseSemaphores(int status, Datum arg) { int i; for (i = 0; i < numSemaSets; i++) IpcSemaphoreKill(mySemaSets[i]); free(mySemaSets); }
/* * ProcFreeAllSemaphores - * on exiting the postmaster, we free up all the semaphores allocated * to the lmgrs of the backends. */ void ProcFreeAllSemaphores() { int i; int32 *freeSemMap = ProcGlobal->freeSemMap; for(i=0; i < MAX_PROC_SEMS/PROC_NSEMS_PER_SET; i++) { if (freeSemMap[i]!=0) IpcSemaphoreKill(ProcGlobal->currKey + i); } }
/* * ProcFreeSem - * free up our semaphore in the semaphore set. If we're the last one * in the set, also remove the semaphore set. */ static void ProcFreeSem(IpcSemaphoreKey semKey, int semNum) { int mask; int i; int32 *freeSemMap = ProcGlobal->freeSemMap; i = semKey - ProcGlobal->currKey; mask = ~(1 << semNum); freeSemMap[i] &= mask; if (freeSemMap[i]==0) IpcSemaphoreKill(semKey); }
/* * CreateSpinlocks -- Create a sysV semaphore array for * the spinlocks * */ bool CreateSpinlocks(IPCKey key) { int status; IpcSemaphoreId semid; semid = IpcSemaphoreCreate(key, MAX_SPINS, IPCProtection, IpcSemaphoreDefaultStartValue, 1, &status); if (status == IpcSemIdExist) { IpcSemaphoreKill(key); elog(NOTICE,"Destroying old spinlock semaphore"); semid = IpcSemaphoreCreate(key, MAX_SPINS, IPCProtection, IpcSemaphoreDefaultStartValue, 1, &status); } if (semid >= 0) { SpinLockId = semid; return(TRUE); } /* cannot create spinlocks */ elog(FATAL,"CreateSpinlocks: cannot create spin locks"); return(FALSE); }