Unmark gen_random_uuid() function leakproof.
[pgsql.git] / src / include / storage / pg_sema.h
blobdfef79ac963846eacb7943a2b3f01c8875af44fd
1 /*-------------------------------------------------------------------------
3 * pg_sema.h
4 * Platform-independent API for semaphores.
6 * PostgreSQL requires counting semaphores (the kind that keep track of
7 * multiple unlock operations, and will allow an equal number of subsequent
8 * lock operations before blocking). The underlying implementation is
9 * not the same on every platform. This file defines the API that must
10 * be provided by each port.
13 * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
14 * Portions Copyright (c) 1994, Regents of the University of California
16 * src/include/storage/pg_sema.h
18 *-------------------------------------------------------------------------
20 #ifndef PG_SEMA_H
21 #define PG_SEMA_H
24 * struct PGSemaphoreData and pointer type PGSemaphore are the data structure
25 * representing an individual semaphore. The contents of PGSemaphoreData vary
26 * across implementations and must never be touched by platform-independent
27 * code; hence, PGSemaphoreData is declared as an opaque struct here.
29 * However, Windows is sufficiently unlike our other ports that it doesn't
30 * seem worth insisting on ABI compatibility for Windows too. Hence, on
31 * that platform just define PGSemaphore as HANDLE.
33 #ifndef USE_WIN32_SEMAPHORES
34 typedef struct PGSemaphoreData *PGSemaphore;
35 #else
36 typedef HANDLE PGSemaphore;
37 #endif
40 /* Report amount of shared memory needed */
41 extern Size PGSemaphoreShmemSize(int maxSemas);
43 /* Module initialization (called during postmaster start or shmem reinit) */
44 extern void PGReserveSemaphores(int maxSemas);
46 /* Allocate a PGSemaphore structure with initial count 1 */
47 extern PGSemaphore PGSemaphoreCreate(void);
49 /* Reset a previously-initialized PGSemaphore to have count 0 */
50 extern void PGSemaphoreReset(PGSemaphore sema);
52 /* Lock a semaphore (decrement count), blocking if count would be < 0 */
53 extern void PGSemaphoreLock(PGSemaphore sema);
55 /* Unlock a semaphore (increment count) */
56 extern void PGSemaphoreUnlock(PGSemaphore sema);
58 /* Lock a semaphore only if able to do so without blocking */
59 extern bool PGSemaphoreTryLock(PGSemaphore sema);
61 #endif /* PG_SEMA_H */