summaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/threading/at_fork.h
blob: d95565f2b1cca5e974e71ef93c354fde583a9512 (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 "writer_starving_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.
TWriterStarvingRWSpinLock* GetForkLock();

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

} // namespace NYT::NThreading