forkable.h
Go to the documentation of this file.
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 
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.
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
grpc_event_engine::experimental::RegisterForkHandlers
void RegisterForkHandlers()
Definition: forkable.cc:90
grpc_event_engine::experimental::Forkable::~Forkable
virtual ~Forkable()
Definition: forkable.cc:88
grpc_event_engine::experimental::PostforkChild
void PostforkChild()
Definition: forkable.cc:93
grpc_event_engine::experimental::PostforkParent
void PostforkParent()
Definition: forkable.cc:92
grpc_event_engine::experimental::StopManagingForkable
void StopManagingForkable(Forkable *)
Definition: forkable.cc:96
grpc_event_engine::experimental::Forkable
Definition: forkable.h:40
grpc_event_engine
Definition: endpoint_config.h:24
grpc_event_engine::experimental::Forkable::PostforkChild
virtual void PostforkChild()=0
grpc_event_engine::experimental::PrepareFork
void PrepareFork()
Definition: forkable.cc:91
grpc_event_engine::experimental::Forkable::PrepareFork
virtual void PrepareFork()=0
grpc_event_engine::experimental::Forkable::PostforkParent
virtual void PostforkParent()=0
grpc_event_engine::experimental::Forkable::Forkable
Forkable()
Definition: forkable.cc:87
grpc_event_engine::experimental::ManageForkable
void ManageForkable(Forkable *)
Definition: forkable.cc:95
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:59:22