at_fork.h 797 B

123456789101112131415161718192021222324252627282930
  1. #pragma once
  2. #include "rw_spin_lock.h"
  3. #include <functional>
  4. namespace NYT::NThreading {
  5. ////////////////////////////////////////////////////////////////////////////////
  6. using TAtForkHandler = std::function<void()>;
  7. //! Registers handlers to be invoked at fork time.
  8. //! See |pthread_atfork| for more details.
  9. /*!
  10. * Once all prepare handlers are invoked, fork lock is acquired
  11. * in writer mode. This lock is subsequently released in both child
  12. * and parent processes once fork is complete.
  13. */
  14. void RegisterAtForkHandlers(
  15. TAtForkHandler prepare,
  16. TAtForkHandler parent,
  17. TAtForkHandler child);
  18. //! Returns the fork lock.
  19. TReaderWriterSpinLock* GetForkLock();
  20. ////////////////////////////////////////////////////////////////////////////////
  21. } // namespace NYT::NThreading