codekingpro/portable-devtools
114k
1/*-------------------------------------------------------------------------2 *3 * pg_sema.h4 * Platform-independent API for semaphores.5 *6 * PostgreSQL requires counting semaphores (the kind that keep track of7 * multiple unlock operations, and will allow an equal number of subsequent8 * lock operations before blocking). The underlying implementation is9 * not the same on every platform. This file defines the API that must10 * be provided by each port.11 *12 *13 * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group14 * Portions Copyright (c) 1994, Regents of the University of California15 *16 * src/include/storage/pg_sema.h17 *18 *-------------------------------------------------------------------------19 */20#ifndef PG_SEMA_H21#define PG_SEMA_H22 23/*24 * struct PGSemaphoreData and pointer type PGSemaphore are the data structure25 * representing an individual semaphore. The contents of PGSemaphoreData vary26 * across implementations and must never be touched by platform-independent27 * code; hence, PGSemaphoreData is declared as an opaque struct here.28 *29 * However, Windows is sufficiently unlike our other ports that it doesn't30 * seem worth insisting on ABI compatibility for Windows too. Hence, on31 * that platform just define PGSemaphore as HANDLE.32 */33#ifndef USE_WIN32_SEMAPHORES34typedef struct PGSemaphoreData *PGSemaphore;35#else36typedef HANDLE PGSemaphore;37#endif38 39 40/* Report amount of shared memory needed */41extern Size PGSemaphoreShmemSize(int maxSemas);42 43/* Module initialization (called during postmaster start or shmem reinit) */44extern void PGReserveSemaphores(int maxSemas);45 46/* Allocate a PGSemaphore structure with initial count 1 */47extern PGSemaphore PGSemaphoreCreate(void);48 49/* Reset a previously-initialized PGSemaphore to have count 0 */50extern void PGSemaphoreReset(PGSemaphore sema);51 52/* Lock a semaphore (decrement count), blocking if count would be < 0 */53extern void PGSemaphoreLock(PGSemaphore sema);54 55/* Unlock a semaphore (increment count) */56extern void PGSemaphoreUnlock(PGSemaphore sema);57 58/* Lock a semaphore only if able to do so without blocking */59extern bool PGSemaphoreTryLock(PGSemaphore sema);60 61#endif /* PG_SEMA_H */62 