apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject cvs commit: apr/atomic/unix apr_atomic.c
Date Mon, 08 Dec 2003 22:58:03 GMT
trawick     2003/12/08 14:58:02

  Modified:    atomic/unix apr_atomic.c
  Log:
  changes to the apr atomic implementations for unix-ish boxes
  
  a) need to check for __ppc__ on Darwin to pick up the PPC
     non-portable atomics
  
  b) axe the historic checks for defined(apr_atomic_foo) when deciding
     whether to generate the default version of apr_atomic_foo; checking
     for APR_OVERRIDE_ATOMIC_FOO is sufficient
  
  c) if the platform has defined apr_atomic_cas32() but not all the
     other apr_atomic_foo32(), use apr_atomic_cas32() in a generic
     version that will be much preferable to the no-cas32 version
     (which must use locking)
  
  Revision  Changes    Path
  1.35      +69 -33    apr/atomic/unix/apr_atomic.c
  
  Index: apr_atomic.c
  ===================================================================
  RCS file: /home/cvs/apr/atomic/unix/apr_atomic.c,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- apr_atomic.c	8 Dec 2003 19:49:16 -0000	1.34
  +++ apr_atomic.c	8 Dec 2003 22:58:02 -0000	1.35
  @@ -175,7 +175,7 @@
   
   #endif /* (__linux__ || __EMX__ || __FreeBSD__) && __i386__ */
   
  -#if defined(__PPC__) && defined(__GNUC__) && !APR_FORCE_ATOMIC_GENERIC
  +#if (defined(__PPC__) || defined(__ppc__)) && defined(__GNUC__) && !APR_FORCE_ATOMIC_GENERIC
   APR_DECLARE(apr_uint32_t) apr_atomic_cas32(volatile apr_uint32_t *mem,
                                              apr_uint32_t swap,
                                              apr_uint32_t cmp)
  @@ -200,7 +200,7 @@
   
   #endif /* __PPC__ && __GNUC__ */
   
  -#if !defined(apr_atomic_init) && !defined(APR_OVERRIDE_ATOMIC_INIT)
  +#if !defined(APR_OVERRIDE_ATOMIC_INIT)
   
   #if APR_HAS_THREADS
   #define NUM_ATOMIC_HASH 7
  @@ -226,12 +226,24 @@
   #endif /* APR_HAS_THREADS */
       return APR_SUCCESS;
   }
  -#endif /*!defined(apr_atomic_init) && !defined(APR_OVERRIDE_ATOMIC_INIT) */
  +#endif /* !defined(APR_OVERRIDE_ATOMIC_INIT) */
   
   /* abort() if 'x' does not evaluate to APR_SUCCESS. */
   #define CHECK(x) do { if ((x) != APR_SUCCESS) abort(); } while (0)
   
  -#if !defined(apr_atomic_add32) && !defined(APR_OVERRIDE_ATOMIC_ADD32)
  +#if !defined(APR_OVERRIDE_ATOMIC_ADD32)
  +#if defined(APR_OVERRIDE_ATOMIC_CAS32)
  +apr_uint32_t apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
  +{
  +    apr_uint32_t old_value, new_value;
  +    
  +    do {
  +        old_value = *mem;
  +        new_value = old_value + val;
  +    } while (apr_atomic_cas32(mem, new_value, old_value) != old_value);
  +    return old_value;
  +}
  +#else
   apr_uint32_t apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
   {
       apr_uint32_t old_value;
  @@ -249,9 +261,21 @@
   #endif /* APR_HAS_THREADS */
       return old_value;
   }
  -#endif /*!defined(apr_atomic_sub32) && !defined(APR_OVERRIDE_ATOMIC_SUB32) */
  +#endif /* defined(APR_OVERRIDE_ATOMIC_CAS32) */
  +#endif /* !defined(APR_OVERRIDE_ATOMIC_SUB32) */
   
  -#if !defined(apr_atomic_sub32) && !defined(APR_OVERRIDE_ATOMIC_SUB32)
  +#if !defined(APR_OVERRIDE_ATOMIC_SUB32)
  +#if defined(APR_OVERRIDE_ATOMIC_CAS32)
  +void apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
  +{
  +    apr_uint32_t old_value, new_value;
  +    
  +    do {
  +        old_value = *mem;
  +        new_value = old_value - val;
  +    } while (apr_atomic_cas32(mem, new_value, old_value) != old_value);
  +}
  +#else
   void apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val) 
   {
   #if APR_HAS_THREADS
  @@ -264,9 +288,10 @@
       *mem -= val;
   #endif /* APR_HAS_THREADS */
   }
  -#endif /*!defined(apr_atomic_sub32) && !defined(APR_OVERRIDE_ATOMIC_SUB32) */
  +#endif /* defined(APR_OVERRIDE_ATOMIC_CAS32) */
  +#endif /* !defined(APR_OVERRIDE_ATOMIC_SUB32) */
   
  -#if !defined(apr_atomic_set32) && !defined(APR_OVERRIDE_ATOMIC_SET32)
  +#if !defined(APR_OVERRIDE_ATOMIC_SET32)
   void apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val) 
   {
   #if APR_HAS_THREADS
  @@ -279,29 +304,28 @@
       *mem = val;
   #endif /* APR_HAS_THREADS */
   }
  -#endif /*!defined(apr_atomic_set32) && !defined(APR_OVERRIDE_ATOMIC_SET32) */
  +#endif /* !defined(APR_OVERRIDE_ATOMIC_SET32) */
   
  -#if !defined(apr_atomic_inc32) && !defined(APR_OVERRIDE_ATOMIC_INC32)
  +#if !defined(APR_OVERRIDE_ATOMIC_INC32)
   apr_uint32_t apr_atomic_inc32(volatile apr_uint32_t *mem) 
   {
  -    apr_uint32_t old_value;
  -
  -#if APR_HAS_THREADS
  -    apr_thread_mutex_t *lock = hash_mutex[ATOMIC_HASH(mem)];
  -
  -    CHECK(apr_thread_mutex_lock(lock));
  -    old_value = *mem;
  -    (*mem)++;
  -    CHECK(apr_thread_mutex_unlock(lock));
  -#else
  -    old_value = *mem;
  -    (*mem)++;
  -#endif /* APR_HAS_THREADS */
  -    return old_value;
  +    return apr_atomic_add32(mem, 1);
   }
  -#endif /*!defined(apr_atomic_inc32) && !defined(APR_OVERRIDE_ATOMIC_INC32) */
  +#endif /* !defined(APR_OVERRIDE_ATOMIC_INC32) */
   
  -#if !defined(apr_atomic_dec32) && !defined(APR_OVERRIDE_ATOMIC_DEC32)
  +#if !defined(APR_OVERRIDE_ATOMIC_DEC32)
  +#if defined(APR_OVERRIDE_ATOMIC_CAS32)
  +int apr_atomic_dec32(volatile apr_uint32_t *mem)
  +{
  +    apr_uint32_t old_value, new_value;
  +    
  +    do {
  +        old_value = *mem;
  +        new_value = old_value - 1;
  +    } while (apr_atomic_cas32(mem, new_value, old_value) != old_value);
  +    return old_value != 1;
  +}
  +#else
   int apr_atomic_dec32(volatile apr_uint32_t *mem) 
   {
   #if APR_HAS_THREADS
  @@ -318,9 +342,10 @@
       return *mem; 
   #endif /* APR_HAS_THREADS */
   }
  -#endif /*!defined(apr_atomic_dec32) && !defined(APR_OVERRIDE_ATOMIC_DEC32) */
  +#endif /* defined(APR_OVERRIDE_ATOMIC_CAS32) */
  +#endif /* !defined(APR_OVERRIDE_ATOMIC_DEC32) */
   
  -#if !defined(apr_atomic_cas32) && !defined(APR_OVERRIDE_ATOMIC_CAS32)
  +#if !defined(APR_OVERRIDE_ATOMIC_CAS32)
   apr_uint32_t apr_atomic_cas32(volatile apr_uint32_t *mem, apr_uint32_t with,
   			      apr_uint32_t cmp)
   {
  @@ -342,9 +367,19 @@
   #endif /* APR_HAS_THREADS */
       return prev;
   }
  -#endif /*!defined(apr_atomic_cas32) && !defined(APR_OVERRIDE_ATOMIC_CAS32) */
  +#endif /* !defined(APR_OVERRIDE_ATOMIC_CAS32) */
   
  -#if !defined(apr_atomic_xchg32) && !defined(APR_OVERRIDE_ATOMIC_XCHG32)
  +#if !defined(APR_OVERRIDE_ATOMIC_XCHG32)
  +#if defined(APR_OVERRIDE_ATOMIC_CAS32)
  +apr_uint32_t apr_atomic_xchg32(volatile apr_uint32_t *mem, apr_uint32_t val)
  +{
  +    apr_uint32_t prev;
  +    do {
  +        prev = *mem;
  +    } while (apr_atomic_cas32(mem, val, prev) != prev);
  +    return prev;
  +}
  +#else
   apr_uint32_t apr_atomic_xchg32(volatile apr_uint32_t *mem, apr_uint32_t val)
   {
       apr_uint32_t prev;
  @@ -361,9 +396,10 @@
   #endif /* APR_HAS_THREADS */
       return prev;
   }
  -#endif /*!defined(apr_atomic_xchg32) && !defined(APR_OVERRIDE_ATOMIC_XCHG32) */
  +#endif /* defined(APR_OVERRIDE_ATOMIC_CAS32) */
  +#endif /* !defined(APR_OVERRIDE_ATOMIC_XCHG32) */
   
  -#if !defined(apr_atomic_casptr) && !defined(APR_OVERRIDE_ATOMIC_CASPTR)
  +#if !defined(APR_OVERRIDE_ATOMIC_CASPTR)
   void *apr_atomic_casptr(volatile void **mem, void *with, const void *cmp)
   {
       void *prev;
  @@ -384,7 +420,7 @@
   #endif /* APR_HAS_THREADS */
       return prev;
   }
  -#endif /*!defined(apr_atomic_casptr) && !defined(APR_OVERRIDE_ATOMIC_CASPTR) */
  +#endif /* !defined(APR_OVERRIDE_ATOMIC_CASPTR) */
   
   #if !defined(APR_OVERRIDE_ATOMIC_READ32)
   APR_DECLARE(apr_uint32_t) apr_atomic_read32(volatile apr_uint32_t *mem)
  
  
  

Mime
View raw message