Debian Codegraph @

src/core/lib/event_engine/forkable.h

raw
1 // Copyright 2022 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #ifndef GRPC_CORE_LIB_EVENT_ENGINE_FORKABLE_H
15 #define GRPC_CORE_LIB_EVENT_ENGINE_FORKABLE_H
16
17 #include <grpc/support/port_platform.h>
18
19 namespace grpc_event_engine {
20 namespace experimental {
21
22 // Register fork handlers with the system, enabling fork support.
23 //
24 // This provides pthread-based support for fork events. Any objects that
25 // implement Forkable can register themselves with this system using
26 // ManageForkable, and their respective methods will be called upon fork.
27 //
28 // This should be called once upon grpc_initialization.
29 void RegisterForkHandlers();
30
31 // Global callback for pthread_atfork's *prepare argument
32 void PrepareFork();
33 // Global callback for pthread_atfork's *parent argument
34 void PostforkParent();
35 // Global callback for pthread_atfork's *child argument
36 void PostforkChild();
37
38 // An interface to be implemented by EventEngines that wish to have managed fork
39 // support.
40 class Forkable {
41 public:
42 Forkable();
43 virtual ~Forkable();
44 virtual void PrepareFork() = 0;
45 virtual void PostforkParent() = 0;
46 virtual void PostforkChild() = 0;
47 };
48
49 // Add Forkables from the set of objects that are supported.
50 // Upon fork, each forkable will have its respective fork hooks called on
51 // the thread that invoked the fork.
52 //
53 // Relative ordering of fork callback operations is not guaranteed.
54 void ManageForkable(Forkable* forkable);
55 // Remove a forkable from the managed set.
56 void StopManagingForkable(Forkable* forkable);
57
58 } // namespace experimental
59 } // namespace grpc_event_engine
60
61 #endif // GRPC_CORE_LIB_EVENT_ENGINE_FORKABLE_H