Logo Search packages:      
Sourcecode: pulseaudio version File versions

pa_usec_t pa_timeval_diff ( const struct timeval *  a,
const struct timeval *  b 
)

Calculate the difference between the two specified timeval structs.

Definition at line 78 of file timeval.c.

                                                                            {
    pa_usec_t r;

    pa_assert(a);
    pa_assert(b);

    /* Check which whan is the earlier time and swap the two arguments if required. */
    if (pa_timeval_cmp(a, b) < 0) {
        const struct timeval *c;
        c = a;
        a = b;
        b = c;
    }

    /* Calculate the second difference*/
    r = ((pa_usec_t) a->tv_sec - (pa_usec_t) b->tv_sec) * PA_USEC_PER_SEC;

    /* Calculate the microsecond difference */
    if (a->tv_usec > b->tv_usec)
        r += ((pa_usec_t) a->tv_usec - (pa_usec_t) b->tv_usec);
    else if (a->tv_usec < b->tv_usec)
        r -= ((pa_usec_t) b->tv_usec - (pa_usec_t) a->tv_usec);

    return r;
}


Generated by  Doxygen 1.6.0   Back to index