aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/threading/at_fork.h
blob: bb9a2f2ebd5ec73011b713fa9426145fa4e8c61e (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
#pragma once

#include "rw_spin_lock.h"

#include <functional>

namespace NYT::NThreading {

////////////////////////////////////////////////////////////////////////////////

using TAtForkHandler = std::function<void()>;

//! Registers handlers to be invoked at fork time.
//! See |pthread_atfork| for more details.
/*!
 *  Once all prepare handlers are invoked, fork lock is acquired
 *  in writer mode. This lock is subsequently released in both child
 *  and parent processes once fork is complete.
 */
void RegisterAtForkHandlers(
    TAtForkHandler prepare,
    TAtForkHandler parent,
    TAtForkHandler child);

//! Returns the fork lock.
TReaderWriterSpinLock* GetForkLock();

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT::NThreading