void readOutputAndClose()

in native/cyglaunch/main.c [119:142]


void readOutputAndClose(struct thread_data_t thread_data) {
    static long WAIT_NS = 200 * 1000000;
    static long MAX_NS = 999999999;

    timespec_t timespec;
    bool readComplete = false;
    while (!readComplete) {
        clock_gettime(CLOCK_REALTIME, &timespec);

        timespec.tv_nsec += WAIT_NS;
        if (timespec.tv_nsec > MAX_NS) {
            timespec.tv_sec += 1;
            timespec.tv_nsec -= MAX_NS;
        }

        pthread_mutex_lock(thread_data.mutex);
        readComplete = pthread_cond_timedwait(thread_data.condition, thread_data.mutex, &timespec) != 0;
        pthread_mutex_unlock(thread_data.mutex);
    }

    close(thread_data.fdm);
    pthread_join(thread_data.tid, NULL);
    CloseHandle(thread_data.pipe);
}