Support condition variables

Enterprise / PostgreSQL - Robert Haas [postgresql.org] - 22 November 2016 13:27 UTC

Condition variables provide a flexible way to sleep until a cooperating process causes an arbitrary condition to become true. In simple cases, this can be accomplished with a WaitLatch/ResetLatch loop; the cooperating process can call SetLatch after performing work that might cause the condition to be satisfied, and the waiting process can recheck the condition each time. However, if the process performing the work doesn't have an easy way to identify which processes might be waiting, this doesn't work, because it can't identify which latches to set. Condition variables solve that problem by internally maintaining a list of waiters; a process that may have caused some waiter's condition to be satisfied must "signal" or "broadcast" on the condition variable.

Robert Haas and Thomas Munro

e8ac886 Support condition variables.
src/backend/access/transam/xact.c | 4 +
src/backend/bootstrap/bootstrap.c | 2 +
src/backend/postmaster/bgwriter.c | 2 +
src/backend/postmaster/checkpointer.c | 2 +
src/backend/postmaster/walwriter.c | 2 +
src/backend/replication/walsender.c | 2 +
src/backend/storage/lmgr/Makefile | 2 +-
src/backend/storage/lmgr/condition_variable.c | 225 +++++++++++++++++++++++++
src/backend/storage/lmgr/proc.c | 7 +
src/include/storage/condition_variable.h | 59 +++++++
src/include/storage/proc.h | 3 +
src/include/storage/proclist.h | 56 +++++-
12 files changed, 364 insertions(+), 2 deletions(-)

Upstream: git.postgresql.org


  • Share