Browse Source

util: timer_remaining_us function

Luke Dashjr 11 years ago
parent
commit
bb116363d0
1 changed files with 10 additions and 1 deletions
  1. 10 1
      util.h

+ 10 - 1
util.h

@@ -1,5 +1,5 @@
 /*
- * Copyright 2013-2014 Luke Dashjr
+ * Copyright 2013-2015 Luke Dashjr
  * Copyright 2012-2014 Con Kolivas
  * Copyright 2011 Andrew Smith
  * Copyright 2011 Jeff Garzik
@@ -723,6 +723,15 @@ int timer_elapsed(const struct timeval *tvp_timer, const struct timeval *tvp_now
 	return tv.tv_sec;
 }
 
+static inline
+long timer_remaining_us(const struct timeval *tvp_timer, const struct timeval *tvp_now)
+{
+	struct timeval tv;
+	const struct timeval *_tvp_now = _bfg_nullisnow(tvp_now, &tv);
+	timersub(tvp_timer, _tvp_now, &tv);
+	return timeval_to_us(&tv);
+}
+
 static inline
 bool timer_passed(const struct timeval *tvp_timer, const struct timeval *tvp_now)
 {