aboutsummaryrefslogtreecommitdiff
path: root/src/include/storage/condition_variable.h
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-01-08 18:28:03 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2018-01-08 18:28:03 -0500
commite35dba475a440f73dccf9ed1fd61e3abc6ee61db (patch)
tree5080f6679f5179b27f11952b75c5c6956d6e131b /src/include/storage/condition_variable.h
parentea8e1bbc538444d373cf712a0f5188c906b71a9d (diff)
downloadpostgresql-e35dba475a440f73dccf9ed1fd61e3abc6ee61db.tar.gz
postgresql-e35dba475a440f73dccf9ed1fd61e3abc6ee61db.zip
Cosmetic improvements in condition_variable.[hc].
Clarify a bunch of comments. Discussion: https://postgr.es/m/CAEepm=0NWKehYw7NDoUSf8juuKOPRnCyY3vuaSvhrEWsOTAa3w@mail.gmail.com
Diffstat (limited to 'src/include/storage/condition_variable.h')
-rw-r--r--src/include/storage/condition_variable.h23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/include/storage/condition_variable.h b/src/include/storage/condition_variable.h
index c7afbbca429..7dac477d259 100644
--- a/src/include/storage/condition_variable.h
+++ b/src/include/storage/condition_variable.h
@@ -27,30 +27,33 @@
typedef struct
{
- slock_t mutex;
- proclist_head wakeup;
+ slock_t mutex; /* spinlock protecting the wakeup list */
+ proclist_head wakeup; /* list of wake-able processes */
} ConditionVariable;
/* Initialize a condition variable. */
-extern void ConditionVariableInit(ConditionVariable *);
+extern void ConditionVariableInit(ConditionVariable *cv);
/*
* To sleep on a condition variable, a process should use a loop which first
* checks the condition, exiting the loop if it is met, and then calls
* ConditionVariableSleep. Spurious wakeups are possible, but should be
- * infrequent. After exiting the loop, ConditionVariableCancelSleep should
+ * infrequent. After exiting the loop, ConditionVariableCancelSleep must
* be called to ensure that the process is no longer in the wait list for
- * the condition variable.
+ * the condition variable. Only one condition variable can be used at a
+ * time, ie, ConditionVariableCancelSleep must be called before any attempt
+ * is made to sleep on a different condition variable.
*/
-extern void ConditionVariableSleep(ConditionVariable *, uint32 wait_event_info);
+extern void ConditionVariableSleep(ConditionVariable *cv, uint32 wait_event_info);
extern void ConditionVariableCancelSleep(void);
/*
- * The use of this function is optional and not necessary for correctness;
- * for efficiency, it should be called prior entering the loop described above
- * if it is thought that the condition is unlikely to hold immediately.
+ * Optionally, ConditionVariablePrepareToSleep can be called before entering
+ * the test-and-sleep loop described above. Doing so is more efficient if
+ * at least one sleep is needed, whereas not doing so is more efficient when
+ * no sleep is needed because the test condition is true the first time.
*/
-extern void ConditionVariablePrepareToSleep(ConditionVariable *);
+extern void ConditionVariablePrepareToSleep(ConditionVariable *cv);
/* Wake up a single waiter (via signal) or all waiters (via broadcast). */
extern void ConditionVariableSignal(ConditionVariable *cv);