[Fork] Noop RegisterForkable if fork support is not enabled (#35787)

<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #35787

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/35787 from yijiem:fix-fork 703b8ae039
PiperOrigin-RevId: 603492379
pull/35673/head
Yijie Ma 1 year ago committed by Copybara-Service
parent 610f439342
commit a61b58b0f1
  1. 12
      src/core/lib/event_engine/forkable.cc

@ -43,13 +43,15 @@ bool IsForkEnabled() {
void ObjectGroupForkHandler::RegisterForkable(
std::shared_ptr<Forkable> forkable, GRPC_UNUSED void (*prepare)(void),
GRPC_UNUSED void (*parent)(void), GRPC_UNUSED void (*child)(void)) {
GPR_ASSERT(!is_forking_);
forkables_.emplace_back(forkable);
if (IsForkEnabled()) {
GPR_ASSERT(!is_forking_);
forkables_.emplace_back(forkable);
#ifdef GRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK
if (!std::exchange(registered_, true)) {
pthread_atfork(prepare, parent, child);
}
if (!std::exchange(registered_, true)) {
pthread_atfork(prepare, parent, child);
}
#endif // GRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK
}
}
void ObjectGroupForkHandler::Prefork() {

Loading…
Cancel
Save