36#ifndef HAVE_UNION_SEMUN
54#define SEMAS_PER_SET 16
56#define IPCProtection (0600)
58#define PGSemaMagic 537
105 int saved_errno = errno;
122 (saved_errno == EEXIST
123 || saved_errno == EACCES
124 || saved_errno == EINVAL
126 || saved_errno ==
EIDRM
135 (
errmsg(
"could not create semaphores: %m"),
136 errdetail(
"Failed system call was semget(%lu, %d, 0%o).",
137 (
unsigned long) semKey,
numSems,
139 (saved_errno == ENOSPC) ?
140 errhint(
"This error does *not* mean that you have run out of disk space. "
141 "It occurs when either the system limit for the maximum number of "
142 "semaphore sets (SEMMNI), or the system wide maximum number of "
143 "semaphores (SEMMNS), would be exceeded. You need to raise the "
144 "respective kernel parameter. Alternatively, reduce PostgreSQL's "
145 "consumption of semaphores by reducing its \"max_connections\" parameter.\n"
146 "The PostgreSQL documentation contains more information about "
147 "configuring your system for PostgreSQL.") : 0));
164 int saved_errno = errno;
168 semId, semNum,
value),
169 (saved_errno == ERANGE) ?
170 errhint(
"You possibly need to raise your kernel's SEMVMX value to be at least "
171 "%d. Look into the PostgreSQL documentation for details.",
187 elog(
LOG,
"semctl(%d, 0, IPC_RMID, ...) failed: %m", semId);
198 return semctl(semId, semNum,
GETVAL, dummy);
209 return semctl(semId, semNum,
GETPID, dummy);
258 if (creatorPID != getpid())
260 if (
kill(creatorPID, 0) == 0 || errno != ESRCH)
295 mysema.semId = semId;
343 errmsg(
"could not stat data directory \"%s\": %m",
395 elog(
PANIC,
"too many semaphores created");
402 elog(
PANIC,
"too many semaphores created");
437 sops.sem_num = sema->
semNum;
450 errStatus = semop(sema->
semId, &sops, 1);
451 }
while (errStatus < 0 && errno ==
EINTR);
470 sops.sem_num = sema->
semNum;
480 errStatus = semop(sema->
semId, &sops, 1);
481 }
while (errStatus < 0 && errno ==
EINTR);
500 sops.sem_num = sema->
semNum;
509 errStatus = semop(sema->
semId, &sops, 1);
510 }
while (errStatus < 0 && errno ==
EINTR);
519#if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
int errmsg_internal(const char *fmt,...)
int errcode_for_file_access(void)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
Assert(PointerIsAligned(start, uint64))
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
struct PGSemaphoreData * PGSemaphore
Size mul_size(Size s1, Size s2)
void * ShmemAlloc(Size size)
Size PGSemaphoreShmemSize(int maxSemas)
static IpcSemaphoreId InternalIpcSemaphoreCreate(IpcSemaphoreKey semKey, int numSems, bool retry_ok)
void PGSemaphoreUnlock(PGSemaphore sema)
struct PGSemaphoreData PGSemaphoreData
static pid_t IpcSemaphoreGetLastPID(IpcSemaphoreId semId, int semNum)
static int IpcSemaphoreGetValue(IpcSemaphoreId semId, int semNum)
void PGReserveSemaphores(int maxSemas)
static void IpcSemaphoreKill(IpcSemaphoreId semId)
static int maxSharedSemas
void PGSemaphoreReset(PGSemaphore sema)
void PGSemaphoreLock(PGSemaphore sema)
static IpcSemaphoreKey nextSemaKey
bool PGSemaphoreTryLock(PGSemaphore sema)
static int nextSemaNumber
static PGSemaphore sharedSemas
PGSemaphore PGSemaphoreCreate(void)
static int numSharedSemas
static void ReleaseSemaphores(int status, Datum arg)
static IpcSemaphoreId * mySemaSets
static IpcSemaphoreId IpcSemaphoreCreate(int numSems)
static void IpcSemaphoreInitialize(IpcSemaphoreId semId, int semNum, int value)