| 454 | } |
| 455 | |
| 456 | void kwsysProcess_Delete(kwsysProcess* cp) |
| 457 | { |
| 458 | int i; |
| 459 | |
| 460 | /* Make sure we have an instance. */ |
| 461 | if (!cp) { |
| 462 | return; |
| 463 | } |
| 464 | |
| 465 | /* If the process is executing, wait for it to finish. */ |
| 466 | if (cp->State == kwsysProcess_State_Executing) { |
| 467 | if (cp->Detached) { |
| 468 | kwsysProcess_Disown(cp); |
| 469 | } else { |
| 470 | kwsysProcess_WaitForExit(cp, 0); |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | /* We are deleting the kwsysProcess instance. */ |
| 475 | cp->Deleting = 1; |
| 476 | |
| 477 | /* Terminate each of the threads. */ |
| 478 | for (i = 0; i < KWSYSPE_PIPE_COUNT; ++i) { |
| 479 | /* Terminate this reading thread. */ |
| 480 | if (cp->Pipe[i].Reader.Thread) { |
| 481 | /* Signal the thread we are ready for it. It will terminate |
| 482 | immediately since Deleting is set. */ |
| 483 | ReleaseSemaphore(cp->Pipe[i].Reader.Ready, 1, 0); |
| 484 | |
| 485 | /* Wait for the thread to exit. */ |
| 486 | WaitForSingleObject(cp->Pipe[i].Reader.Thread, INFINITE); |
| 487 | |
| 488 | /* Close the handle to the thread. */ |
| 489 | kwsysProcessCleanupHandle(&cp->Pipe[i].Reader.Thread); |
| 490 | } |
| 491 | |
| 492 | /* Terminate this waking thread. */ |
| 493 | if (cp->Pipe[i].Waker.Thread) { |
| 494 | /* Signal the thread we are ready for it. It will terminate |
| 495 | immediately since Deleting is set. */ |
| 496 | ReleaseSemaphore(cp->Pipe[i].Waker.Ready, 1, 0); |
| 497 | |
| 498 | /* Wait for the thread to exit. */ |
| 499 | WaitForSingleObject(cp->Pipe[i].Waker.Thread, INFINITE); |
| 500 | |
| 501 | /* Close the handle to the thread. */ |
| 502 | kwsysProcessCleanupHandle(&cp->Pipe[i].Waker.Thread); |
| 503 | } |
| 504 | |
| 505 | /* Cleanup the pipe's semaphores. */ |
| 506 | kwsysProcessCleanupHandle(&cp->Pipe[i].Reader.Ready); |
| 507 | kwsysProcessCleanupHandle(&cp->Pipe[i].Reader.Go); |
| 508 | kwsysProcessCleanupHandle(&cp->Pipe[i].Reader.Reset); |
| 509 | kwsysProcessCleanupHandle(&cp->Pipe[i].Waker.Ready); |
| 510 | kwsysProcessCleanupHandle(&cp->Pipe[i].Waker.Go); |
| 511 | kwsysProcessCleanupHandle(&cp->Pipe[i].Waker.Reset); |
| 512 | } |
| 513 |
no test coverage detected
searching dependent graphs…