Browse Source

revamp and move timeval functions

pull/81/head
Richard Fuchs 11 years ago
parent
commit
0e4e6f2f3c
4 changed files with 45 additions and 67 deletions
  1. +43
    -0
      daemon/aux.h
  2. +0
    -52
      daemon/call.c
  3. +0
    -13
      daemon/call.h
  4. +2
    -2
      daemon/ice.c

+ 43
- 0
daemon/aux.h View File

@ -782,4 +782,47 @@ INLINE void atomic64_local_copy_zero(atomic64 *dst, atomic64 *src) {
/*** TIMEVAL FUNCTIONS ***/
INLINE long long timeval_ms(const struct timeval *t) {
return (long long) ((long long) t->tv_sec * 1000000LL) + t->tv_usec;
}
INLINE void timeval_from_ms(struct timeval *t, long long ms) {
t->tv_sec = ms/1000000LL;
t->tv_usec = ms%1000000LL;
}
INLINE long long timeval_diff(const struct timeval *a, const struct timeval *b) {
return timeval_ms(a) - timeval_ms(b);
}
INLINE void timeval_subtract(struct timeval *result, const struct timeval *a, const struct timeval *b) {
timeval_from_ms(result, timeval_diff(a, b));
}
INLINE void timeval_multiply(struct timeval *result, const struct timeval *a, const long multiplier) {
timeval_from_ms(result, timeval_ms(a) * multiplier);
}
INLINE void timeval_divide(struct timeval *result, const struct timeval *a, const long divisor) {
timeval_from_ms(result, timeval_ms(a) / divisor);
}
INLINE void timeval_add(struct timeval *result, const struct timeval *a, const struct timeval *b) {
timeval_from_ms(result, timeval_ms(a) + timeval_ms(b));
}
INLINE void timeval_add_usec(struct timeval *tv, long usec) {
timeval_from_ms(tv, timeval_ms(tv) + usec);
}
INLINE int timeval_cmp(const struct timeval *a, const struct timeval *b) {
long long diff;
diff = timeval_diff(a, b);
if (diff < 0)
return -1;
if (diff > 0)
return 1;
return 0;
}
INLINE void timeval_lowest(struct timeval *l, const struct timeval *n) {
if (!n->tv_sec)
return;
if (!l->tv_sec || timeval_cmp(l, n) == 1)
*l = *n;
}
#endif

+ 0
- 52
daemon/call.c View File

@ -2561,58 +2561,6 @@ static void __unkernelize(struct packet_stream *p) {
PS_CLEAR(p, KERNELIZED);
}
/* XXX move these somewhere else */
u_int64_t timeval_diff(const struct timeval *a, const struct timeval *b) {
u_int64_t microseconds;
microseconds = ((u_int64_t)a->tv_sec - (u_int64_t)b->tv_sec) * 1000000LLU + (a->tv_usec - b->tv_usec);
return microseconds;
}
void timeval_subtract (struct timeval *result, const struct timeval *a, const struct timeval *b) {
u_int64_t microseconds;
microseconds = timeval_diff(a, b);
result->tv_sec = microseconds/1000000LLU;
result->tv_usec = microseconds%1000000LLU;
}
void timeval_multiply(struct timeval *result, const struct timeval *a, const long multiplier) {
u_int64_t microseconds;
microseconds = (((u_int64_t)a->tv_sec * 1000000LLU) + a->tv_usec) * multiplier;
result->tv_sec = microseconds/1000000LLU;
result->tv_usec = microseconds%1000000LLU;
}
void timeval_divide(struct timeval *result, const struct timeval *a, const long divisor) {
u_int64_t microseconds;
microseconds = (((u_int64_t)a->tv_sec * 1000000LLU) + a->tv_usec) / divisor;
result->tv_sec = microseconds/1000000LLU;
result->tv_usec = microseconds%1000000LLU;
}
void timeval_add(struct timeval *result, const struct timeval *a, const struct timeval *b) {
u_int64_t microseconds;
microseconds = ((u_int64_t)a->tv_sec + (u_int64_t)b->tv_sec) * 1000000LLU + (a->tv_usec + b->tv_usec);
result->tv_sec = microseconds/1000000LLU;
result->tv_usec = microseconds%1000000LLU;
}
void timeval_add_usec(struct timeval *tv, long usec) {
struct timeval a;
a.tv_sec = usec / 1000000LLU;
a.tv_usec = usec % 1000000LLU;
timeval_add(tv, tv, &a);
}
int timeval_cmp(const struct timeval *a, const struct timeval *b) {
if (a->tv_sec < b->tv_sec)
return -1;
if (a->tv_sec > b->tv_sec)
return 1;
if (a->tv_usec < b->tv_usec)
return -1;
if (a->tv_usec > b->tv_usec)
return 1;
return 0;
}
static void timeval_totalstats_average_add(struct totalstats *s, const struct timeval *add) {
struct timeval dp, oa;


+ 0
- 13
daemon/call.h View File

@ -510,19 +510,6 @@ struct interface_address *get_any_interface_address(struct local_interface *lif,
const struct transport_protocol *transport_protocol(const str *s);
void timeval_subtract (struct timeval *result, const struct timeval *a, const struct timeval *b);
void timeval_multiply(struct timeval *result, const struct timeval *a, const long multiplier);
void timeval_divide(struct timeval *result, const struct timeval *a, const long divisor);
void timeval_add(struct timeval *result, const struct timeval *a, const struct timeval *b);
int timeval_cmp(const struct timeval *a, const struct timeval *b);
void timeval_add_usec(struct timeval *tv, long usec);
u_int64_t timeval_diff(const struct timeval *a, const struct timeval *b);
INLINE void timeval_lowest(struct timeval *l, const struct timeval *n) {
if (!n->tv_sec)
return;
if (!l->tv_sec || timeval_cmp(l, n) == 1)
*l = *n;
}
INLINE void *call_malloc(struct call *c, size_t l) {


+ 2
- 2
daemon/ice.c View File

@ -493,7 +493,7 @@ static void __agent_schedule(struct ice_agent *ag, unsigned long usec) {
}
static void __agent_schedule_abs(struct ice_agent *ag, const struct timeval *tv) {
struct timeval nxt;
unsigned long diff;
long long diff;
nxt = *tv;
@ -1264,7 +1264,7 @@ err:
void ice_thread_run(void *p) {
struct ice_agent *ag;
struct call *call;
unsigned long sleeptime;
long long sleeptime;
struct timeval tv;
mutex_lock(&ice_agents_timers_lock);


Loading…
Cancel
Save