OSDN Git Service

Update copyright to 2004.
[pg-rex/syncrep.git] / src / include / storage / pg_sema.h
1 /*-------------------------------------------------------------------------
2  *
3  * pg_sema.h
4  *        Platform-independent API for semaphores.
5  *
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.
11  *
12  *
13  * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
14  * Portions Copyright (c) 1994, Regents of the University of California
15  *
16  * $PostgreSQL: pgsql/src/include/storage/pg_sema.h,v 1.6 2004/08/29 04:13:10 momjian Exp $
17  *
18  *-------------------------------------------------------------------------
19  */
20 #ifndef PG_SEMA_H
21 #define PG_SEMA_H
22
23 /*
24  * PGSemaphoreData and pointer type PGSemaphore are the data structure
25  * representing an individual semaphore.  The contents of PGSemaphoreData
26  * vary across implementations and must never be touched by platform-
27  * independent code.  PGSemaphoreData structures are always allocated
28  * in shared memory (to support implementations where the data changes during
29  * lock/unlock).
30  *
31  * pg_config.h must define exactly one of the USE_xxx_SEMAPHORES symbols.
32  */
33
34 #ifdef USE_NAMED_POSIX_SEMAPHORES
35
36 #include <semaphore.h>
37
38 typedef sem_t *PGSemaphoreData;
39 #endif
40
41 #ifdef USE_UNNAMED_POSIX_SEMAPHORES
42
43 #include <semaphore.h>
44
45 typedef sem_t PGSemaphoreData;
46 #endif
47
48 #ifdef USE_SYSV_SEMAPHORES
49
50 typedef struct PGSemaphoreData
51 {
52         int                     semId;                  /* semaphore set identifier */
53         int                     semNum;                 /* semaphore number within set */
54 } PGSemaphoreData;
55 #endif
56
57 typedef PGSemaphoreData *PGSemaphore;
58
59
60 /* Module initialization (called during postmaster start or shmem reinit) */
61 extern void PGReserveSemaphores(int maxSemas, int port);
62
63 /* Initialize a PGSemaphore structure to represent a sema with count 1 */
64 extern void PGSemaphoreCreate(PGSemaphore sema);
65
66 /* Reset a previously-initialized PGSemaphore to have count 0 */
67 extern void PGSemaphoreReset(PGSemaphore sema);
68
69 /* Lock a semaphore (decrement count), blocking if count would be < 0 */
70 extern void PGSemaphoreLock(PGSemaphore sema, bool interruptOK);
71
72 /* Unlock a semaphore (increment count) */
73 extern void PGSemaphoreUnlock(PGSemaphore sema);
74
75 /* Lock a semaphore only if able to do so without blocking */
76 extern bool PGSemaphoreTryLock(PGSemaphore sema);
77
78 #endif   /* PG_SEMA_H */