You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by bn...@apache.org on 2003/12/04 22:44:33 UTC

cvs commit: apr/atomic/netware apr_atomic.c

bnicholes    2003/12/04 13:44:33

  Modified:    atomic/netware apr_atomic.c
  Log:
  Fix up the return values for apr_atomic_add32() and apr_atomic_inc32() since the native Netware functions return void by default
  
  Revision  Changes    Path
  1.8       +6 -2      apr/atomic/netware/apr_atomic.c
  
  Index: apr_atomic.c
  ===================================================================
  RCS file: /home/cvs/apr/atomic/netware/apr_atomic.c,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- apr_atomic.c	4 Dec 2003 20:06:03 -0000	1.7
  +++ apr_atomic.c	4 Dec 2003 21:44:33 -0000	1.8
  @@ -64,7 +64,9 @@
   
   APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
   {
  -    return atomic_add((unsigned long *)mem,(unsigned long)val);
  +    apr_uint32_t old = *mem;
  +    atomic_add((unsigned long *)mem,(unsigned long)val);
  +    return old;
   }
   
   APR_DECLARE(void) apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
  @@ -74,7 +76,9 @@
   
   APR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem)
   {
  -    return atomic_inc((unsigned long *)mem);
  +    apr_uint32_t old = *mem;
  +    atomic_inc((unsigned long *)mem);
  +    return old;
   }
   
   APR_DECLARE(void) apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val)
  
  
  

Re: cvs commit: apr/atomic/netware apr_atomic.c

Posted by Jeff Trawick <tr...@attglobal.net>.
William A. Rowe, Jr. wrote:

>>  APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
>>  {
>> -    return atomic_add((unsigned long *)mem,(unsigned long)val);
>> +    apr_uint32_t old = *mem;
>> +    atomic_add((unsigned long *)mem,(unsigned long)val);
>> +    return old;
>>  }

> Because the old value isn't atomically fetched with the add/sub operation, 
> is this solution worse than no solution at all?

looked that way to me...   c-a-s time

> Perhaps we need two flavors, one fast (add/sub) that do *not* rely on any
> result value (returning void) and another that explicitly returns the old value
> on add, and the new value on subtract?

I'll be glad just to have a set that is functionally sufficient to support 
common ideoms :)  Start asking for adding more to the mess we have now (which 
doesn't support enough platforms) and I'm back to wishing we had just a simple 
core routine (cas32, but also casptr) implemented for n platforms and the rest 
of it portable functions using the cas32 primitive.



Re: cvs commit: apr/atomic/netware apr_atomic.c

Posted by "William A. Rowe, Jr." <wr...@apache.org>.
Because the old value isn't atomically fetched with the add/sub operation, 
is this solution worse than no solution at all?

Perhaps we need two flavors, one fast (add/sub) that do *not* rely on any
result value (returning void) and another that explicitly returns the old value
on add, and the new value on subtract?

Bill

At 03:44 PM 12/4/2003, bnicholes@apache.org wrote:
>bnicholes    2003/12/04 13:44:33
>
>  Modified:    atomic/netware apr_atomic.c
>  Log:
>  Fix up the return values for apr_atomic_add32() and apr_atomic_inc32() since the native Netware functions return void by default
>  
>  Revision  Changes    Path
>  1.8       +6 -2      apr/atomic/netware/apr_atomic.c
>  
>  Index: apr_atomic.c
>  ===================================================================
>  RCS file: /home/cvs/apr/atomic/netware/apr_atomic.c,v
>  retrieving revision 1.7
>  retrieving revision 1.8
>  diff -u -r1.7 -r1.8
>  --- apr_atomic.c      4 Dec 2003 20:06:03 -0000       1.7
>  +++ apr_atomic.c      4 Dec 2003 21:44:33 -0000       1.8
>  @@ -64,7 +64,9 @@
>   
>   APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
>   {
>  -    return atomic_add((unsigned long *)mem,(unsigned long)val);
>  +    apr_uint32_t old = *mem;
>  +    atomic_add((unsigned long *)mem,(unsigned long)val);
>  +    return old;
>   }
>   
>   APR_DECLARE(void) apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
>  @@ -74,7 +76,9 @@
>   
>   APR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem)
>   {
>  -    return atomic_inc((unsigned long *)mem);
>  +    apr_uint32_t old = *mem;
>  +    atomic_inc((unsigned long *)mem);
>  +    return old;
>   }
>   
>   APR_DECLARE(void) apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val)
>  
>  
>