You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by sa...@apache.org on 2003/01/09 03:48:46 UTC

cvs commit: apr/include apr_atomic.h

sascha      2003/01/08 18:48:46

  Modified:    include  apr_atomic.h
  Log:
  When one does not use the value of the apr_atomic_cas macro,
  GCC 2.95.3/3.2.1 will happily optimize the assembler statement away (x86).
  
  E.g.
  
      apr_atomic_t lck = 0;
      apr_atomic_cas(&lck, 1, 0);
      printf("%d\n", lck);
  
  will be turned into
  
      movl    $0, 4(%esp)
      movl    $.LC0, (%esp)
      call    printf
  
  Adding `volatile� to the asm statement fixes that.
  
      asm volatile ("lock; cmpxchgl %1, %2" ...
  
  gcc -O -S produces:
  
      movl    $0, %edx
      movl    $0, -4(%ebp)
      movl    $1, %ecx
      movl    %edx, %eax
  #APP
      lock; cmpxchgl %ecx, -4(%ebp)
  #NO_APP
      movl    -4(%ebp), %eax
      movl    %eax, 4(%esp)
      movl    $.LC0, (%esp)
      call    printf
  
  Revision  Changes    Path
  1.44      +1 -1      apr/include/apr_atomic.h
  
  Index: apr_atomic.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_atomic.h,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- apr_atomic.h	1 Jan 2003 00:01:45 -0000	1.43
  +++ apr_atomic.h	9 Jan 2003 02:48:46 -0000	1.44
  @@ -199,7 +199,7 @@
   #define apr_atomic_t apr_uint32_t
   #define apr_atomic_cas(mem,with,cmp) \
   ({ apr_atomic_t prev; \
  -    asm ("lock; cmpxchgl %1, %2"              \
  +    asm volatile ("lock; cmpxchgl %1, %2"              \
            : "=a" (prev)               \
            : "r" (with), "m" (*(mem)), "0"(cmp) \
            : "memory"); \