| 215 | } |
| 216 | |
| 217 | Error MCPServer::stop_game_process() { |
| 218 | OS::ProcessID pid_to_kill = 0; |
| 219 | { |
| 220 | MutexLock lock(process_mutex); |
| 221 | if (game_pid == 0) { |
| 222 | return ERR_DOES_NOT_EXIST; |
| 223 | } |
| 224 | pid_to_kill = game_pid; |
| 225 | } |
| 226 | |
| 227 | Error err = OS::get_singleton()->kill(pid_to_kill); |
| 228 | if (err == OK) { |
| 229 | // Wait up to 1s for it to exit and be reaped |
| 230 | uint64_t start = OS::get_singleton()->get_ticks_msec(); |
| 231 | while (OS::get_singleton()->is_process_running(pid_to_kill) && OS::get_singleton()->get_ticks_msec() - start < 1000) { |
| 232 | OS::get_singleton()->delay_usec(10000); |
| 233 | } |
| 234 | MutexLock lock(process_mutex); |
| 235 | if (game_pid == pid_to_kill) { |
| 236 | game_pid = 0; |
| 237 | } |
| 238 | } |
| 239 | return err; |
| 240 | } |
| 241 | |
| 242 | bool MCPServer::is_game_running() const { |
| 243 | MutexLock lock(process_mutex); |
no test coverage detected