| 145 | }; |
| 146 | |
| 147 | AtForkState* GetAtForkState() { |
| 148 | static std::unique_ptr<AtForkState> state = []() { |
| 149 | auto state = std::make_unique<AtForkState>(); |
| 150 | #ifndef _WIN32 |
| 151 | int r = pthread_atfork(/*prepare=*/[] { GetAtForkState()->BeforeFork(); }, |
| 152 | /*parent=*/[] { GetAtForkState()->AfterForkParent(); }, |
| 153 | /*child=*/[] { GetAtForkState()->AfterForkChild(); }); |
| 154 | if (r != 0) { |
| 155 | IOErrorFromErrno(r, "Error when calling pthread_atfork: ").Abort(); |
| 156 | } |
| 157 | #endif |
| 158 | return state; |
| 159 | }(); |
| 160 | return state.get(); |
| 161 | } |
| 162 | |
| 163 | }; // namespace |
| 164 |
no test coverage detected