PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
condition_variable.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * condition_variable.h
4  * Condition variables
5  *
6  * A condition variable is a method of waiting until a certain condition
7  * becomes true. Conventionally, a condition variable supports three
8  * operations: (1) sleep; (2) signal, which wakes up one process sleeping
9  * on the condition variable; and (3) broadcast, which wakes up every
10  * process sleeping on the condition variable. In our implementation,
11  * condition variables put a process into an interruptible sleep (so it
12  * can be cancelled prior to the fulfillment of the condition) and do not
13  * use pointers internally (so that they are safe to use within DSMs).
14  *
15  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
16  * Portions Copyright (c) 1994, Regents of the University of California
17  *
18  * src/include/storage/condition_variable.h
19  *
20  *-------------------------------------------------------------------------
21  */
22 #ifndef CONDITION_VARIABLE_H
23 #define CONDITION_VARIABLE_H
24 
25 #include "storage/s_lock.h"
26 #include "storage/proclist_types.h"
27 
28 typedef struct
29 {
33 
34 /* Initialize a condition variable. */
36 
37 /*
38  * To sleep on a condition variable, a process should use a loop which first
39  * checks the condition, exiting the loop if it is met, and then calls
40  * ConditionVariableSleep. Spurious wakeups are possible, but should be
41  * infrequent. After exiting the loop, ConditionVariableCancelSleep should
42  * be called to ensure that the process is no longer in the wait list for
43  * the condition variable.
44  */
45 extern void ConditionVariableSleep(ConditionVariable *, uint32 wait_event_info);
46 extern void ConditionVariableCancelSleep(void);
47 
48 /*
49  * The use of this function is optional and not necessary for correctness;
50  * for efficiency, it should be called prior entering the loop described above
51  * if it is thought that the condition is unlikely to hold immediately.
52  */
54 
55 /* Wake up a single waiter (via signal) or all waiters (via broadcast). */
58 
59 #endif /* CONDITION_VARIABLE_H */
int slock_t
Definition: s_lock.h:888
int ConditionVariableBroadcast(ConditionVariable *)
void ConditionVariableInit(ConditionVariable *)
proclist_head wakeup
void ConditionVariableCancelSleep(void)
void ConditionVariableSleep(ConditionVariable *, uint32 wait_event_info)
unsigned int uint32
Definition: c.h:265
bool ConditionVariableSignal(ConditionVariable *)
void ConditionVariablePrepareToSleep(ConditionVariable *)