Return-Path: Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 25596 invoked by uid 500); 20 Jun 2002 03:38:09 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 25585 invoked from network); 20 Jun 2002 03:38:08 -0000 Date: Wed, 19 Jun 2002 20:38:42 -0700 From: Brian Pane Subject: Re: apr_uuid is not thread safe In-reply-to: To: dev@apr.apache.org Message-id: <1024544323.10883.11.camel@localhost> MIME-version: 1.0 X-Mailer: Ximian Evolution 1.0.3 (1.0.3-4) Content-type: text/plain Content-transfer-encoding: 7BIT References: X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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