apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Pane <bp...@pacbell.net>
Subject Re: apr_uuid is not thread safe
Date Thu, 20 Jun 2002 03:38:42 GMT
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



Mime
View raw message