aboutsummaryrefslogtreecommitdiffstats
path: root/util/random/init_atfork.cpp
blob: 3397425a297a6accb45782391fb0dc79b629230d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "init_atfork.h"
#include "random.h"
#include "entropy.h"

#include <util/generic/singleton.h>
#include <util/system/yassert.h>

#if defined(_unix_)
    #include <pthread.h>
#endif

namespace {
    struct TInit {
        inline TInit() noexcept {
            (void)&AtFork; 

#if defined(_unix_)
            Y_VERIFY(pthread_atfork(nullptr, AtFork, nullptr) == 0, "it happens");
#endif
        }

        static void AtFork() noexcept {
            ResetRandomState();
        }
    };
}

void RNGInitAtForkHandlers() {
    SingletonWithPriority<TInit, 0>();
}