barrier.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*-------------------------------------------------------------------------
  2. *
  3. * barrier.h
  4. * Barriers for synchronizing cooperating processes.
  5. *
  6. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  7. * Portions Copyright (c) 1994, Regents of the University of California
  8. *
  9. * src/include/storage/barrier.h
  10. *
  11. *-------------------------------------------------------------------------
  12. */
  13. #ifndef BARRIER_H
  14. #define BARRIER_H
  15. /*
  16. * For the header previously known as "barrier.h", please include
  17. * "port/atomics.h", which deals with atomics, compiler barriers and memory
  18. * barriers.
  19. */
  20. #include "storage/condition_variable.h"
  21. #include "storage/spin.h"
  22. typedef struct Barrier
  23. {
  24. slock_t mutex;
  25. int phase; /* phase counter */
  26. int participants; /* the number of participants attached */
  27. int arrived; /* the number of participants that have
  28. * arrived */
  29. int elected; /* highest phase elected */
  30. bool static_party; /* used only for assertions */
  31. ConditionVariable condition_variable;
  32. } Barrier;
  33. extern void BarrierInit(Barrier *barrier, int num_workers);
  34. extern bool BarrierArriveAndWait(Barrier *barrier, uint32 wait_event_info);
  35. extern bool BarrierArriveAndDetach(Barrier *barrier);
  36. extern bool BarrierArriveAndDetachExceptLast(Barrier *barrier);
  37. extern int BarrierAttach(Barrier *barrier);
  38. extern bool BarrierDetach(Barrier *barrier);
  39. extern int BarrierPhase(Barrier *barrier);
  40. extern int BarrierParticipants(Barrier *barrier);
  41. #endif /* BARRIER_H */