Function called in each pipe's thread to handle data for one execution of a subprocess. */
| 1497 | execution of a subprocess. |
| 1498 | */ |
| 1499 | void kwsysProcessPipeThreadReadPipe(kwsysProcess* cp, kwsysProcessPipeData* td) |
| 1500 | { |
| 1501 | /* Wait for space in the thread's buffer. */ |
| 1502 | while ((KWSYSPE_DEBUG((stderr, "wait for read %d\n", td->Index)), |
| 1503 | WaitForSingleObject(td->Reader.Go, INFINITE), !td->Closed)) { |
| 1504 | KWSYSPE_DEBUG((stderr, "reading %d\n", td->Index)); |
| 1505 | |
| 1506 | /* Read data from the pipe. This may block until data are available. */ |
| 1507 | if (!ReadFile(td->Read, td->DataBuffer, KWSYSPE_PIPE_BUFFER_SIZE, |
| 1508 | &td->DataLength, 0)) { |
| 1509 | if (GetLastError() != ERROR_BROKEN_PIPE) { |
| 1510 | /* UNEXPECTED failure to read the pipe. */ |
| 1511 | } |
| 1512 | |
| 1513 | /* The pipe closed. There are no more data to read. */ |
| 1514 | td->Closed = 1; |
| 1515 | KWSYSPE_DEBUG((stderr, "read closed %d\n", td->Index)); |
| 1516 | } |
| 1517 | |
| 1518 | KWSYSPE_DEBUG((stderr, "read %d\n", td->Index)); |
| 1519 | |
| 1520 | /* Wait for our turn to be handled by the main thread. */ |
| 1521 | WaitForSingleObject(cp->SharedIndexMutex, INFINITE); |
| 1522 | |
| 1523 | KWSYSPE_DEBUG((stderr, "reporting read %d\n", td->Index)); |
| 1524 | |
| 1525 | /* Tell the main thread we have something to report. */ |
| 1526 | cp->SharedIndex = td->Index; |
| 1527 | ReleaseSemaphore(cp->Full, 1, 0); |
| 1528 | } |
| 1529 | |
| 1530 | /* We were signalled to exit with our buffer empty. Reset the |
| 1531 | mutex for a new process. */ |
| 1532 | KWSYSPE_DEBUG((stderr, "self releasing reader %d\n", td->Index)); |
| 1533 | ReleaseSemaphore(td->Reader.Go, 1, 0); |
| 1534 | } |
| 1535 | |
| 1536 | /* |
| 1537 | Function executed for each pipe's thread. Argument is a pointer to |
no test coverage detected