apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject cvs commit: apr/include apr_atomic.h
Date Thu, 04 Dec 2003 20:06:04 GMT
trawick     2003/12/04 12:06:04

  Modified:    atomic/netware apr_atomic.c
               atomic/os390 atomic.c
               atomic/unix apr_atomic.c
               atomic/win32 apr_atomic.c
               include  apr_atomic.h
  Log:
  apr_atomic_add32() and apr_atomic_inc32() now return values (the old value)
  
  Submitted by:	gregames (all the hard bits) and trawick
  
  Revision  Changes    Path
  1.7       +4 -4      apr/atomic/netware/apr_atomic.c
  
  Index: apr_atomic.c
  ===================================================================
  RCS file: /home/cvs/apr/atomic/netware/apr_atomic.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- apr_atomic.c	3 Dec 2003 00:04:42 -0000	1.6
  +++ apr_atomic.c	4 Dec 2003 20:06:03 -0000	1.7
  @@ -62,9 +62,9 @@
       return APR_SUCCESS;
   }
   
  -APR_DECLARE(void) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
  +APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
   {
  -    atomic_add((unsigned long *)mem,(unsigned long)val);
  +    return atomic_add((unsigned long *)mem,(unsigned long)val);
   }
   
   APR_DECLARE(void) apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
  @@ -72,9 +72,9 @@
       atomic_sub((unsigned long *)mem,(unsigned long)val);
   }
   
  -APR_DECLARE(void) apr_atomic_inc32(volatile apr_uint32_t *mem)
  +APR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem)
   {
  -    atomic_inc((unsigned long *)mem);
  +    return atomic_inc((unsigned long *)mem);
   }
   
   APR_DECLARE(void) apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val)
  
  
  
  1.7       +11 -5     apr/atomic/os390/atomic.c
  
  Index: atomic.c
  ===================================================================
  RCS file: /home/cvs/apr/atomic/os390/atomic.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- atomic.c	3 Dec 2003 00:04:42 -0000	1.6
  +++ atomic.c	4 Dec 2003 20:06:03 -0000	1.7
  @@ -63,24 +63,30 @@
       return APR_SUCCESS;
   }
   
  -void apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
  +apr_uint32_t apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
   {
       apr_uint32_t old, new_val; 
   
       old = *mem;   /* old is automatically updated on cs failure */
       do {
           new_val = old + val;
  -    } while (__cs(&old, (cs_t *)mem, new_val)); 
  +    } while (__cs(&old, (cs_t *)mem, new_val));
  +    return old;
   }
   
   void apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
   {
  -    apr_atomic_add32(mem, -val);
  +     apr_uint32_t old, new_val;
  +
  +     old = *mem;   /* old is automatically updated on cs failure */
  +     do {
  +         new_val = old - val;
  +     } while (__cs(&old, (cs_t *)mem, new_val));
   }
   
  -void apr_atomic_inc32(volatile apr_uint32_t *mem)
  +apr_uint32_t apr_atomic_inc32(volatile apr_uint32_t *mem)
   {
  -    apr_atomic_add32(mem, 1);
  +    return apr_atomic_add32(mem, 1);
   }
   
   int apr_atomic_dec32(volatile apr_uint32_t *mem)
  
  
  
  1.29      +30 -16    apr/atomic/unix/apr_atomic.c
  
  Index: apr_atomic.c
  ===================================================================
  RCS file: /home/cvs/apr/atomic/unix/apr_atomic.c,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- apr_atomic.c	3 Dec 2003 01:05:07 -0000	1.28
  +++ apr_atomic.c	4 Dec 2003 20:06:03 -0000	1.29
  @@ -60,9 +60,9 @@
   
   #include <machine/atomic.h>
   
  -APR_DECLARE(void) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
  +APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
   {
  -    atomic_add_int(mem, val);
  +    return atomic_add_int(mem, val);
   }
   #define APR_OVERRIDE_ATOMIC_ADD32
   
  @@ -72,9 +72,9 @@
   }
   #define APR_OVERRIDE_ATOMIC_DEC32
   
  -APR_DECLARE(void) apr_atomic_inc32(volatile apr_uint32_t *mem)
  +APR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem)
   {
  -    atomic_add_int(mem, 1);
  +    return atomic_add_int(mem, 1);
   }
   #define APR_OVERRIDE_ATOMIC_INC32
   
  @@ -103,12 +103,13 @@
   }
   #define APR_OVERRIDE_ATOMIC_CAS32
   
  -APR_DECLARE(void) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
  +APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
   {
  -    asm volatile ("lock; addl %1, %0"                              
  -                  :                                                           
  -                  : "m" (*(mem)), "r" (val)                                   
  -                  : "memory");
  +    asm volatile ("lock; xadd %1, (%2)"                              
  +                  : "=r"(val)          /* output, same as 1st input */
  +                  : "r"(val), "r"(mem) /* inputs */
  +                  : "%1","memory");    /* tell gcc they are clobbered */
  +    return val;
   }
   #define APR_OVERRIDE_ATOMIC_ADD32
   
  @@ -136,12 +137,15 @@
   }
   #define APR_OVERRIDE_ATOMIC_DEC32
   
  -APR_DECLARE(void) apr_atomic_inc32(volatile apr_uint32_t *mem)
  +APR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem)
   {
  -    asm volatile ("lock; incl %0"
  -                  :
  -                  : "m" (*(mem))
  -                  : "memory");
  +    apr_uint32_t val = 1;
  +
  +    asm volatile ("lock; xadd %1, (%2)"                              
  +                  : "=r"(val)          /* output, same as 1st input */
  +                  : "r"(val), "r"(mem) /* inputs */
  +                  : "%1","memory");    /* tell gcc they are clobbered */
  +    return val;
   }
   #define APR_OVERRIDE_ATOMIC_INC32
   
  @@ -196,18 +200,23 @@
   #endif /*!defined(apr_atomic_init) && !defined(APR_OVERRIDE_ATOMIC_INIT) */
   
   #if !defined(apr_atomic_add32) && !defined(APR_OVERRIDE_ATOMIC_ADD32)
  -void apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val) 
  +apr_uint32_t apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
   {
  +    apr_uint32_t old_value;
  +
   #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);
       }
   #else
  +    old_value = *mem;
       *mem += val;
   #endif /* APR_HAS_THREADS */
  +    return old_value;
   }
   #endif /*!defined(apr_atomic_sub32) && !defined(APR_OVERRIDE_ATOMIC_SUB32) */
   
  @@ -244,18 +253,23 @@
   #endif /*!defined(apr_atomic_set32) && !defined(APR_OVERRIDE_ATOMIC_SET32) */
   
   #if !defined(apr_atomic_inc32) && !defined(APR_OVERRIDE_ATOMIC_INC32)
  -void apr_atomic_inc32(volatile apr_uint32_t *mem) 
  +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)];
   
       if (apr_thread_mutex_lock(lock) == APR_SUCCESS) {
  +        old_value = *mem;
           (*mem)++;
           apr_thread_mutex_unlock(lock);
       }
   #else
  +    old_value = *mem;
       (*mem)++;
   #endif /* APR_HAS_THREADS */
  +    return old_value;
   }
   #endif /*!defined(apr_atomic_inc32) && !defined(APR_OVERRIDE_ATOMIC_INC32) */
   
  
  
  
  1.2       +5 -4      apr/atomic/win32/apr_atomic.c
  
  Index: apr_atomic.c
  ===================================================================
  RCS file: /home/cvs/apr/atomic/win32/apr_atomic.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- apr_atomic.c	3 Dec 2003 01:05:07 -0000	1.1
  +++ apr_atomic.c	4 Dec 2003 20:06:03 -0000	1.2
  @@ -79,9 +79,9 @@
       (apr_uint32_t volatile *, 
        apr_uint32_t, apr_uint32_t);
   
  -APR_DECLARE(void) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
  +APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
   {
  -    ((apr_atomic_win32_ptr_val_fn)InterlockedExchangeAdd)(mem, val);
  +    return ((apr_atomic_win32_ptr_val_fn)InterlockedExchangeAdd)(mem, val);
   }
   
   APR_DECLARE(void) apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
  @@ -89,9 +89,10 @@
       ((apr_atomic_win32_ptr_val_fn)InterlockedExchangeAdd)(mem, -val);
   }
   
  -APR_DECLARE(void) apr_atomic_inc32(volatile apr_uint32_t *mem)
  +APR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem)
   {
  -    ((apr_atomic_win32_ptr_fn)InterlockedIncrement)(mem);
  +    /* we return old value, win32 returns new value :( */
  +    return ((apr_atomic_win32_ptr_fn)InterlockedIncrement)(mem) - 1;
   }
   
   APR_DECLARE(int) apr_atomic_dec32(volatile apr_uint32_t *mem)
  
  
  
  1.66      +4 -2      apr/include/apr_atomic.h
  
  Index: apr_atomic.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_atomic.h,v
  retrieving revision 1.65
  retrieving revision 1.66
  diff -u -r1.65 -r1.66
  --- apr_atomic.h	3 Dec 2003 00:04:42 -0000	1.65
  +++ apr_atomic.h	4 Dec 2003 20:06:03 -0000	1.66
  @@ -107,8 +107,9 @@
    * atomically add 'val' to an apr_uint32_t
    * @param mem pointer to the object
    * @param val amount to add
  + * @return old value pointed to by mem
    */
  -APR_DECLARE(void) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val);
  +APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val);
   
   /**
    * atomically subtract 'val' from an apr_uint32_t
  @@ -120,8 +121,9 @@
   /**
    * atomically increment an apr_uint32_t by 1
    * @param mem pointer to the object
  + * @return old value pointed to by mem
    */
  -APR_DECLARE(void) apr_atomic_inc32(volatile apr_uint32_t *mem);
  +APR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem);
   
   /**
    * atomically decrement an apr_uint32_t by 1
  
  
  

Mime
View raw message