corto_void _os_sleep(corto_uint32 sec, corto_uint32 nsec) { /* $begin(::corto::os::sleep) */ corto_sleep(sec, nsec); /* $end */ }
static corto_ll cortotool_waitForChanges(corto_pid pid, corto_ll files, corto_ll changed) { corto_int32 i = 0; if (changed) { corto_ll_free(changed); changed = NULL; } do { corto_sleep(0, 50000000); /* Check if process is still running */ if (pid) { if ((retcode = corto_proccheck(pid, NULL))) { break; } } i++; /* Only check files every second */ if (!(i % 20)) { changed = cortotool_getModified(files, changed); } else { continue; } }while (!changed || (pid && retcode)); return changed; }
void* corto_mount_thread(void* arg) { corto_mount this = arg; corto_float64 frequency = this->policy.sampleRate; corto_time interval = corto_mount_doubleToTime(1.0 / frequency); corto_time next, current, sleep = {0, 0}, lastSleep = {0, 0}; corto_timeGet(&next); next = corto_timeAdd(next, interval); while (!this->quit) { corto_mount_onPoll(this); corto_timeGet(¤t); lastSleep = sleep; sleep = corto_timeSub(next, current); if (lastSleep.sec || lastSleep.nanosec) { /* Attempt to limit the amount of oscillation in a fully loaded system */ if (corto_time_compare(lastSleep, sleep) == CORTO_LT) { double tmp = (corto_timeToDouble(sleep) + corto_timeToDouble(lastSleep)) / 2; sleep = corto_mount_doubleToTime(tmp); } } if (sleep.sec >= 0) { corto_sleep(sleep.sec, sleep.nanosec); } else { sleep = corto_timeSub(current, next); corto_warning( "processing events took [%d.%.9d] longer than sampleRate interval", sleep.sec, sleep.nanosec); corto_timeGet(&next); } next = corto_timeAdd(next, interval); } return NULL; }