original) (raw)
PostgreSQL Source Code: src/backend/port/posix_sema.c File Reference (#include "[postgres.h](postgres%5F8h%5Fsource.html)"
#include <fcntl.h>
#include <semaphore.h>
#include <signal.h>
#include <[unistd.h](unistd%5F8h%5Fsource.html)>
#include <sys/stat.h>
#include "[miscadmin.h](miscadmin%5F8h%5Fsource.html)"
#include "[storage/ipc.h](ipc%5F8h%5Fsource.html)"
#include "[storage/pg_sema.h](pg%5F%5Fsema%5F8h%5Fsource.html)"
#include "[storage/shmem.h](shmem%5F8h%5Fsource.html)"
Go to the source code of this file.
Functions | |
---|---|
static void | ReleaseSemaphores (int status, Datum arg) |
static void | PosixSemaphoreCreate (sem_t *sem) |
static void | PosixSemaphoreKill (sem_t *sem) |
Size | PGSemaphoreShmemSize (int maxSemas) |
void | PGReserveSemaphores (int maxSemas) |
PGSemaphore | PGSemaphoreCreate (void) |
void | PGSemaphoreReset (PGSemaphore sema) |
void | PGSemaphoreLock (PGSemaphore sema) |
void | PGSemaphoreUnlock (PGSemaphore sema) |
bool | PGSemaphoreTryLock (PGSemaphore sema) |
Variables | |
---|---|
static PGSemaphore | sharedSemas |
static int | numSems |
static int | maxSems |
static int | nextSemKey |
◆ IPCProtection
#define IPCProtection (0600) /* access/modify by user only */
◆ PG_SEM_REF
| #define PG_SEM_REF | ( | | x | ) | (&(x)->sem_padded.pgsem) | | -------------------- | - | | ---------------------------------------------------- | - | ---------------------------------------------------------------------------- |
◆ PGSemaphoreData
◆ SemTPadded
◆ PGReserveSemaphores()
void PGReserveSemaphores | ( | int | maxSemas | ) |
---|
Definition at line 196 of file posix_sema.c.
197{
198 struct stat statbuf;
199
200
201
202
203
204
205
209 errmsg("could not stat data directory \"%s\": %m",
211
212#ifdef USE_NAMED_POSIX_SEMAPHORES
213 mySemPointers = (sem_t **) malloc(maxSemas * sizeof(sem_t *));
214 if (mySemPointers == NULL)
216#else
217
218
219
220
221
224#endif
225
229
231}
int errcode_for_file_access(void)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
struct PGSemaphoreData * PGSemaphore
Size PGSemaphoreShmemSize(int maxSemas)
static PGSemaphore sharedSemas
static void ReleaseSemaphores(int status, Datum arg)
void * ShmemAllocUnlocked(Size size)
References DataDir, elog, ereport, errcode_for_file_access(), errmsg(), FATAL, malloc, maxSems, nextSemKey, numSems, on_shmem_exit(), PANIC, PGSemaphoreShmemSize(), ReleaseSemaphores(), sharedSemas, ShmemAllocUnlocked(), stat::st_ino, and stat.
Referenced by CreateSharedMemoryAndSemaphores().
◆ PGSemaphoreCreate()
Definition at line 261 of file posix_sema.c.
262{
264 sem_t *newsem;
265
266
268
270 elog(PANIC, "too many semaphores created");
271
272#ifdef USE_NAMED_POSIX_SEMAPHORES
274
275 mySemPointers[numSems] = newsem;
277#else
281#endif
282
284
285 return sema;
286}
Assert(PointerIsAligned(start, uint64))
static void PosixSemaphoreCreate(sem_t *sem)
References Assert(), elog, IsUnderPostmaster, maxSems, numSems, PANIC, PG_SEM_REF, PosixSemaphoreCreate(), and sharedSemas.
Referenced by InitProcGlobal().
◆ PGSemaphoreLock()
◆ PGSemaphoreReset()
◆ PGSemaphoreShmemSize()
Size PGSemaphoreShmemSize | ( | int | maxSemas | ) |
---|
◆ PGSemaphoreTryLock()
Definition at line 364 of file posix_sema.c.
365{
366 int errStatus;
367
368
369
370
371
372
373 do
374 {
375 errStatus = sem_trywait(PG_SEM_REF(sema));
376 } while (errStatus < 0 && errno == EINTR);
377
378 if (errStatus < 0)
379 {
380 if (errno == EAGAIN || errno == EDEADLK)
381 return false;
382
383 elog(FATAL, "sem_trywait failed: %m");
384 }
385
386 return true;
387}
References EAGAIN, EINTR, elog, FATAL, and PG_SEM_REF.
◆ PGSemaphoreUnlock()
Definition at line 339 of file posix_sema.c.
340{
341 int errStatus;
342
343
344
345
346
347
348
349 do
350 {
351 errStatus = sem_post(PG_SEM_REF(sema));
352 } while (errStatus < 0 && errno == EINTR);
353
354 if (errStatus < 0)
355 elog(FATAL, "sem_post failed: %m");
356}
References EINTR, elog, FATAL, and PG_SEM_REF.
Referenced by LWLockAcquire(), LWLockAcquireOrWait(), LWLockDequeueSelf(), LWLockUpdateVar(), LWLockWaitForVar(), LWLockWakeup(), ProcArrayGroupClearXid(), and TransactionGroupUpdateXidStatus().
◆ PosixSemaphoreCreate()
static void PosixSemaphoreCreate ( sem_t * sem) | static |
---|
◆ PosixSemaphoreKill()
static void PosixSemaphoreKill ( sem_t * sem) | static |
---|
Definition at line 147 of file posix_sema.c.
148{
149#ifdef USE_NAMED_POSIX_SEMAPHORES
150
151 if (sem_close(sem) < 0)
152 elog(LOG, "sem_close failed: %m");
153#else
154
155 if (sem_destroy(sem) < 0)
156 elog(LOG, "sem_destroy failed: %m");
157#endif
158}
References elog, LOG, and sem.
Referenced by ReleaseSemaphores().
◆ ReleaseSemaphores()
static void ReleaseSemaphores ( int status, Datum arg ) | static |
---|