apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i...@apache.org
Subject cvs commit: apr/test testatomic.c
Date Wed, 20 Feb 2002 05:52:04 GMT
ianh        02/02/19 21:52:04

  Modified:    atomic/unix apr_atomic.c
               include  apr_atomic.h
               test     testatomic.c
  Log:
  linux compatibility checks
  use linux macro cmpxchg if available.
  now.. to retest solaris ;)
  
  Revision  Changes    Path
  1.7       +15 -12    apr/atomic/unix/apr_atomic.c
  
  Index: apr_atomic.c
  ===================================================================
  RCS file: /home/cvs/apr/atomic/unix/apr_atomic.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- apr_atomic.c	19 Feb 2002 23:15:39 -0000	1.6
  +++ apr_atomic.c	20 Feb 2002 05:52:04 -0000	1.7
  @@ -60,7 +60,7 @@
   
   #if APR_HAS_THREADS
   
  -#if defined(APR_ATOMIC_NEED_DEFAULT) 
  +#if defined(APR_ATOMIC_NEED_DEFAULT)  || defined(APR_ATOMIC_NEED_CAS_DEFAULT)
   
   #define NUM_ATOMIC_HASH 7
   /* shift by 2 to get rid of alignment issues */
  @@ -79,7 +79,10 @@
       }
       return APR_SUCCESS;
   }
  -apr_uint32_t apr_atomic_add(volatile apr_atomic_t *mem, apr_uint32_t val) 
  +#endif /* APR_ATOMIC_NEED_DEFAULT || APR_ATOMIC_NEED_CAS_DEFAULT */
  +
  +#if defined(APR_ATOMIC_NEED_DEFAULT) 
  +void apr_atomic_add(volatile apr_atomic_t *mem, apr_uint32_t val) 
   {
       apr_thread_mutex_t *lock = hash_mutex[ATOMIC_HASH(mem)];
       apr_uint32_t prev;
  @@ -93,7 +96,7 @@
       printf("debug no workee\n");
       return *mem;
   }
  -apr_uint32_t apr_atomic_set(volatile apr_atomic_t *mem, apr_uint32_t val) 
  +void apr_atomic_set(volatile apr_atomic_t *mem, apr_uint32_t val) 
   {
       apr_thread_mutex_t *lock = hash_mutex[ATOMIC_HASH(mem)];
       apr_uint32_t prev;
  @@ -107,7 +110,7 @@
       return *mem;
   }
   
  -apr_uint32_t apr_atomic_inc( volatile apr_uint32_t *mem) 
  +void apr_atomic_inc( volatile apr_uint32_t *mem) 
   {
       apr_thread_mutex_t *lock = hash_mutex[ATOMIC_HASH(mem)];
       apr_uint32_t prev;
  @@ -120,7 +123,7 @@
       }
       return *mem;
   }
  -apr_uint32_t apr_atomic_dec(volatile apr_atomic_t *mem) 
  +void apr_atomic_dec(volatile apr_atomic_t *mem) 
   {
       apr_thread_mutex_t *lock = hash_mutex[ATOMIC_HASH(mem)];
       apr_uint32_t prev;
  @@ -134,25 +137,25 @@
       return *mem;
   }
   
  +#endif /* APR_ATOMIC_NEED_DEFAULT */
   #if defined(APR_ATOMIC_NEED_CAS_DEFAULT)
   
  -long apr_atomic_cas(volatile apr_atomic_t *mem,long with, long cmp)
  +long apr_atomic_cas(volatile void *mem,long with, long cmp)
   {
       apr_thread_mutex_t *lock = hash_mutex[ATOMIC_HASH(mem)];
  -    apr_uint32_t prev;
  +    long prev;
   
       if (apr_thread_mutex_lock(lock) == APR_SUCCESS) {
  -        prev = *mem;
  -        if ( *mem == cmp) {
  -            *mem = with;
  +        prev = *(long*)mem;
  +        if ( prev == cmp) {
  +            *(long*)mem = with;
           }
           apr_thread_mutex_unlock(lock);
           return prev;
       }
  -    return *mem;
  +    return *(long*)mem;
   }
   #endif /* APR_ATOMIC_NEED_CAS_DEFAULT */
   
  -#endif /* APR_ATOMIC_NEED_DEFAULT */
   
   #endif /* APR_HAS_THREADS */
  
  
  
  1.9       +18 -14    apr/include/apr_atomic.h
  
  Index: apr_atomic.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_atomic.h,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- apr_atomic.h	19 Feb 2002 23:45:06 -0000	1.8
  +++ apr_atomic.h	20 Feb 2002 05:52:04 -0000	1.9
  @@ -99,30 +99,26 @@
    * set the value for atomic.
    * @param the pointer
    * @param the value
  - * @warning the return value is undefined at the moment
    */
  -apr_uint32_t apr_atomic_set(volatile apr_atomic_t *mem, apr_uint32_t val);
  +void apr_atomic_set(volatile apr_atomic_t *mem, apr_uint32_t val);
   /**
    * Add 'val' to the atomic variable
    * @param mem pointer to the atomic value
    * @param val the addition
  - * @return the old value of the atomic
    */
  -apr_uint32_t apr_atomic_add(volatile apr_atomic_t *mem, apr_uint32_t val);
  +void apr_atomic_add(volatile apr_atomic_t *mem, apr_uint32_t val);
   
   /**
    * increment the atomic variable by 1
    * @param mem pointer to the atomic value
  - * @return the old value of the atomic
    */
  -apr_uint32_t apr_atomic_inc(volatile apr_atomic_t *mem);
  +void apr_atomic_inc(volatile apr_atomic_t *mem);
   
   /**
    * decrement the atomic variable by 1
    * @param mem pointer to the atomic value
  - * @return the old value of the atomic
    */
  -apr_uint32_t apr_atomic_dec(volatile apr_atomic_t *mem);
  +void apr_atomic_dec(volatile apr_atomic_t *mem);
   
   /**
    * compare the atomic's value with cmp.
  @@ -131,8 +127,10 @@
    * @param with what to swap it with
    * @param the value to compare it to
    * @return the old value of the atomic
  + * @warning do not mix apr_atomic's with the CAS function.
  + * on some platforms they may be implemented by different mechanisms
    */
  -long apr_atomic_cas(volatile apr_atomic_t *mem,long with,long cmp);
  +apr_uint32_t apr_atomic_cas(volatile apr_uint32_t *mem,long with,long cmp);
   #else /* !DOXYGEN */
   
   #ifdef WIN32
  @@ -150,6 +148,7 @@
   #elif defined(__linux)
   
   #include <asm/atomic.h>
  +#include <asm/system.h>
   #define apr_atomic_t atomic_t
   
   #define apr_atomic_add(mem, val)     atomic_add(val,mem)
  @@ -157,8 +156,12 @@
   #define apr_atomic_inc(mem)          atomic_inc(mem)
   #define apr_atomic_set(mem, val)     atomic_set(mem, val)
   #define apr_atomic_read(mem)         atomic_read(mem)
  +#if defined(cmpxchg)
   #define apr_atomic_init(pool)        APR_SUCCESS
  +#define apr_atomic_cas(mem,with,cmp) cmpxchg(mem,cmp,with)
  +#else
   #define APR_ATOMIC_NEED_CAS_DEFAULT 1
  +#endif
   
   #elif defined(__FreeBSD__) && (__FreeBSD__ >= 4)
   #include <machine/atomic.h>
  @@ -195,10 +198,10 @@
   #define apr_atomic_t apr_uint32_t
   #define apr_atomic_read(p)  *p
   apr_status_t apr_atomic_init(apr_pool_t *p);
  -apr_uint32_t apr_atomic_set(volatile apr_atomic_t *mem, apr_uint32_t val);
  -apr_uint32_t apr_atomic_add(volatile apr_atomic_t *mem, apr_uint32_t val);
  -apr_uint32_t apr_atomic_inc(volatile apr_atomic_t *mem);
  -apr_uint32_t apr_atomic_dec(volatile apr_atomic_t *mem);
  +void apr_atomic_set(volatile apr_atomic_t *mem, apr_uint32_t val);
  +void apr_atomic_add(volatile apr_atomic_t *mem, apr_uint32_t val);
  +void apr_atomic_inc(volatile apr_atomic_t *mem);
  +void apr_atomic_dec(volatile apr_atomic_t *mem);
   
   #define APR_ATOMIC_NEED_DEFAULT 1
   #define APR_ATOMIC_NEED_CAS_DEFAULT 1
  @@ -208,7 +211,8 @@
   #endif /* !defined(WIN32) && !defined(__linux) */
   
   #if defined(APR_ATOMIC_NEED_CAS_DEFAULT)
  -long apr_atomic_cas(volatile apr_atomic_t *mem,long with,long cmp);
  +apr_status_t apr_atomic_init(apr_pool_t *p);
  +apr_uint32_t apr_atomic_cas(volatile apr_uint32_t *mem,long with,long cmp);
   #endif
   
   #endif /* DOXYGEN */
  
  
  
  1.6       +8 -11     apr/test/testatomic.c
  
  Index: testatomic.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testatomic.c,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- testatomic.c	19 Feb 2002 23:45:06 -0000	1.5
  +++ testatomic.c	20 Feb 2002 05:52:04 -0000	1.6
  @@ -75,40 +75,37 @@
   static apr_status_t check_basic_atomics(volatile apr_atomic_t*p)
   {
       apr_uint32_t oldval;
  +    apr_uint32_t casval=0;
       apr_atomic_set(&y,0);
       printf("%-60s", "testing CAS");
  -    oldval = apr_atomic_cas(&y,12,0);
  +    oldval = apr_atomic_cas(&casval,12,0);
       if (oldval != 0) {
           fprintf(stderr, "Failed\noldval =%d should be zero\n",oldval);
           return APR_EGENERAL;
       }
       printf("OK\n");
       printf("%-60s", "testing CAS - match non-null");
  -    oldval = apr_atomic_cas(&y,23,12);
  +    oldval = apr_atomic_cas(&casval,23,12);
       if (oldval != 12) {
           fprintf(stderr, "Failed\noldval =%d should be 12 y=%d\n",
                   oldval,
  -                apr_atomic_read(&y));
  +                casval);
           return APR_EGENERAL;
       }
       printf("OK\n");
       printf("%-60s", "testing CAS - no match");
  -    oldval = apr_atomic_cas(&y,23,12);
  +    oldval = apr_atomic_cas(&casval,23,12);
       if (oldval != 23 ) {
           fprintf(stderr, "Failed\noldval =%d should be 23 y=%d\n",
                   oldval, 
  -                apr_atomic_read(&y));
  +                casval);
           return APR_EGENERAL;
       }
       printf("OK\n");
   
       printf("%-60s", "testing add");
  -    oldval = apr_atomic_add(&y,4);
  -    if (oldval != 23) {
  -        fprintf(stderr, "Failed\nAtomic Add should return the old value expecting 23 got
%d\n",
  -                oldval);
  -        exit(-1);
  -    }
  +    apr_atomic_set(&y,23);
  +    apr_atomic_add(&y,4);
       if (apr_atomic_read(&y) != 27) {
           fprintf(stderr, "Failed\nAtomic Add doesn't add up ;( expected 27 got %d\n",
               oldval);
  
  
  

Mime
View raw message