bool timestamp_elapsed_safe(int a, int b) { if (a == 0) { return true; } return timestamp_ms() >= a || timestamp_ms() < (a - b + 100); }
int timestamp(int delta_ms ) { int t2; if (delta_ms < 0 ) return 0; if (delta_ms == 0 ) return 1; t2 = timestamp_ms() + delta_ms; if ( t2 > MAX_TIME ) { // wrap!!! t2 = delta_ms - (MAX_TIME-timestamp_ms()); } if (t2 < 2 ) t2 = 2; // hack?? return t2; }
bool timestamp_elapsed(int stamp) { if (stamp == 0) { return false; } return timestamp_ms() >= stamp; }
void print_stat_collection_csv(struct stat_collection* stats, struct timeval* time) { // time, ipv4_packet, arp_packet, unknown_packet printf("%li,%" PRIu64 ",%" PRIu64 ",%" PRIu64 "\n", timestamp_ms(*time), stats->ipv4_packet->value, stats->arp_packet->value, stats->unknown_packet->value ); };
int timestamp_has_time_elapsed(int stamp, int time) { int t; if (time <= 0) return 1; t = stamp + time; if (t <= timestamp_ms()) return 1; // if we are unlucky enough to have it wrap on us, this will assume time has elapsed. return 0; }
void timestamp_inc(fix frametime) { // Compute the microseconds, assumes that a fix uses the lower 16 bit for storing the fractional part auto delta = (std::uint64_t)frametime; delta = delta * (MICROSECONDS_PER_SECOND / 65536); timestamp_ticker += delta; if ( timestamp_ms() > MAX_TIME ) { timestamp_ticker = 2; // Roll! } if (timestamp_ticker < 2 ) { mprintf(("Whoa!!! timestamp_ticker < 2 -- resetting to 2!!!\n")); timestamp_ticker = 2; } }
// Returns milliseconds until timestamp will elapse. // Negative value gives milliseconds ago that timestamp elapsed. int timestamp_until(int stamp) { // JAS: FIX // HACK!! This doesn't handle rollover! // (Will it ever happen?) return stamp - timestamp_ms(); /* uint delta; delta = stamp - timestamp_ticker; if (delta > UINT_MAX/2) delta = UINT_MAX - delta + 1; else if (delta < - ( (int) (UINT_MAX/2))) delta = UINT_MAX + delta + 1; return delta; */ }
// alternate timestamp functions. The way these work is you call xtimestamp() to get the // current counter value, and then call int timestamp() { return timestamp_ms(); }