/** The driver_wait function to work out if we have used more time then available to process one cycle. This is written once for either timespec (HAVE_CLOCK_GETTIME) or jack_time_t, see the unified_jack_time.h file. This function manages the time now and the next expected time to return. The return happens once per block of time (period_size). The general idea of *_driver_wait is to do the following : a] Mark the time now if this is the first time through or if an overrun previously happened. b] If an overrun is detected (we have exceeded the maximum time held in our audio buffers) then indicate. c] If we are late but not dangerously, then keep going. d] If we are early then sleep a little to allow clients enough time to process. The effect of 'c]' and 'd]' is to create time pumping. Theoretically we will always be either a little over or under time, and it will be difficult to match audio block time exactly. This doesn't matter if the time pumping is a small fraction of our block time. This means that the clients will have slightly more or less then audio block time to process. */ static jack_nframes_t iio_driver_wait(iio_driver_t *driver, int extra_fd, int *status, float *delayed_usecs) { jack_nframes_t nframes = driver->period_size; //Debugger<<"iio_driver_wait\n"; *delayed_usecs = 0; *status = 0; timeType now; getNow(&now); // the time right now if (compareTimesLt(NEXT_TIME, now)) { // NEXT_TIME < now ... this is a problem as the next time should be >= now //printf("iio_driver_wait NOT good\n"); if (compareTimeZero(NEXT_TIME)) { /* first time through */ //DebuggerLocal<<"iio_driver_first time - OK\n"; //printf("first time through\n\n\n"); getNow(&NEXT_TIME); // reset the next time to now, will be incremented later } else if (timeDiffUsComp(now, driver->next_wakeup, driver->maxDelayUSecs)) { /* xrun = (now - NEXT_TIME) > maxDelayTime */ ////Debugger<<"NEXT_TIME "<<NEXT_TIME<<" now "<<now<<endl; jack_error("**** iio: xrun of %ju usec", timeDiffUs(now, NEXT_TIME)); nframes=0; // indicated the xrun zeroTime(&NEXT_TIME); // reset the next time to zero because of the overrun, we don't know when to start again. //*status=-1; // xruns are fatal } else /* late, but handled by our "buffer" */ ; } else { // now sleep to ensure we give the clients enough time to process *status = nanoSleep(NEXT_TIME, delayed_usecs); //printf("iio_driver_wait all good\n"); } if (nframes!=0) // if there is no xrun, then indicate the next expected time to land in this funciton. NEXT_TIME=addTimes(NEXT_TIME, driver->wait_time); driver->last_wait_ust = driver->engine->get_microseconds (); driver->engine->transport_cycle_start (driver->engine, driver->last_wait_ust); return nframes; }
int main() { Time t1(6, 30); Time t2(8, 51); bool isGreaterThan = greaterThan(t1, t2); if (isGreaterThan) cout << "t1 > t2: TRUE" << endl; else cout << "t1 > t2: FALSE" << endl; bool isLessThan = lessThan(t1, t2); if (isLessThan) cout << "t1 < t2: TRUE" << endl; else cout << "t1 < t2: FALSE" << endl; bool isEqual = equals(t1, t2); if (isEqual) cout << "t1 = t2: TRUE" << endl; else cout << "t1 = t2: FALSE" << endl; Time t3 = addTimes(t1, t2); cout << "t3 - minutes: " << t3.getMinutes() << " seconds: " << t3.getSeconds() << endl; Time t4 = subtractTimes(t1, t2); cout << "t4 - minutes: " << t4.getMinutes() << " seconds: " << t4.getSeconds() << endl; return 0; }
ULONGLONG CpuUsage::getProcessNonIdleTimes() { FILETIME ftProcCreation, ftProcExit, ftProcKernel, ftProcUser; if (!GetProcessTimes(m_hProcess, &ftProcCreation, &ftProcExit, &ftProcKernel, &ftProcUser) && false) { errorMsg(TEXT("GetProcessNonIdleTimes")); return 0; } return addTimes(ftProcKernel, ftProcUser); }
ULONGLONG CpuUsage::getSystemNonIdleTimes() { FILETIME ftSysIdle, ftSysKernel, ftSysUser; if (!GetSystemTimes(&ftSysIdle, &ftSysKernel, &ftSysUser)) { errorMsg(TEXT("GetSystemTimes")); return 0; } return addTimes(ftSysKernel, ftSysUser); }
int main( int args, char **argc ) { int i; double radii[4] = { 1, 4.657, 10, 42 }; int moneyValues[4] = { 20, 79, 10, 42 }; int times[3][2] = {{ 1045, 345 }, { 800, 435 }, { 2300, 300 }}; for( i = 0; i < 11; i++ ) { if( i%4 == 0 ) printf( "\n" ); // Execution of part 1 if( i < 4 ) printf( "The volume for a sphere with radius %g is %3.7f\n", radii[i], volumeForRadius( radii[i] )); // Execution of part 2 if( i > 3 && i < 8 ) getChange( moneyValues[i%4]); // Execution of part 3 if( i > 7 ) printf( "Start time is %d. Duration is %d. End time is %d\n", times[i%4][START], times[i%4][DURATION], addTimes( times[i%4][START], times[i%4][DURATION] )); } }