apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jor...@apache.org
Subject cvs commit: apr/atomic/unix apr_atomic.c
Date Fri, 05 Dec 2003 13:12:04 GMT
jorton      2003/12/05 05:12:04

  Modified:    atomic/unix apr_atomic.c
  Log:
  * apr_atomic.c: abort() if any mutex locking or unlocking calls fail.
  
  Revision  Changes    Path
  1.31      +42 -51    apr/atomic/unix/apr_atomic.c
  
  Index: apr_atomic.c
  ===================================================================
  RCS file: /home/cvs/apr/atomic/unix/apr_atomic.c,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -u -r1.30 -r1.31
  --- apr_atomic.c	4 Dec 2003 22:14:16 -0000	1.30
  +++ apr_atomic.c	5 Dec 2003 13:12:03 -0000	1.31
  @@ -56,6 +56,8 @@
   #include "apr_atomic.h"
   #include "apr_thread_mutex.h"
   
  +#include <stdlib.h>
  +
   #if defined(__FreeBSD__) && !defined(__i386__) && !APR_FORCE_ATOMIC_GENERIC
   
   #include <machine/atomic.h>
  @@ -199,6 +201,9 @@
   }
   #endif /*!defined(apr_atomic_init) && !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)
   apr_uint32_t apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
   {
  @@ -207,11 +212,10 @@
   #if APR_HAS_THREADS
       apr_thread_mutex_t *lock = hash_mutex[ATOMIC_HASH(mem)];
          
  -    if (apr_thread_mutex_lock(lock) == APR_SUCCESS) {
  -        old_value = *mem;
  -        *mem += val;
  -        apr_thread_mutex_unlock(lock);
  -    }
  +    CHECK(apr_thread_mutex_lock(lock));
  +    old_value = *mem;
  +    *mem += val;
  +    CHECK(apr_thread_mutex_unlock(lock));
   #else
       old_value = *mem;
       *mem += val;
  @@ -226,10 +230,9 @@
   #if APR_HAS_THREADS
       apr_thread_mutex_t *lock = hash_mutex[ATOMIC_HASH(mem)];
          
  -    if (apr_thread_mutex_lock(lock) == APR_SUCCESS) {
  -        *mem -= val;
  -        apr_thread_mutex_unlock(lock);
  -    }
  +    CHECK(apr_thread_mutex_lock(lock));
  +    *mem -= val;
  +    CHECK(apr_thread_mutex_unlock(lock));
   #else
       *mem -= val;
   #endif /* APR_HAS_THREADS */
  @@ -242,10 +245,9 @@
   #if APR_HAS_THREADS
       apr_thread_mutex_t *lock = hash_mutex[ATOMIC_HASH(mem)];
   
  -    if (apr_thread_mutex_lock(lock) == APR_SUCCESS) {
  -        *mem = val;
  -        apr_thread_mutex_unlock(lock);
  -    }
  +    CHECK(apr_thread_mutex_lock(lock));
  +    *mem = val;
  +    CHECK(apr_thread_mutex_unlock(lock));
   #else
       *mem = val;
   #endif /* APR_HAS_THREADS */
  @@ -260,11 +262,10 @@
   #if APR_HAS_THREADS
       apr_thread_mutex_t *lock = hash_mutex[ATOMIC_HASH(mem)];
   
  -    if (apr_thread_mutex_lock(lock) == APR_SUCCESS) {
  -        old_value = *mem;
  -        (*mem)++;
  -        apr_thread_mutex_unlock(lock);
  -    }
  +    CHECK(apr_thread_mutex_lock(lock));
  +    old_value = *mem;
  +    (*mem)++;
  +    CHECK(apr_thread_mutex_unlock(lock));
   #else
       old_value = *mem;
       (*mem)++;
  @@ -280,16 +281,15 @@
       apr_thread_mutex_t *lock = hash_mutex[ATOMIC_HASH(mem)];
       apr_uint32_t new;
   
  -    if (apr_thread_mutex_lock(lock) == APR_SUCCESS) {
  -        (*mem)--;
  -        new = *mem;
  -        apr_thread_mutex_unlock(lock);
  -        return new; 
  -    }
  +    CHECK(apr_thread_mutex_lock(lock));
  +    (*mem)--;
  +    new = *mem;
  +    CHECK(apr_thread_mutex_unlock(lock));
  +    return new;
   #else
       (*mem)--;
  -#endif /* APR_HAS_THREADS */
       return *mem; 
  +#endif /* APR_HAS_THREADS */
   }
   #endif /*!defined(apr_atomic_dec32) && !defined(APR_OVERRIDE_ATOMIC_DEC32) */
   
  @@ -301,22 +301,19 @@
   #if APR_HAS_THREADS
       apr_thread_mutex_t *lock = hash_mutex[ATOMIC_HASH(mem)];
   
  -    if (apr_thread_mutex_lock(lock) == APR_SUCCESS) {
  -        prev = *mem;
  -        if (prev == cmp) {
  -            *mem = with;
  -        }
  -        apr_thread_mutex_unlock(lock);
  -        return prev;
  +    CHECK(apr_thread_mutex_lock(lock));
  +    prev = *mem;
  +    if (prev == cmp) {
  +        *mem = with;
       }
  -    return *mem;
  +    CHECK(apr_thread_mutex_unlock(lock));
   #else
       prev = *mem;
       if (prev == cmp) {
           *mem = with;
       }
  -    return prev;
   #endif /* APR_HAS_THREADS */
  +    return prev;
   }
   #endif /*!defined(apr_atomic_cas32) && !defined(APR_OVERRIDE_ATOMIC_CAS32) */
   
  @@ -327,18 +324,15 @@
   #if APR_HAS_THREADS
       apr_thread_mutex_t *lock = hash_mutex[ATOMIC_HASH(mem)];
   
  -    if (apr_thread_mutex_lock(lock) == APR_SUCCESS) {
  -        prev = *mem;
  -        *mem = val;
  -        apr_thread_mutex_unlock(lock);
  -        return prev;
  -    }
  -    return *mem;
  +    CHECK(apr_thread_mutex_lock(lock));
  +    prev = *mem;
  +    *mem = val;
  +    CHECK(apr_thread_mutex_unlock(lock));
   #else
       prev = *mem;
       *mem = val;
  -    return prev;
   #endif /* APR_HAS_THREADS */
  +    return prev;
   }
   #endif /*!defined(apr_atomic_xchg32) && !defined(APR_OVERRIDE_ATOMIC_XCHG32) */
   
  @@ -349,22 +343,19 @@
   #if APR_HAS_THREADS
       apr_thread_mutex_t *lock = hash_mutex[ATOMIC_HASH(mem)];
   
  -    if (apr_thread_mutex_lock(lock) == APR_SUCCESS) {
  -        prev = *(void **)mem;
  -        if (prev == cmp) {
  -            *mem = with;
  -        }
  -        apr_thread_mutex_unlock(lock);
  -        return prev;
  +    CHECK(apr_thread_mutex_lock(lock));
  +    prev = *(void **)mem;
  +    if (prev == cmp) {
  +        *mem = with;
       }
  -    return *(void **)mem;
  +    CHECK(apr_thread_mutex_unlock(lock));
   #else
       prev = *(void **)mem;
       if (prev == cmp) {
           *mem = with;
       }
  -    return prev;
   #endif /* APR_HAS_THREADS */
  +    return prev;
   }
   #endif /*!defined(apr_atomic_casptr) && !defined(APR_OVERRIDE_ATOMIC_CASPTR) */
   
  
  
  

Mime
View raw message