X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fstructure%2FSGAtomic.cxx;h=e7dd76c29a3883c38aaf975e75487f8166bd49cc;hb=58c7edfed6a848f555bb0eaa65593162b5a206ce;hp=9eabf4ec816719557daa2c42ae9830e3f4845a95;hpb=b028adb6af41c63b1086d5f42760a2119447e163;p=simgear.git diff --git a/simgear/structure/SGAtomic.cxx b/simgear/structure/SGAtomic.cxx index 9eabf4ec..e7dd76c2 100644 --- a/simgear/structure/SGAtomic.cxx +++ b/simgear/structure/SGAtomic.cxx @@ -1,6 +1,6 @@ /* -*-c++-*- * - * Copyright (C) 2005-2006 Mathias Froehlich + * Copyright (C) 2005-2009 Mathias Froehlich * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -20,7 +20,7 @@ #include "SGAtomic.hxx" -#if defined(SGATOMIC_USE_GCC4_BUILTINS) && defined(__i386__) +#if defined(SGATOMIC_USE_GCC4_BUILTINS) && defined (__i386__) // Usually the apropriate functions are inlined by gcc. // But if gcc is called with something aequivalent to -march=i386, @@ -53,6 +53,18 @@ unsigned __sync_add_and_fetch_4(volatile void *ptr, unsigned value) return result + value; } +unsigned __sync_bool_compare_and_swap_4(volatile void *ptr, + unsigned oldValue, unsigned newValue) +{ + register volatile unsigned* mem = reinterpret_cast(ptr); + unsigned before; + __asm__ __volatile__("lock; cmpxchg{l} {%1,%2|%1,%2}" + : "=a"(before) + : "q"(newValue), "m"(*mem), "0"(oldValue) + : "memory"); + return before == oldValue; +} + void __sync_synchronize() { __asm__ __volatile__("": : : "memory");