diff options
author | Jung-uk Kim <jkim@FreeBSD.org> | 2012-08-27 10:38:05 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2012-08-27 13:33:43 +0200 |
commit | 1d6e13e13b36163c07fc6013c9c3da6fc553e697 (patch) | |
tree | 6dac29d1c8fad518719b8e31f161854b98d74138 /sal | |
parent | fdo#53855: Detect GCC built-in atomic functions (diff) | |
download | core-1d6e13e13b36163c07fc6013c9c3da6fc553e697.tar.gz core-1d6e13e13b36163c07fc6013c9c3da6fc553e697.zip |
fdo#53855: Use the newly added HAVE_GCC_BUILTIN_ATOMIC for sal
Signed-off-by: Stephan Bergmann <sbergman@redhat.com>:
* nCount is needed in else branches after all
* tabs -> spaces
Change-Id: Iaa39ba9e1ed645819905f0e484fa4f1812271700
Diffstat (limited to 'sal')
-rw-r--r-- | sal/Library_sal.mk | 3 | ||||
-rw-r--r-- | sal/osl/unx/interlck.c | 24 |
2 files changed, 16 insertions, 11 deletions
diff --git a/sal/Library_sal.mk b/sal/Library_sal.mk index de22417f29f9..7e77034c6a45 100644 --- a/sal/Library_sal.mk +++ b/sal/Library_sal.mk @@ -40,6 +40,9 @@ $(eval $(call gb_Library_set_include,sal,\ )) $(eval $(call gb_Library_add_defs,sal,\ + $(if $(filter $(HAVE_GCC_BUILTIN_ATOMIC),TRUE), \ + -DHAVE_GCC_BUILTIN_ATOMIC \ + ) \ $(if $(VALGRIND_CFLAGS), \ $(VALGRIND_CFLAGS) \ -DHAVE_MEMCHECK_H=1 \ diff --git a/sal/osl/unx/interlck.c b/sal/osl/unx/interlck.c index bf9ff62b2ecc..91dd9c8d4d56 100644 --- a/sal/osl/unx/interlck.c +++ b/sal/osl/unx/interlck.c @@ -49,10 +49,9 @@ oslInterlockedCount SAL_CALL osl_incrementInterlockedCount(oslInterlockedCount* { // Fast case for old, slow, single CPU Intel machines for whom // interlocking is a performance nightmare. - register oslInterlockedCount nCount asm("%eax"); - nCount = 1; - if ( osl_isSingleCPU ) { + register oslInterlockedCount nCount asm("%eax"); + nCount = 1; __asm__ __volatile__ ( "xaddl %0, %1\n\t" : "+r" (nCount), "+m" (*pCount) @@ -60,28 +59,29 @@ oslInterlockedCount SAL_CALL osl_incrementInterlockedCount(oslInterlockedCount* : "memory"); return ++nCount; } -#if ( __GNUC__ > 4 ) || (( __GNUC__ == 4) && ( __GNUC_MINOR__ >= 4 )) +#if defined( HAVE_GCC_BUILTIN_ATOMIC ) else return __sync_add_and_fetch (pCount, 1); #else else { + register oslInterlockedCount nCount asm("%eax"); + nCount = 1; __asm__ __volatile__ ( "lock\n\t" "xaddl %0, %1\n\t" : "+r" (nCount), "+m" (*pCount) : /* nothing */ : "memory"); + return ++nCount; } - return ++nCount; #endif } oslInterlockedCount SAL_CALL osl_decrementInterlockedCount(oslInterlockedCount* pCount) { - register oslInterlockedCount nCount asm("%eax"); - nCount = -1; - if ( osl_isSingleCPU ) { + register oslInterlockedCount nCount asm("%eax"); + nCount = -1; __asm__ __volatile__ ( "xaddl %0, %1\n\t" : "+r" (nCount), "+m" (*pCount) @@ -89,22 +89,24 @@ oslInterlockedCount SAL_CALL osl_decrementInterlockedCount(oslInterlockedCount* : "memory"); return --nCount; } -#if ( __GNUC__ > 4 ) || (( __GNUC__ == 4) && ( __GNUC_MINOR__ >= 4 )) +#if defined( HAVE_GCC_BUILTIN_ATOMIC ) else return __sync_sub_and_fetch (pCount, 1); #else else { + register oslInterlockedCount nCount asm("%eax"); + nCount = -1; __asm__ __volatile__ ( "lock\n\t" "xaddl %0, %1\n\t" : "+r" (nCount), "+m" (*pCount) : /* nothing */ : "memory"); + return --nCount; } - return --nCount; #endif } -#elif ( __GNUC__ > 4 ) || (( __GNUC__ == 4) && ( __GNUC_MINOR__ >= 4 )) +#elif defined( HAVE_GCC_BUILTIN_ATOMIC ) oslInterlockedCount SAL_CALL osl_incrementInterlockedCount(oslInterlockedCount* pCount) { return __sync_add_and_fetch(pCount, 1); |