| 113 | } |
| 114 | |
| 115 | void AfterForkChild() { |
| 116 | // Need to reinitialize the mutex as it is probably invalid. Also, the |
| 117 | // old mutex destructor may fail. |
| 118 | // Fortunately, we are a single thread in the child process by now, so no |
| 119 | // additional synchronization is needed. |
| 120 | new (&mutex_) std::mutex; |
| 121 | |
| 122 | auto handlers = std::move(handlers_while_forking_); |
| 123 | handlers_while_forking_.clear(); |
| 124 | |
| 125 | // Execute handlers in reverse order |
| 126 | for (auto it = handlers.rbegin(); it != handlers.rend(); ++it) { |
| 127 | auto&& handler = *it; |
| 128 | if (handler.handler->child_after) { |
| 129 | handler.handler->child_after(std::move(handler.token)); |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | void RegisterAtFork(std::weak_ptr<AtForkHandler> weak_handler) { |
| 135 | std::lock_guard<std::mutex> lock(mutex_); |
no test coverage detected