On Wed, 2002-06-19 at 09:39, Doug MacEachern wrote:
> 
> static void get_current_time(apr_uint64_t *timestamp)
> {
>     /* ### this needs to be made thread-safe! */
> 
>     apr_uint64_t time_now;
>     static apr_uint64_t time_last = 0;
>     static int fudge = 0;
> 
> any plans/thoughts on making it threadsafe?

How about something like this as a replacement for the
get_current_time() logic...

for (;;) {
    gettimeofday(&now);
    if (now > time_last) {
        atomic_cas(&time_last, now, time_last);
        if (atomic_cas succeeded) {
            return now;
        }
    }
    else {
        now = time_last + 1;
        atomic_cas(&time_last, now, time_last);
        if (atomic_cas succeeded) {
            return now;
        }
    }
}

--Brian


Reply via email to