36 #ifndef HAVE_UNION_SEMUN
54 #define SEMAS_PER_SET 16
56 #define IPCProtection (0600)
58 #define PGSemaMagic 537
101 int saved_errno = errno;
109 if (saved_errno == EEXIST || saved_errno == EACCES
111 || saved_errno ==
EIDRM
120 (
errmsg(
"could not create semaphores: %m"),
121 errdetail(
"Failed system call was semget(%lu, %d, 0%o).",
122 (
unsigned long) semKey,
numSems,
124 (saved_errno == ENOSPC) ?
125 errhint(
"This error does *not* mean that you have run out of disk space. "
126 "It occurs when either the system limit for the maximum number of "
127 "semaphore sets (SEMMNI), or the system wide maximum number of "
128 "semaphores (SEMMNS), would be exceeded. You need to raise the "
129 "respective kernel parameter. Alternatively, reduce PostgreSQL's "
130 "consumption of semaphores by reducing its \"max_connections\" parameter.\n"
131 "The PostgreSQL documentation contains more information about "
132 "configuring your system for PostgreSQL.") : 0));
149 int saved_errno = errno;
153 semId, semNum,
value),
154 (saved_errno == ERANGE) ?
155 errhint(
"You possibly need to raise your kernel's SEMVMX value to be at least "
156 "%d. Look into the PostgreSQL documentation for details.",
172 elog(
LOG,
"semctl(%d, 0, IPC_RMID, ...) failed: %m", semId);
183 return semctl(semId, semNum,
GETVAL, dummy);
194 return semctl(semId, semNum,
GETPID, dummy);
238 if (creatorPID != getpid())
240 if (
kill(creatorPID, 0) == 0 || errno != ESRCH)
275 mysema.semId = semId;
323 errmsg(
"could not stat data directory \"%s\": %m",
379 elog(
PANIC,
"too many semaphores created");
386 elog(
PANIC,
"too many semaphores created");
421 sops.sem_num = sema->
semNum;
434 errStatus = semop(sema->
semId, &sops, 1);
435 }
while (errStatus < 0 && errno ==
EINTR);
454 sops.sem_num = sema->
semNum;
464 errStatus = semop(sema->
semId, &sops, 1);
465 }
while (errStatus < 0 && errno ==
EINTR);
484 sops.sem_num = sema->
semNum;
493 errStatus = semop(sema->
semId, &sops, 1);
494 }
while (errStatus < 0 && errno ==
EINTR);
503 #if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
#define Assert(condition)
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,...)
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
struct PGSemaphoreData * PGSemaphore
Size mul_size(Size s1, Size s2)
void * ShmemAllocUnlocked(Size size)
Size PGSemaphoreShmemSize(int maxSemas)
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
static IpcSemaphoreId InternalIpcSemaphoreCreate(IpcSemaphoreKey semKey, int numSems)
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)