init_atfork.cpp 566 B

1234567891011121314151617181920212223242526272829
  1. #include "init_atfork.h"
  2. #include "random.h"
  3. #include <util/generic/singleton.h>
  4. #include <util/system/yassert.h>
  5. #if defined(_unix_)
  6. #include <pthread.h>
  7. #endif
  8. namespace {
  9. struct TInit {
  10. inline TInit() noexcept {
  11. (void)&AtFork;
  12. #if defined(_unix_)
  13. Y_ABORT_UNLESS(pthread_atfork(nullptr, AtFork, nullptr) == 0, "it happens");
  14. #endif
  15. }
  16. static void AtFork() noexcept {
  17. ResetRandomState();
  18. }
  19. };
  20. } // namespace
  21. void RNGInitAtForkHandlers() {
  22. SingletonWithPriority<TInit, 0>();
  23. }