init_atfork.cpp 568 B

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