FreeBSD/tools/tools/netrate/netsend/netsend.c
/*
 * Busy wait spinning until we reach (or slightly pass) the desired time.
 * Optionally return the current time as retrieved on the last time check
 * to the caller.  Optionally also increment a counter provided by the
 * caller each time we loop.
 */
Busy wait spinning until we reach (or slightly pass) the desired time.
Optionally return the current time as retrieved on the last time check
to the caller.  Optionally also increment a counter provided by the
caller each time we loop.
Busy wait spinning until we reach ( or slightly pass ) the desired time . Optionally return the current time as retrieved on the last time check to the caller . Optionally also increment a counter provided by the caller each time we loop .
static int
wait_time(struct timespec ts, struct timespec *wakeup_ts, long long *waited)
{
	struct timespec curtime;
	curtime.tv_sec = 0;
	curtime.tv_nsec = 0;
	if (clock_gettime(CLOCK_REALTIME, &curtime) == -1) {
		perror("clock_gettime");
		return (-1);
	}
#if 0
	if (timespec_ge(&curtime, &ts))
		printf("warning: wait_time missed deadline without spinning\n");
#endif
	while (timespec_ge(&ts, &curtime)) {
		if (waited != NULL)
			(*waited)++;
		if (clock_gettime(CLOCK_REALTIME, &curtime) == -1) {
			perror("clock_gettime");
			return (-1);
		}
	}
	if (wakeup_ts != NULL)
		*wakeup_ts = curtime;
	return (0);
}
static int wait_time ( struct timespec ts , struct timespec * wakeup_ts , long long * waited ) { struct timespec curtime ; curtime . tv_sec = 0 ; curtime . tv_nsec = 0 ; if ( clock_gettime ( CLOCK_REALTIME , & curtime ) == -1 ) { perror ( " " ) ; return ( -1 ) ; } #if 0 if ( timespec_ge ( & curtime , & ts ) ) printf ( " \n " ) ; #endif while ( timespec_ge ( & ts , & curtime ) ) { if ( waited != NULL ) ( * waited ) ++ ; if ( clock_gettime ( CLOCK_REALTIME , & curtime ) == -1 ) { perror ( " " ) ; return ( -1 ) ; } } if ( wakeup_ts != NULL ) * wakeup_ts = curtime ; return ( 0 ) ; }
Busy wait spinning until we reach (or slightly pass) the desired time.
Busy wait spinning until we reach ( or slightly pass ) the desired time .