| 314 | } |
| 315 | |
| 316 | void EndProcess(process_t* process){ |
| 317 | asm("sti"); |
| 318 | while(process->children.get_length()) |
| 319 | EndProcess(process->children.get_front()); |
| 320 | |
| 321 | CPU* cpu = GetCPULocal(); |
| 322 | for(unsigned i = 0; i < process->threads.get_length(); i++){ |
| 323 | thread_t* thread = process->threads[i]; |
| 324 | if(thread != cpu->currentThread && thread){ |
| 325 | thread->state = ThreadStateZombie; |
| 326 | acquireLock(&thread->lock); // Make sure we acquire a lock on all threads to ensure that they are not in a syscall and are not retaining a lock |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | if(process->parent){ |
| 331 | process->parent->children.remove(process); |
| 332 | } |
| 333 | |
| 334 | processes->remove(process); |
| 335 | |
| 336 | for(thread_t* t : process->blocking){ |
| 337 | UnblockThread(t); |
| 338 | } |
| 339 | |
| 340 | for(unsigned i = 0; i < process->threads.get_length(); i++){ |
| 341 | thread_t* thread = process->threads[i]; |
| 342 | |
| 343 | for(List<thread_t*>* queue : thread->waiting){ |
| 344 | queue->remove(thread); |
| 345 | } |
| 346 | |
| 347 | process->threads[i]->waiting.clear(); |
| 348 | |
| 349 | thread->state = ThreadStateBlocked; |
| 350 | thread->timeSlice = thread->timeSliceDefault = 0; |
| 351 | } |
| 352 | |
| 353 | for(unsigned i = 0; i < process->fileDescriptors.get_length(); i++){ |
| 354 | if(process->fileDescriptors[i]){ |
| 355 | fs::Close(process->fileDescriptors[i]); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | acquireLock(&cpu->runQueueLock); |
| 360 | asm("cli"); |
| 361 | |
| 362 | for(unsigned j = 0; j < cpu->runQueue->get_length(); j++){ |
| 363 | if(cpu->runQueue->get_at(j)->parent == process) cpu->runQueue->remove_at(j); |
| 364 | } |
| 365 | |
| 366 | for(fs_fd_t* fd : process->fileDescriptors){ |
| 367 | if(fd && fd->node) |
| 368 | fd->node->Close(); |
| 369 | } |
| 370 | process->fileDescriptors.clear(); |
| 371 | |
| 372 | for(unsigned i = 0; i < SMP::processorCount; i++){ |
| 373 | if(i == cpu->id) continue; // Is current processor? |
no test coverage detected