* src/threads/posix/thread-posix.cpp: Eliminated some easy-to-fix or pointless compil...
[cacao.git] / src / vm / jit / i386 / md-atomic.hpp
index d6ea3d777f5b89451be85d0e76ac7980d84cd4c1..f1e875234a12b5b8fdaf505409d91e93ec623af7 100644 (file)
@@ -1,6 +1,6 @@
 /* src/vm/jit/i386/atomic.hpp - i386 atomic instructions
 
-   Copyright (C) 2008
+   Copyright (C) 2008, 2010
    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
@@ -32,6 +32,7 @@
 
 #include "threads/atomic.hpp"
 
+namespace Atomic_md {
 
 /**
  * An atomic compare and swap for 32-bit integer values.
  *
  * @return value of the memory location before the store
  */
-inline uint32_t Atomic::compare_and_swap(volatile uint32_t *p, uint32_t oldval, uint32_t newval)
+inline uint32_t compare_and_swap(volatile uint32_t *p, uint32_t oldval, uint32_t newval)
 {
        uint32_t result;
 
        __asm__ __volatile__ ("lock; cmpxchgl %2, %1"
                                                  : "=a" (result), "=m" (*p)
-                                                 : "r" (newval), "m" (*p), "0" (oldval));
+                                                 : "r" (newval), "m" (*p), "0" (oldval)
+                                                 : "cc");
 
        return result;
 }
@@ -63,32 +65,16 @@ inline uint32_t Atomic::compare_and_swap(volatile uint32_t *p, uint32_t oldval,
  *
  * @return value of the memory location before the store
  */
-inline uint64_t Atomic::compare_and_swap(volatile uint64_t *p, uint64_t oldval, uint64_t newval)
+inline uint64_t compare_and_swap(volatile uint64_t *p, uint64_t oldval, uint64_t newval)
 {
-#warning Should we use cmpxchg8b or a generic version?
-       return generic_compare_and_swap(p, oldval, newval);
-}
-
-
-/**
- * An atomic compare and swap for pointer values.
- *
- * @param p      Pointer to memory address.
- * @param oldval Old value to be expected.
- * @param newval New value to be stored.
- *
- * @return value of the memory location before the store
- */
-inline void* Atomic::compare_and_swap(volatile void** p, void* oldval, void* newval)
-{
-       return (void*) compare_and_swap((volatile uint32_t*) p, (uint32_t) oldval, (uint32_t) newval);
+       return Atomic::generic_compare_and_swap(p, oldval, newval);
 }
 
 
 /**
  * A memory barrier.
  */
-inline void Atomic::memory_barrier(void)
+inline void memory_barrier(void)
 {
        __asm__ __volatile__ ("lock; add $0, 0(%%esp)" : : : "memory" );
 }
@@ -97,7 +83,7 @@ inline void Atomic::memory_barrier(void)
 /**
  * A write memory barrier.
  */
-inline void Atomic::write_memory_barrier(void)
+inline void write_memory_barrier(void)
 {
        __asm__ __volatile__ ("" : : : "memory");
 }
@@ -106,9 +92,13 @@ inline void Atomic::write_memory_barrier(void)
 /**
  * An instruction barrier.
  */
-inline void Atomic::instruction_barrier(void)
+inline void instruction_barrier(void)
 {
-       // Nothing.
+       // We need the "memory" constraint here because compare_and_swap does not
+       // have it.
+       __asm__ __volatile__ ("" : : : "memory");
+}
+
 }
 
 #endif // _MD_ATOMIC_HPP