| 74 | } |
| 75 | |
| 76 | void BeforeFork() { |
| 77 | // Lock the mutex and keep it locked until the end of AfterForkParent(), |
| 78 | // to avoid multiple concurrent forks and atforks. |
| 79 | mutex_.lock(); |
| 80 | |
| 81 | DCHECK(handlers_while_forking_.empty()); // AfterForkParent clears it |
| 82 | |
| 83 | for (const auto& weak_handler : handlers_) { |
| 84 | if (auto handler = weak_handler.lock()) { |
| 85 | handlers_while_forking_.emplace_back(std::move(handler)); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | // XXX can the handler call RegisterAtFork()? |
| 90 | for (auto&& handler : handlers_while_forking_) { |
| 91 | if (handler.handler->before) { |
| 92 | handler.token = handler.handler->before(); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | void AfterForkParent() { |
| 98 | // The mutex was locked by BeforeFork() |
no test coverage detected