From b3bfac3f16c320d9c5f56f54b048606872d0a8fd Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Fri, 27 Feb 2015 17:29:10 -0500 Subject: [PATCH 1/7] add EPICS_ALWAYS_INLINE --- .../osi/compiler/clang/compilerSpecific.h | 6 +++ .../osi/compiler/default/compilerSpecific.h | 8 ++++ .../osi/compiler/gcc/compilerSpecific.h | 6 +++ .../osi/compiler/msvc/compilerSpecific.h | 6 +++ .../osi/compiler/solStudio/compilerSpecific.h | 43 +++++++++++++++++++ 5 files changed, 69 insertions(+) create mode 100644 src/libCom/osi/compiler/solStudio/compilerSpecific.h diff --git a/src/libCom/osi/compiler/clang/compilerSpecific.h b/src/libCom/osi/compiler/clang/compilerSpecific.h index 482ee513e..9871fcf7d 100644 --- a/src/libCom/osi/compiler/clang/compilerSpecific.h +++ b/src/libCom/osi/compiler/clang/compilerSpecific.h @@ -20,6 +20,12 @@ # error compiler/clang/compilerSpecific.h is only for use with the clang compiler #endif +#if __has_attribute(always_inline) +#define EPICS_ALWAYS_INLINE __inline__ __attribute__((always_inline)) +#else +#define EPICS_ALWAYS_INLINE __inline__ +#endif + #ifdef __cplusplus /* diff --git a/src/libCom/osi/compiler/default/compilerSpecific.h b/src/libCom/osi/compiler/default/compilerSpecific.h index f2a3f8c36..8af1727c5 100644 --- a/src/libCom/osi/compiler/default/compilerSpecific.h +++ b/src/libCom/osi/compiler/default/compilerSpecific.h @@ -15,6 +15,14 @@ #ifndef compilerSpecific_h #define compilerSpecific_h + +/* The 'inline' key work, possibily with compiler + * dependent flags to force inlineing where it would + * otherwise not be done. + * + * Warning: Second guessing the compiler may result in larger code size + */ +#define EPICS_ALWAYS_INLINE inline #ifdef __cplusplus diff --git a/src/libCom/osi/compiler/gcc/compilerSpecific.h b/src/libCom/osi/compiler/gcc/compilerSpecific.h index 6696c7a89..ca46a9348 100644 --- a/src/libCom/osi/compiler/gcc/compilerSpecific.h +++ b/src/libCom/osi/compiler/gcc/compilerSpecific.h @@ -23,6 +23,12 @@ #ifdef __clang__ # error compiler/gcc/compilerSpecific.h is not for use with the clang compiler #endif + +#if __GNUC__ > 2 +# define EPICS_ALWAYS_INLINE __inline__ __attribute__((always_inline)) +#else +# define EPICS_ALWAYS_INLINE __inline__ +#endif #ifdef __cplusplus diff --git a/src/libCom/osi/compiler/msvc/compilerSpecific.h b/src/libCom/osi/compiler/msvc/compilerSpecific.h index 587d534c7..49cf266ae 100644 --- a/src/libCom/osi/compiler/msvc/compilerSpecific.h +++ b/src/libCom/osi/compiler/msvc/compilerSpecific.h @@ -20,6 +20,12 @@ # error compiler/msvc/compilerSpecific.h is only for use with the Microsoft compiler #endif +#if _MSC_VER >= 1200 +#define EPICS_ALWAYS_INLINE __forceinline +#else +#define EPICS_ALWAYS_INLINE __inline +#endif + #ifdef __cplusplus /* diff --git a/src/libCom/osi/compiler/solStudio/compilerSpecific.h b/src/libCom/osi/compiler/solStudio/compilerSpecific.h new file mode 100644 index 000000000..2bdcec64d --- /dev/null +++ b/src/libCom/osi/compiler/solStudio/compilerSpecific.h @@ -0,0 +1,43 @@ +/*************************************************************************\ +* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne +* National Laboratory. +* Copyright (c) 2002 The Regents of the University of California, as +* Operator of Los Alamos National Laboratory. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ + +/* + * Author: + * Jeffrey O. Hill + * johill@lanl.gov + */ + +#ifndef compilerSpecific_h +#define compilerSpecific_h + +#ifndef __SUNPRO_C +# error Not Solaris Studio +#endif + +#if __SUNPRO_C<0x590 +# define EPICS_ALWAYS_INLINE inline +#else +# define EPICS_ALWAYS_INLINE inline __attribute__((always_inline)) +#endif + +#ifdef __cplusplus + +/* + * CXX_PLACEMENT_DELETE - defined if compiler supports placement delete + * CXX_THROW_SPECIFICATION - defined if compiler supports throw specification + * + * (our default guess is that the compiler implements the C++ 97 standard) + */ +#define CXX_THROW_SPECIFICATION +#define CXX_PLACEMENT_DELETE + +#endif /* __cplusplus */ + + +#endif /* ifndef compilerSpecific_h */ From 84e9ff3bc5236c36ed0fa741a67df4d1e595502f Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Fri, 27 Feb 2015 17:29:10 -0500 Subject: [PATCH 2/7] libCom/test: Add epicsInlineTest --- src/libCom/test/Makefile | 8 ++++ src/libCom/test/epicsInlineTest1.c | 64 +++++++++++++++++++++++++++ src/libCom/test/epicsInlineTest2.c | 28 ++++++++++++ src/libCom/test/epicsInlineTest3.cpp | 27 +++++++++++ src/libCom/test/epicsInlineTest4.cpp | 27 +++++++++++ src/libCom/test/epicsRunLibComTests.c | 2 + 6 files changed, 156 insertions(+) create mode 100644 src/libCom/test/epicsInlineTest1.c create mode 100644 src/libCom/test/epicsInlineTest2.c create mode 100644 src/libCom/test/epicsInlineTest3.cpp create mode 100644 src/libCom/test/epicsInlineTest4.cpp diff --git a/src/libCom/test/Makefile b/src/libCom/test/Makefile index 3a3d32a8f..e0c1b064c 100755 --- a/src/libCom/test/Makefile +++ b/src/libCom/test/Makefile @@ -22,6 +22,14 @@ epicsTypesTest_SRCS += epicsTypesTest.cpp testHarness_SRCS += epicsTypesTest.cpp TESTS += epicsTypesTest +TESTPROD_HOST += epicsInlineTest +epicsInlineTest_SRCS += epicsInlineTest1.c +epicsInlineTest_SRCS += epicsInlineTest2.c +epicsInlineTest_SRCS += epicsInlineTest3.cpp +epicsInlineTest_SRCS += epicsInlineTest4.cpp +testHarness_SRCS += $(epicsInlineTest_SRCS) +TESTS += epicsInlineTest + TESTPROD_HOST += epicsCalcTest epicsCalcTest_SRCS += epicsCalcTest.cpp testHarness_SRCS += epicsCalcTest.cpp diff --git a/src/libCom/test/epicsInlineTest1.c b/src/libCom/test/epicsInlineTest1.c new file mode 100644 index 000000000..e377e5f1d --- /dev/null +++ b/src/libCom/test/epicsInlineTest1.c @@ -0,0 +1,64 @@ +/*************************************************************************\ +* Copyright (c) 2015 Brookhaven Science Associates, as Operator of +* Brookhaven National Laboratory. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ + +/* This test checks the variations on inline function defintions. + * + * "static inline int func(void) {...}" + * + * Consistent meaning in C89, C99, and C++ (98 and 11). + * If not inline'd results in a private symbol in each compilation unit. + * Thus the non-inline'd version is duplicated in each compilation unit. + * However, definitions in different compilation units may be different. + * + * "inline int func(void) {...}" + * Warning: Not consistent, avoid use in headers meant for C or C++ + * + * In C++ this may be safely defined in more than one compilation unit. + * Where not inlined it will result in a weak public symbol. + * Thus non-inline'd version isn't duplicated, but must be the same + * in all compilation units. + * + */ + +#include "compilerSpecific.h" +#include "epicsUnitTest.h" + +#include "testMain.h" + +static EPICS_ALWAYS_INLINE int epicsInlineTestFn1(void) +{ + return 1; +} + +/* Fails to link in C99 +inline int epicsInlineTestFn2(void) +{ + return 42; +} +*/ + +void epicsInlineTest1(void) +{ + testDiag("epicsInlineTest1()"); + testOk1(epicsInlineTestFn1()==1); + /*testOk1(epicsInlineTestFn2()==42);*/ +} + +void epicsInlineTest2(void); +void epicsInlineTest3(void); +void epicsInlineTest4(void); + +MAIN(epicsInlineTest) +{ + testPlan(6); + testDiag("Test variation on inline int func()"); + epicsInlineTest1(); + epicsInlineTest2(); + epicsInlineTest3(); + epicsInlineTest4(); + return testDone(); +} diff --git a/src/libCom/test/epicsInlineTest2.c b/src/libCom/test/epicsInlineTest2.c new file mode 100644 index 000000000..b787276fb --- /dev/null +++ b/src/libCom/test/epicsInlineTest2.c @@ -0,0 +1,28 @@ +/*************************************************************************\ +* Copyright (c) 2015 Brookhaven Science Associates, as Operator of +* Brookhaven National Laboratory. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ + +#include "compilerSpecific.h" +#include "epicsUnitTest.h" + +static EPICS_ALWAYS_INLINE int epicsInlineTestFn1(void) +{ + return 2; +} + +/* Fails to link in C99 +inline int epicsInlineTestFn2(void) +{ + return 42; +} +*/ + +void epicsInlineTest2(void) +{ + testDiag("epicsInlineTest2()"); + testOk1(epicsInlineTestFn1()==2); + /*testOk1(epicsInlineTestFn2()==42);*/ +} diff --git a/src/libCom/test/epicsInlineTest3.cpp b/src/libCom/test/epicsInlineTest3.cpp new file mode 100644 index 000000000..9647be6dc --- /dev/null +++ b/src/libCom/test/epicsInlineTest3.cpp @@ -0,0 +1,27 @@ +/*************************************************************************\ +* Copyright (c) 2015 Brookhaven Science Associates, as Operator of +* Brookhaven National Laboratory. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ + +#include "compilerSpecific.h" +#include "epicsUnitTest.h" + +static EPICS_ALWAYS_INLINE int epicsInlineTestFn1(void) +{ + return 3; +} + +inline int epicsInlineTestFn2(void) +{ + return 42; +} + +extern "C" +void epicsInlineTest3(void) +{ + testDiag("epicsInlineTest3()"); + testOk1(epicsInlineTestFn1()==3); + testOk1(epicsInlineTestFn2()==42); +} diff --git a/src/libCom/test/epicsInlineTest4.cpp b/src/libCom/test/epicsInlineTest4.cpp new file mode 100644 index 000000000..545b45ffd --- /dev/null +++ b/src/libCom/test/epicsInlineTest4.cpp @@ -0,0 +1,27 @@ +/*************************************************************************\ +* Copyright (c) 2015 Brookhaven Science Associates, as Operator of +* Brookhaven National Laboratory. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ + +#include "compilerSpecific.h" +#include "epicsUnitTest.h" + +static EPICS_ALWAYS_INLINE int epicsInlineTestFn1(void) +{ + return 4; +} + +inline int epicsInlineTestFn2(void) +{ + return 42; +} + +extern "C" +void epicsInlineTest4(void) +{ + testDiag("epicsInlineTest4()"); + testOk1(epicsInlineTestFn1()==4); + testOk1(epicsInlineTestFn2()==42); +} diff --git a/src/libCom/test/epicsRunLibComTests.c b/src/libCom/test/epicsRunLibComTests.c index 5bf6cafd1..fe308b061 100644 --- a/src/libCom/test/epicsRunLibComTests.c +++ b/src/libCom/test/epicsRunLibComTests.c @@ -44,6 +44,7 @@ int epicsThreadTest(void); int epicsTimerTest(void); int epicsTimeTest(void); int epicsTypesTest(void); +int epicsInlineTest(void); int macDefExpandTest(void); int macLibTest(void); int ringBytesTest(void); @@ -92,6 +93,7 @@ void epicsRunLibComTests(void) runTest(epicsThreadPrivateTest); runTest(epicsTimeTest); runTest(epicsTypesTest); + runTest(epicsInlineTest); runTest(macDefExpandTest); runTest(macLibTest); runTest(ringBytesTest); From 0d4519eb541f5717d2774801196856e12aa04342 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Fri, 27 Feb 2015 17:29:11 -0500 Subject: [PATCH 3/7] epicsAtomic: fix C linkage With gcc -std=gnu99 (present default) functions qualified with plain 'inline' emit strong public symbols (nm says 'T') in every compilation unit the definition appears. This causes linking to fail in all cases where executable are statically linked, and many where dynamic linking is used. --- src/libCom/osi/compiler/clang/epicsAtomicCD.h | 10 -- .../osi/compiler/default/epicsAtomicCD.h | 11 +- src/libCom/osi/compiler/gcc/epicsAtomicCD.h | 10 +- src/libCom/osi/compiler/msvc/epicsAtomicCD.h | 20 +--- .../osi/compiler/solStudio/epicsAtomicCD.h | 10 -- src/libCom/osi/epicsAtomic.h | 101 +++++++----------- src/libCom/osi/os/WIN32/epicsAtomicOSD.cpp | 22 ---- src/libCom/osi/os/default/epicsAtomicOSD.c | 0 src/libCom/osi/os/posix/epicsAtomicOSD.cpp | 27 +---- src/libCom/osi/os/posix/epicsAtomicOSD.h | 17 +++ src/libCom/osi/os/solaris/epicsAtomicOSD.h | 16 +-- src/libCom/osi/os/vxWorks/epicsAtomicOSD.cpp | 21 ---- src/libCom/osi/os/vxWorks/epicsAtomicOSD.h | 8 +- 13 files changed, 82 insertions(+), 191 deletions(-) delete mode 100644 src/libCom/osi/os/WIN32/epicsAtomicOSD.cpp create mode 100644 src/libCom/osi/os/default/epicsAtomicOSD.c delete mode 100644 src/libCom/osi/os/vxWorks/epicsAtomicOSD.cpp diff --git a/src/libCom/osi/compiler/clang/epicsAtomicCD.h b/src/libCom/osi/compiler/clang/epicsAtomicCD.h index 00fa24e4b..34037869b 100644 --- a/src/libCom/osi/compiler/clang/epicsAtomicCD.h +++ b/src/libCom/osi/compiler/clang/epicsAtomicCD.h @@ -16,16 +16,6 @@ #ifndef epicsAtomicCD_h #define epicsAtomicCD_h -#if defined ( __cplusplus ) -# define EPICS_ATOMIC_INLINE inline -#else -# define EPICS_ATOMIC_INLINE __inline__ -#endif - -/* - * we have an inline keyword so we can proceed - * with an os specific inline instantiation - */ #include "epicsAtomicOSD.h" #endif /* epicsAtomicCD_h */ diff --git a/src/libCom/osi/compiler/default/epicsAtomicCD.h b/src/libCom/osi/compiler/default/epicsAtomicCD.h index 3ca260759..34037869b 100644 --- a/src/libCom/osi/compiler/default/epicsAtomicCD.h +++ b/src/libCom/osi/compiler/default/epicsAtomicCD.h @@ -16,15 +16,6 @@ #ifndef epicsAtomicCD_h #define epicsAtomicCD_h -#if __STDC_VERSION__ >= 199901L || defined ( __cplusplus ) -# define EPICS_ATOMIC_INLINE inline - /* - * We have already defined the public interface in epicsAtomic.h - * so there is nothing more to implement if there isnt an inline - * keyword available. Otherwise, if we have an inline keyword - * we will proceed with an os specific inline implementation. - */ -# include "epicsAtomicOSD.h" -#endif +#include "epicsAtomicOSD.h" #endif /* epicsAtomicCD_h */ diff --git a/src/libCom/osi/compiler/gcc/epicsAtomicCD.h b/src/libCom/osi/compiler/gcc/epicsAtomicCD.h index e3989769f..8f7f97d16 100644 --- a/src/libCom/osi/compiler/gcc/epicsAtomicCD.h +++ b/src/libCom/osi/compiler/gcc/epicsAtomicCD.h @@ -20,8 +20,6 @@ # error this header is only for use with the gnu compiler #endif -#define EPICS_ATOMIC_INLINE __inline__ - #define GCC_ATOMIC_CONCAT( A, B ) GCC_ATOMIC_CONCATR(A,B) #define GCC_ATOMIC_CONCATR( A, B ) ( A ## B ) @@ -69,7 +67,7 @@ extern "C" { #ifndef EPICS_ATOMIC_READ_MEMORY_BARRIER #define EPICS_ATOMIC_READ_MEMORY_BARRIER -EPICS_ATOMIC_INLINE void epicsAtomicReadMemoryBarrier () +EPICS_ATOMIC_INLINE void epicsAtomicReadMemoryBarrier (void) { __sync_synchronize (); } @@ -77,7 +75,7 @@ EPICS_ATOMIC_INLINE void epicsAtomicReadMemoryBarrier () #ifndef EPICS_ATOMIC_WRITE_MEMORY_BARRIER #define EPICS_ATOMIC_WRITE_MEMORY_BARRIER -EPICS_ATOMIC_INLINE void epicsAtomicWriteMemoryBarrier () +EPICS_ATOMIC_INLINE void epicsAtomicWriteMemoryBarrier (void) { __sync_synchronize (); } @@ -88,7 +86,7 @@ EPICS_ATOMIC_INLINE void epicsAtomicWriteMemoryBarrier () #ifndef EPICS_ATOMIC_READ_MEMORY_BARRIER #if GCC_ATOMIC_INTRINSICS_MIN_X86 #define EPICS_ATOMIC_READ_MEMORY_BARRIER -EPICS_ATOMIC_INLINE void epicsAtomicReadMemoryBarrier () +EPICS_ATOMIC_INLINE void epicsAtomicReadMemoryBarrier (void) { asm("mfence;"); } @@ -98,7 +96,7 @@ EPICS_ATOMIC_INLINE void epicsAtomicReadMemoryBarrier () #ifndef EPICS_ATOMIC_WRITE_MEMORY_BARRIER #if GCC_ATOMIC_INTRINSICS_MIN_X86 #define EPICS_ATOMIC_WRITE_MEMORY_BARRIER -EPICS_ATOMIC_INLINE void epicsAtomicWriteMemoryBarrier () +EPICS_ATOMIC_INLINE void epicsAtomicWriteMemoryBarrier (void) { asm("mfence;"); } diff --git a/src/libCom/osi/compiler/msvc/epicsAtomicCD.h b/src/libCom/osi/compiler/msvc/epicsAtomicCD.h index f834f0405..282aa971a 100644 --- a/src/libCom/osi/compiler/msvc/epicsAtomicCD.h +++ b/src/libCom/osi/compiler/msvc/epicsAtomicCD.h @@ -26,16 +26,10 @@ #include -#if _MSC_VER >= 1200 -# define EPICS_ATOMIC_INLINE __forceinline -#else -# define EPICS_ATOMIC_INLINE __inline -#endif - #if defined ( _M_IX86 ) # pragma warning( push ) # pragma warning( disable : 4793 ) - EPICS_ATOMIC_INLINE void epicsAtomicMemoryBarrier () + EPICS_ATOMIC_INLINE void epicsAtomicMemoryBarrier (void) { long fence; __asm { xchg fence, eax } @@ -44,14 +38,14 @@ #elif defined ( _M_X64 ) # define MS_ATOMIC_64 # pragma intrinsic ( __faststorefence ) - EPICS_ATOMIC_INLINE void epicsAtomicMemoryBarrier () + EPICS_ATOMIC_INLINE void epicsAtomicMemoryBarrier (void) { __faststorefence (); } #elif defined ( _M_IA64 ) # define MS_ATOMIC_64 # pragma intrinsic ( __mf ) - EPICS_ATOMIC_INLINE void epicsAtomicMemoryBarrier () + EPICS_ATOMIC_INLINE void epicsAtomicMemoryBarrier (void) { __mf (); } @@ -88,13 +82,13 @@ extern "C" { #endif /* __cplusplus */ #define EPICS_ATOMIC_READ_MEMORY_BARRIER -EPICS_ATOMIC_INLINE void epicsAtomicReadMemoryBarrier () +EPICS_ATOMIC_INLINE void epicsAtomicReadMemoryBarrier (void) { epicsAtomicMemoryBarrier (); } #define EPICS_ATOMIC_WRITE_MEMORY_BARRIER -EPICS_ATOMIC_INLINE void epicsAtomicWriteMemoryBarrier () +EPICS_ATOMIC_INLINE void epicsAtomicWriteMemoryBarrier (void) { epicsAtomicMemoryBarrier (); } @@ -108,10 +102,6 @@ EPICS_ATOMIC_INLINE void epicsAtomicWriteMemoryBarrier () #else /* ifdef _MSC_EXTENSIONS */ -#if defined ( __cplusplus ) -# define EPICS_ATOMIC_INLINE inline -#endif - /* * if unavailable as an intrinsic we will try * for os specific inline solution diff --git a/src/libCom/osi/compiler/solStudio/epicsAtomicCD.h b/src/libCom/osi/compiler/solStudio/epicsAtomicCD.h index 60083cf71..34037869b 100644 --- a/src/libCom/osi/compiler/solStudio/epicsAtomicCD.h +++ b/src/libCom/osi/compiler/solStudio/epicsAtomicCD.h @@ -16,16 +16,6 @@ #ifndef epicsAtomicCD_h #define epicsAtomicCD_h -#if defined ( __cplusplus ) -# define EPICS_ATOMIC_INLINE inline -#else -# define EPICS_ATOMIC_INLINE __inline -#endif - -/* - * we have an inline keyword so we can proceed - * with an os specific inline instantiation - */ #include "epicsAtomicOSD.h" #endif /* epicsAtomicCD_h */ diff --git a/src/libCom/osi/epicsAtomic.h b/src/libCom/osi/epicsAtomic.h index f3d509f56..f568c9de0 100644 --- a/src/libCom/osi/epicsAtomic.h +++ b/src/libCom/osi/epicsAtomic.h @@ -17,7 +17,9 @@ #include /* define size_t */ -#include "shareLib.h" +#include "compilerSpecific.h" + +#define EPICS_ATOMIC_INLINE EPICS_FUNC_INLINE #ifdef __cplusplus extern "C" { @@ -26,10 +28,10 @@ extern "C" { typedef void * EpicsAtomicPtrT; /* load target into cache */ -epicsShareFunc void epicsAtomicReadMemoryBarrier (); +EPICS_ATOMIC_INLINE void epicsAtomicReadMemoryBarrier (void); /* push cache version of target into target */ -epicsShareFunc void epicsAtomicWriteMemoryBarrier (); +EPICS_ATOMIC_INLINE void epicsAtomicWriteMemoryBarrier (void); /* * lock out other smp processors from accessing the target, @@ -37,8 +39,8 @@ epicsShareFunc void epicsAtomicWriteMemoryBarrier (); * to target, allow other smp processors to access the target, * return new value of target as modified by this operation */ -epicsShareFunc size_t epicsAtomicIncrSizeT ( size_t * pTarget ); -epicsShareFunc int epicsAtomicIncrIntT ( int * pTarget ); +EPICS_ATOMIC_INLINE size_t epicsAtomicIncrSizeT ( size_t * pTarget ); +EPICS_ATOMIC_INLINE int epicsAtomicIncrIntT ( int * pTarget ); /* * lock out other smp processors from accessing the target, @@ -46,8 +48,8 @@ epicsShareFunc int epicsAtomicIncrIntT ( int * pTarget ); * to target, allow out other smp processors to access the target, * return new value of target as modified by this operation */ -epicsShareFunc size_t epicsAtomicDecrSizeT ( size_t * pTarget ); -epicsShareFunc int epicsAtomicDecrIntT ( int * pTarget ); +EPICS_ATOMIC_INLINE size_t epicsAtomicDecrSizeT ( size_t * pTarget ); +EPICS_ATOMIC_INLINE int epicsAtomicDecrIntT ( int * pTarget ); /* * lock out other smp processors from accessing the target, @@ -55,23 +57,23 @@ epicsShareFunc int epicsAtomicDecrIntT ( int * pTarget ); * to target, allow other smp processors to access the target, * return new value of target as modified by this operation */ -epicsShareFunc size_t epicsAtomicAddSizeT ( size_t * pTarget, size_t delta ); -epicsShareFunc size_t epicsAtomicSubSizeT ( size_t * pTarget, size_t delta ); -epicsShareFunc int epicsAtomicAddIntT ( int * pTarget, int delta ); +EPICS_ATOMIC_INLINE size_t epicsAtomicAddSizeT ( size_t * pTarget, size_t delta ); +EPICS_ATOMIC_INLINE size_t epicsAtomicSubSizeT ( size_t * pTarget, size_t delta ); +EPICS_ATOMIC_INLINE int epicsAtomicAddIntT ( int * pTarget, int delta ); /* * set cache version of target, flush cache to target */ -epicsShareFunc void epicsAtomicSetSizeT ( size_t * pTarget, size_t newValue ); -epicsShareFunc void epicsAtomicSetIntT ( int * pTarget, int newValue ); -epicsShareFunc void epicsAtomicSetPtrT ( EpicsAtomicPtrT * pTarget, EpicsAtomicPtrT newValue ); +EPICS_ATOMIC_INLINE void epicsAtomicSetSizeT ( size_t * pTarget, size_t newValue ); +EPICS_ATOMIC_INLINE void epicsAtomicSetIntT ( int * pTarget, int newValue ); +EPICS_ATOMIC_INLINE void epicsAtomicSetPtrT ( EpicsAtomicPtrT * pTarget, EpicsAtomicPtrT newValue ); /* * fetch target into cache, return new value of target */ -epicsShareFunc size_t epicsAtomicGetSizeT ( const size_t * pTarget ); -epicsShareFunc int epicsAtomicGetIntT ( const int * pTarget ); -epicsShareFunc EpicsAtomicPtrT epicsAtomicGetPtrT ( const EpicsAtomicPtrT * pTarget ); +EPICS_ATOMIC_INLINE size_t epicsAtomicGetSizeT ( const size_t * pTarget ); +EPICS_ATOMIC_INLINE int epicsAtomicGetIntT ( const int * pTarget ); +EPICS_ATOMIC_INLINE EpicsAtomicPtrT epicsAtomicGetPtrT ( const EpicsAtomicPtrT * pTarget ); /* * lock out other smp processors from accessing the target, @@ -80,11 +82,11 @@ epicsShareFunc EpicsAtomicPtrT epicsAtomicGetPtrT ( const EpicsAtomicPtrT * pTar * to access the target, return the original value stored in the * target */ -epicsShareFunc size_t epicsAtomicCmpAndSwapSizeT ( size_t * pTarget, +EPICS_ATOMIC_INLINE size_t epicsAtomicCmpAndSwapSizeT ( size_t * pTarget, size_t oldVal, size_t newVal ); -epicsShareFunc int epicsAtomicCmpAndSwapIntT ( int * pTarget, +EPICS_ATOMIC_INLINE int epicsAtomicCmpAndSwapIntT ( int * pTarget, int oldVal, int newVal ); -epicsShareFunc EpicsAtomicPtrT epicsAtomicCmpAndSwapPtrT ( +EPICS_ATOMIC_INLINE EpicsAtomicPtrT epicsAtomicCmpAndSwapPtrT ( EpicsAtomicPtrT * pTarget, EpicsAtomicPtrT oldVal, EpicsAtomicPtrT newVal ); @@ -111,119 +113,98 @@ namespace atomic { /* * overloaded c++ interface */ -epicsShareFunc size_t increment ( size_t & v ); -epicsShareFunc int increment ( int & v ); -epicsShareFunc size_t decrement ( size_t & v ); -epicsShareFunc int decrement ( int & v ); -epicsShareFunc size_t add ( size_t & v, size_t delta ); -epicsShareFunc int add ( int & v, int delta ); -epicsShareFunc size_t subtract ( size_t & v, size_t delta ); -epicsShareFunc int subtract ( int & v, int delta ); -epicsShareFunc void set ( size_t & v , size_t newValue ); -epicsShareFunc void set ( int & v, int newValue ); -epicsShareFunc void set ( EpicsAtomicPtrT & v, - EpicsAtomicPtrT newValue ); -epicsShareFunc size_t get ( const size_t & v ); -epicsShareFunc int get ( const int & v ); -epicsShareFunc EpicsAtomicPtrT get ( const EpicsAtomicPtrT & v ); -epicsShareFunc size_t compareAndSwap ( size_t & v, size_t oldVal, - size_t newVal ); -epicsShareFunc int compareAndSwap ( int & v, int oldVal, int newVal ); -epicsShareFunc EpicsAtomicPtrT compareAndSwap ( EpicsAtomicPtrT & v, - EpicsAtomicPtrT oldVal, - EpicsAtomicPtrT newVal ); /************* incr ***************/ -inline size_t increment ( size_t & v ) +EPICS_ATOMIC_INLINE size_t increment ( size_t & v ) { return epicsAtomicIncrSizeT ( & v ); } -inline int increment ( int & v ) +EPICS_ATOMIC_INLINE int increment ( int & v ) { return epicsAtomicIncrIntT ( & v ); } /************* decr ***************/ -inline size_t decrement ( size_t & v ) +EPICS_ATOMIC_INLINE size_t decrement ( size_t & v ) { return epicsAtomicDecrSizeT ( & v ); } -inline int decrement ( int & v ) +EPICS_ATOMIC_INLINE int decrement ( int & v ) { return epicsAtomicDecrIntT ( & v ); } /************* add ***************/ -inline size_t add ( size_t & v, size_t delta ) +EPICS_ATOMIC_INLINE size_t add ( size_t & v, size_t delta ) { return epicsAtomicAddSizeT ( & v, delta ); } -inline int add ( int & v, int delta ) +EPICS_ATOMIC_INLINE int add ( int & v, int delta ) { return epicsAtomicAddIntT ( & v, delta ); } /************* sub ***************/ -inline size_t subtract ( size_t & v, size_t delta ) +EPICS_ATOMIC_INLINE size_t subtract ( size_t & v, size_t delta ) { return epicsAtomicSubSizeT ( & v, delta ); } -inline int subtract ( int & v, int delta ) +EPICS_ATOMIC_INLINE int subtract ( int & v, int delta ) { return epicsAtomicAddIntT ( & v, -delta ); } /************* set ***************/ -inline void set ( size_t & v , size_t newValue ) +EPICS_ATOMIC_INLINE void set ( size_t & v , size_t newValue ) { epicsAtomicSetSizeT ( & v, newValue ); } -inline void set ( int & v, int newValue ) +EPICS_ATOMIC_INLINE void set ( int & v, int newValue ) { epicsAtomicSetIntT ( & v, newValue ); } -inline void set ( EpicsAtomicPtrT & v, EpicsAtomicPtrT newValue ) +EPICS_ATOMIC_INLINE void set ( EpicsAtomicPtrT & v, EpicsAtomicPtrT newValue ) { epicsAtomicSetPtrT ( & v, newValue ); } /************* get ***************/ -inline size_t get ( const size_t & v ) +EPICS_ATOMIC_INLINE size_t get ( const size_t & v ) { return epicsAtomicGetSizeT ( & v ); } -inline int get ( const int & v ) +EPICS_ATOMIC_INLINE int get ( const int & v ) { return epicsAtomicGetIntT ( & v ); } -inline EpicsAtomicPtrT get ( const EpicsAtomicPtrT & v ) +EPICS_ATOMIC_INLINE EpicsAtomicPtrT get ( const EpicsAtomicPtrT & v ) { return epicsAtomicGetPtrT ( & v ); } /************* cas ***************/ -inline size_t compareAndSwap ( size_t & v, - size_t oldVal, size_t newVal ) +EPICS_ATOMIC_INLINE size_t compareAndSwap ( size_t & v, + size_t oldVal, size_t newVal ) { return epicsAtomicCmpAndSwapSizeT ( & v, oldVal, newVal ); } -inline int compareAndSwap ( int & v, int oldVal, int newVal ) +EPICS_ATOMIC_INLINE int compareAndSwap ( int & v, int oldVal, int newVal ) { return epicsAtomicCmpAndSwapIntT ( & v, oldVal, newVal ); } -inline EpicsAtomicPtrT compareAndSwap ( EpicsAtomicPtrT & v, - EpicsAtomicPtrT oldVal, - EpicsAtomicPtrT newVal ) +EPICS_ATOMIC_INLINE EpicsAtomicPtrT compareAndSwap ( EpicsAtomicPtrT & v, + EpicsAtomicPtrT oldVal, + EpicsAtomicPtrT newVal ) { return epicsAtomicCmpAndSwapPtrT ( & v, oldVal, newVal ); } diff --git a/src/libCom/osi/os/WIN32/epicsAtomicOSD.cpp b/src/libCom/osi/os/WIN32/epicsAtomicOSD.cpp deleted file mode 100644 index e3f684e29..000000000 --- a/src/libCom/osi/os/WIN32/epicsAtomicOSD.cpp +++ /dev/null @@ -1,22 +0,0 @@ - -/*************************************************************************\ -* Copyright (c) 2011 LANS LLC, as Operator of -* Los Alamos National Laboratory. -* EPICS BASE is distributed subject to a Software License Agreement found -* in file LICENSE that is included with this distribution. -\*************************************************************************/ - -/* - * Author Jeffrey O. Hill - * johill@lanl.gov - */ - -#define epicsExportSharedSymbols -#include "epicsAtomic.h" - -// if the compiler is unable to inline then instantiate out-of-line -#ifndef EPICS_ATOMIC_INLINE -# define EPICS_ATOMIC_INLINE -# include "epicsAtomicOSD.h" -#endif - diff --git a/src/libCom/osi/os/default/epicsAtomicOSD.c b/src/libCom/osi/os/default/epicsAtomicOSD.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/libCom/osi/os/posix/epicsAtomicOSD.cpp b/src/libCom/osi/os/posix/epicsAtomicOSD.cpp index 6e94cbcc4..1cc227fcd 100644 --- a/src/libCom/osi/os/posix/epicsAtomicOSD.cpp +++ b/src/libCom/osi/os/posix/epicsAtomicOSD.cpp @@ -19,14 +19,6 @@ #include "epicsAssert.h" #include "epicsAtomic.h" -// if the compiler is unable to inline then instantiate out-of-line -#ifndef EPICS_ATOMIC_INLINE -# define EPICS_ATOMIC_INLINE -# include "epicsAtomicOSD.h" -#endif - -#ifndef EPICS_ATOMIC_LOCK - /* * Slow, but probably correct on all systems. * Useful only if something more efficient isn`t @@ -69,31 +61,14 @@ void epicsAtomicUnlock ( EpicsAtomicLockKey * ) assert ( status == 0 ); } -#endif // ifndef EPICS_ATOMIC_LOCK -#ifndef EPICS_ATOMIC_READ_MEMORY_BARRIER // Slow, but probably correct on all systems. // Useful only if something more efficient isn`t // provided based on knowledge of the compiler // or OS -void epicsAtomicReadMemoryBarrier () +void epicsAtomicMemoryBarrierFallback (void) { EpicsAtomicLockKey key; epicsAtomicLock ( & key ); epicsAtomicUnlock ( & key ); } -#endif - -#ifndef EPICS_ATOMIC_WRITE_MEMORY_BARRIER -// Slow, but probably correct on all systems. -// Useful only if something more efficient isn`t -// provided based on knowledge of the compiler -// or OS -void epicsAtomicWriteMemoryBarrier () -{ - EpicsAtomicLockKey key; - epicsAtomicLock ( & key ); - epicsAtomicUnlock ( & key ); -} -#endif - diff --git a/src/libCom/osi/os/posix/epicsAtomicOSD.h b/src/libCom/osi/os/posix/epicsAtomicOSD.h index ff972016d..fdc38dfe2 100644 --- a/src/libCom/osi/os/posix/epicsAtomicOSD.h +++ b/src/libCom/osi/os/posix/epicsAtomicOSD.h @@ -16,14 +16,31 @@ #ifndef epicsAtomicOSD_h #define epicsAtomicOSD_h +#include + typedef struct EpicsAtomicLockKey {} EpicsAtomicLockKey; #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ +#ifndef EPICS_ATOMIC_READ_MEMORY_BARRIER +EPICS_ATOMIC_INLINE void epicsAtomicReadMemoryBarrier (void) +{ + epicsAtomicMemoryBarrierFallback(); +} +#endif + +#ifndef EPICS_ATOMIC_READ_MEMORY_BARRIER +EPICS_ATOMIC_INLINE void epicsAtomicWriteMemoryBarrier (void) +{ + epicsAtomicMemoryBarrierFallback(); +} +#endif + epicsShareFunc void epicsAtomicLock ( struct EpicsAtomicLockKey * ); epicsShareFunc void epicsAtomicUnlock ( struct EpicsAtomicLockKey * ); +epicsShareFunc void epicsAtomicMemoryBarrierFallback ( void ); #ifdef __cplusplus } /* end of extern "C" */ diff --git a/src/libCom/osi/os/solaris/epicsAtomicOSD.h b/src/libCom/osi/os/solaris/epicsAtomicOSD.h index 6dbda494d..14a5f1502 100644 --- a/src/libCom/osi/os/solaris/epicsAtomicOSD.h +++ b/src/libCom/osi/os/solaris/epicsAtomicOSD.h @@ -13,6 +13,8 @@ * johill@lanl.gov */ +#include "shareLib.h" + #ifndef epicsAtomicOSD_h #define epicsAtomicOSD_h @@ -31,7 +33,7 @@ extern "C" { #ifndef EPICS_ATOMIC_READ_MEMORY_BARRIER #define EPICS_ATOMIC_READ_MEMORY_BARRIER -EPICS_ATOMIC_INLINE void epicsAtomicReadMemoryBarrier () +EPICS_ATOMIC_INLINE void epicsAtomicReadMemoryBarrier (void) { membar_consumer (); } @@ -39,7 +41,7 @@ EPICS_ATOMIC_INLINE void epicsAtomicReadMemoryBarrier () #ifndef EPICS_ATOMIC_WRITE_MEMORY_BARRIER #define EPICS_ATOMIC_WRITE_MEMORY_BARRIER -EPICS_ATOMIC_INLINE void epicsAtomicWriteMemoryBarrier () +EPICS_ATOMIC_INLINE void epicsAtomicWriteMemoryBarrier (void) { membar_producer (); } @@ -47,7 +49,7 @@ EPICS_ATOMIC_INLINE void epicsAtomicWriteMemoryBarrier () #ifndef EPICS_ATOMIC_CAS_INTT #define EPICS_ATOMIC_CAS_INTT -EPICS_ATOMIC_INLINE int epicsAtomicCmpAndSwapIntT ( int * pTarget, +EPICS_ATOMIC_INLINE int epicsAtomicCmpAndSwapIntT ( int * pTarget, int oldVal, int newVal ) { STATIC_ASSERT ( sizeof ( int ) == sizeof ( unsigned ) ); @@ -59,7 +61,7 @@ EPICS_ATOMIC_INLINE int epicsAtomicCmpAndSwapIntT ( int * pTarget, #ifndef EPICS_ATOMIC_CAS_SIZET #define EPICS_ATOMIC_CAS_SIZET -EPICS_ATOMIC_INLINE size_t epicsAtomicCmpAndSwapSizeT ( +EPICS_ATOMIC_INLINE size_t epicsAtomicCmpAndSwapSizeT ( size_t * pTarget, size_t oldVal, size_t newVal ) { @@ -71,7 +73,7 @@ EPICS_ATOMIC_INLINE size_t epicsAtomicCmpAndSwapSizeT ( #ifndef EPICS_ATOMIC_CAS_PTRT #define EPICS_ATOMIC_CAS_PTRT -EPICS_ATOMIC_INLINE EpicsAtomicPtrT epicsAtomicCmpAndSwapPtrT ( +EPICS_ATOMIC_INLINE EpicsAtomicPtrT epicsAtomicCmpAndSwapPtrT ( EpicsAtomicPtrT * pTarget, EpicsAtomicPtrT oldVal, EpicsAtomicPtrT newVal ) @@ -132,7 +134,7 @@ EPICS_ATOMIC_INLINE int epicsAtomicAddIntT ( int * pTarget, int delta ) #ifndef EPICS_ATOMIC_ADD_SIZET #define EPICS_ATOMIC_ADD_SIZET -EPICS_ATOMIC_INLINE size_t epicsAtomicAddSizeT ( size_t * pTarget, +EPICS_ATOMIC_INLINE size_t epicsAtomicAddSizeT ( size_t * pTarget, size_t delta ) { STATIC_ASSERT ( sizeof ( ulong_t ) == sizeof ( size_t ) ); @@ -143,7 +145,7 @@ EPICS_ATOMIC_INLINE size_t epicsAtomicAddSizeT ( size_t * pTarget, #ifndef EPICS_ATOMIC_SUB_SIZET #define EPICS_ATOMIC_SUB_SIZET -EPICS_ATOMIC_INLINE size_t epicsAtomicSubSizeT ( size_t * pTarget, +EPICS_ATOMIC_INLINE size_t epicsAtomicSubSizeT ( size_t * pTarget, size_t delta ) { STATIC_ASSERT ( sizeof ( ulong_t ) == sizeof ( size_t ) ); diff --git a/src/libCom/osi/os/vxWorks/epicsAtomicOSD.cpp b/src/libCom/osi/os/vxWorks/epicsAtomicOSD.cpp deleted file mode 100644 index 6a9f529a3..000000000 --- a/src/libCom/osi/os/vxWorks/epicsAtomicOSD.cpp +++ /dev/null @@ -1,21 +0,0 @@ - -/*************************************************************************\ -* Copyright (c) 2011 LANS LLC, as Operator of -* Los Alamos National Laboratory. -* EPICS BASE is distributed subject to a Software License Agreement found -* in file LICENSE that is included with this distribution. -\*************************************************************************/ - -/* - * Author Jeffrey O. Hill - * johill@lanl.gov - */ - -#define epicsExportSharedSymbols -#include "epicsAtomic.h" - -// if the compiler is unable to inline then instantiate out-of-line -#ifndef EPICS_ATOMIC_INLINE -# define EPICS_ATOMIC_INLINE -# include "epicsAtomicOSD.h" -#endif diff --git a/src/libCom/osi/os/vxWorks/epicsAtomicOSD.h b/src/libCom/osi/os/vxWorks/epicsAtomicOSD.h index 5454e70ba..32a7d5a10 100644 --- a/src/libCom/osi/os/vxWorks/epicsAtomicOSD.h +++ b/src/libCom/osi/os/vxWorks/epicsAtomicOSD.h @@ -38,7 +38,7 @@ extern "C" { #ifndef EPICS_ATOMIC_READ_MEMORY_BARRIER #define EPICS_ATOMIC_READ_MEMORY_BARRIER -EPICS_ATOMIC_INLINE void epicsAtomicReadMemoryBarrier () +EPICS_ATOMIC_INLINE void epicsAtomicReadMemoryBarrier (void) { VX_MEM_BARRIER_R (); } @@ -46,7 +46,7 @@ EPICS_ATOMIC_INLINE void epicsAtomicReadMemoryBarrier () #ifndef EPICS_ATOMIC_WRITE_MEMORY_BARRIER #define EPICS_ATOMIC_WRITE_MEMORY_BARRIER -EPICS_ATOMIC_INLINE void epicsAtomicWriteMemoryBarrier () +EPICS_ATOMIC_INLINE void epicsAtomicWriteMemoryBarrier (void) { VX_MEM_BARRIER_W (); } @@ -232,7 +232,7 @@ EPICS_ATOMIC_INLINE void epicsAtomicUnlock ( EpicsAtomicLockKey * pKey ) * no need for memory barrior since prior to vxWorks 6.6 it is a single cpu system * (we are not protecting against multiple access to memory mapped IO) */ -EPICS_ATOMIC_INLINE void epicsAtomicReadMemoryBarrier () {} +EPICS_ATOMIC_INLINE void epicsAtomicReadMemoryBarrier (void) {} #endif #ifndef EPICS_ATOMIC_WRITE_MEMORY_BARRIER @@ -241,7 +241,7 @@ EPICS_ATOMIC_INLINE void epicsAtomicReadMemoryBarrier () {} * no need for memory barrior since prior to vxWorks 6.6 it is a single cpu system * (we are not protecting against multiple access to memory mapped IO) */ -EPICS_ATOMIC_INLINE void epicsAtomicWriteMemoryBarrier () {} +EPICS_ATOMIC_INLINE void epicsAtomicWriteMemoryBarrier (void) {} #endif #ifdef __cplusplus From 214c9003a9837e8a1b284273f5c76a404d41563f Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Fri, 27 Feb 2015 17:29:11 -0500 Subject: [PATCH 4/7] epicsAtomicTest: include some information about build conditions Give some idea which implementations are being used --- src/libCom/osi/compiler/clang/epicsAtomicCD.h | 2 + .../osi/compiler/default/epicsAtomicCD.h | 2 + src/libCom/osi/compiler/gcc/epicsAtomicCD.h | 2 + src/libCom/osi/compiler/msvc/epicsAtomicCD.h | 4 + .../osi/compiler/solStudio/epicsAtomicCD.h | 2 + src/libCom/osi/os/WIN32/epicsAtomicOSD.h | 2 + src/libCom/osi/os/posix/epicsAtomicOSD.h | 2 + src/libCom/osi/os/solaris/epicsAtomicOSD.h | 2 + src/libCom/osi/os/vxWorks/epicsAtomicOSD.h | 4 + src/libCom/test/epicsAtomicTest.cpp | 78 +++++++++++++++++++ 10 files changed, 100 insertions(+) diff --git a/src/libCom/osi/compiler/clang/epicsAtomicCD.h b/src/libCom/osi/compiler/clang/epicsAtomicCD.h index 34037869b..763cb0537 100644 --- a/src/libCom/osi/compiler/clang/epicsAtomicCD.h +++ b/src/libCom/osi/compiler/clang/epicsAtomicCD.h @@ -16,6 +16,8 @@ #ifndef epicsAtomicCD_h #define epicsAtomicCD_h +#define EPICS_ATOMIC_CMPLR_NAME "CLANG" + #include "epicsAtomicOSD.h" #endif /* epicsAtomicCD_h */ diff --git a/src/libCom/osi/compiler/default/epicsAtomicCD.h b/src/libCom/osi/compiler/default/epicsAtomicCD.h index 34037869b..585a39c97 100644 --- a/src/libCom/osi/compiler/default/epicsAtomicCD.h +++ b/src/libCom/osi/compiler/default/epicsAtomicCD.h @@ -16,6 +16,8 @@ #ifndef epicsAtomicCD_h #define epicsAtomicCD_h +#define EPICS_ATOMIC_CMPLR_NAME "DEFAULT" + #include "epicsAtomicOSD.h" #endif /* epicsAtomicCD_h */ diff --git a/src/libCom/osi/compiler/gcc/epicsAtomicCD.h b/src/libCom/osi/compiler/gcc/epicsAtomicCD.h index 8f7f97d16..15b9a6c9a 100644 --- a/src/libCom/osi/compiler/gcc/epicsAtomicCD.h +++ b/src/libCom/osi/compiler/gcc/epicsAtomicCD.h @@ -20,6 +20,8 @@ # error this header is only for use with the gnu compiler #endif +#define EPICS_ATOMIC_CMPLR_NAME "GCC" + #define GCC_ATOMIC_CONCAT( A, B ) GCC_ATOMIC_CONCATR(A,B) #define GCC_ATOMIC_CONCATR( A, B ) ( A ## B ) diff --git a/src/libCom/osi/compiler/msvc/epicsAtomicCD.h b/src/libCom/osi/compiler/msvc/epicsAtomicCD.h index 282aa971a..e7d1c4b77 100644 --- a/src/libCom/osi/compiler/msvc/epicsAtomicCD.h +++ b/src/libCom/osi/compiler/msvc/epicsAtomicCD.h @@ -24,6 +24,8 @@ #ifdef _MSC_EXTENSIONS +#define EPICS_ATOMIC_CMPLR_NAME "MSVC-INTRINSIC" + #include #if defined ( _M_IX86 ) @@ -102,6 +104,8 @@ EPICS_ATOMIC_INLINE void epicsAtomicWriteMemoryBarrier (void) #else /* ifdef _MSC_EXTENSIONS */ +#define EPICS_ATOMIC_CMPLR_NAME "MSVC-DIRECT" + /* * if unavailable as an intrinsic we will try * for os specific inline solution diff --git a/src/libCom/osi/compiler/solStudio/epicsAtomicCD.h b/src/libCom/osi/compiler/solStudio/epicsAtomicCD.h index 34037869b..8a733a558 100644 --- a/src/libCom/osi/compiler/solStudio/epicsAtomicCD.h +++ b/src/libCom/osi/compiler/solStudio/epicsAtomicCD.h @@ -16,6 +16,8 @@ #ifndef epicsAtomicCD_h #define epicsAtomicCD_h +#define EPICS_ATOMIC_CMPLR_NAME "SOLSTUDIO" + #include "epicsAtomicOSD.h" #endif /* epicsAtomicCD_h */ diff --git a/src/libCom/osi/os/WIN32/epicsAtomicOSD.h b/src/libCom/osi/os/WIN32/epicsAtomicOSD.h index da5e49c86..2170fceff 100644 --- a/src/libCom/osi/os/WIN32/epicsAtomicOSD.h +++ b/src/libCom/osi/os/WIN32/epicsAtomicOSD.h @@ -16,6 +16,8 @@ #ifndef epicsAtomicOSD_h #define epicsAtomicOSD_h +#define EPICS_ATOMIC_OS_NAME "WIN32" + #ifdef VC_EXTRALEAN # define VC_EXTRALEAN_DETECTED_epicsAtomicOSD_h #else diff --git a/src/libCom/osi/os/posix/epicsAtomicOSD.h b/src/libCom/osi/os/posix/epicsAtomicOSD.h index fdc38dfe2..9dad0e204 100644 --- a/src/libCom/osi/os/posix/epicsAtomicOSD.h +++ b/src/libCom/osi/os/posix/epicsAtomicOSD.h @@ -18,6 +18,8 @@ #include +#define EPICS_ATOMIC_OS_NAME "POSIX" + typedef struct EpicsAtomicLockKey {} EpicsAtomicLockKey; #ifdef __cplusplus diff --git a/src/libCom/osi/os/solaris/epicsAtomicOSD.h b/src/libCom/osi/os/solaris/epicsAtomicOSD.h index 14a5f1502..1fa23bd88 100644 --- a/src/libCom/osi/os/solaris/epicsAtomicOSD.h +++ b/src/libCom/osi/os/solaris/epicsAtomicOSD.h @@ -18,6 +18,8 @@ #ifndef epicsAtomicOSD_h #define epicsAtomicOSD_h +#define EPICS_ATOMIC_OS_NAME "Solaris" + #if defined ( __SunOS_5_10 ) /* diff --git a/src/libCom/osi/os/vxWorks/epicsAtomicOSD.h b/src/libCom/osi/os/vxWorks/epicsAtomicOSD.h index 32a7d5a10..e7bdde0c3 100644 --- a/src/libCom/osi/os/vxWorks/epicsAtomicOSD.h +++ b/src/libCom/osi/os/vxWorks/epicsAtomicOSD.h @@ -32,6 +32,8 @@ #include #include +#define EPICS_ATOMIC_OS_NAME "VX-ATOMICLIB" + #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ @@ -206,6 +208,8 @@ EPICS_ATOMIC_INLINE int epicsAtomicCmpAndSwapIntT ( int * pTarget, #include "vxLib.h" #include "intLib.h" +#define EPICS_ATOMIC_OS_NAME "VX-INTLIB" + #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ diff --git a/src/libCom/test/epicsAtomicTest.cpp b/src/libCom/test/epicsAtomicTest.cpp index 78cfa5b95..21d56eec7 100644 --- a/src/libCom/test/epicsAtomicTest.cpp +++ b/src/libCom/test/epicsAtomicTest.cpp @@ -248,11 +248,89 @@ template void testCAS < EpicsAtomicPtrT > (void); # pragma warning ( pop ) #endif +static void testClassify() +{ + testDiag("Classify Build conditions"); +#ifdef EPICS_ATOMIC_CMPLR_NAME + testDiag("Compiler dependent impl name %s", EPICS_ATOMIC_CMPLR_NAME); +#else + testDiag("Compiler dependent impl name undefined"); +#endif +#ifdef EPICS_ATOMIC_CMPLR_NAME + testDiag("OS dependent impl name %s", EPICS_ATOMIC_OS_NAME); +#else + testDiag("OS dependent impl name undefined"); +#endif + +#ifdef __GNUC__ +#if GCC_ATOMIC_INTRINSICS_GCC4_OR_BETTER + testDiag("GCC using atomic builtin memory barrier"); +#else + testDiag("GCC using asm memory barrier"); +#endif +#if GCC_ATOMIC_INTRINSICS_AVAIL_INT_T || GCC_ATOMIC_INTRINSICS_AVAIL_EARLIER + testDiag("GCC use builtin for int"); +#endif +#if GCC_ATOMIC_INTRINSICS_AVAIL_SIZE_T || GCC_ATOMIC_INTRINSICS_AVAIL_EARLIER + testDiag("GCC use builtin for size_t"); +#endif + +#ifndef EPICS_ATOMIC_INCR_INTT + testDiag("Use default epicsAtomicIncrIntT()"); +#endif +#ifndef EPICS_ATOMIC_INCR_SIZET + testDiag("Use default epicsAtomicIncrSizeT()"); +#endif +#ifndef EPICS_ATOMIC_DECR_INTT + testDiag("Use default epicsAtomicDecrIntT()"); +#endif +#ifndef EPICS_ATOMIC_DECR_SIZET + testDiag("Use default epicsAtomicDecrSizeT()"); +#endif +#ifndef EPICS_ATOMIC_ADD_INTT + testDiag("Use default epicsAtomicAddIntT()"); +#endif +#ifndef EPICS_ATOMIC_ADD_SIZET + testDiag("Use default epicsAtomicAddSizeT()"); +#endif +#ifndef EPICS_ATOMIC_SUB_SIZET + testDiag("Use default epicsAtomicSubSizeT()"); +#endif +#ifndef EPICS_ATOMIC_SET_INTT + testDiag("Use default epicsAtomicSetIntT()"); +#endif +#ifndef EPICS_ATOMIC_SET_SIZET + testDiag("Use default epicsAtomicSetSizeT()"); +#endif +#ifndef EPICS_ATOMIC_SET_PTRT + testDiag("Use default epicsAtomicSetPtrT()"); +#endif +#ifndef EPICS_ATOMIC_GET_INTT + testDiag("Use default epicsAtomicGetIntT()"); +#endif +#ifndef EPICS_ATOMIC_GET_SIZET + testDiag("Use default epicsAtomicGetSizeT()"); +#endif +#ifndef EPICS_ATOMIC_GET_PTRT + testDiag("Use default epicsAtomicGetPtrT()"); +#endif +#ifndef EPICS_ATOMIC_CAS_INTT + testDiag("Use default epicsAtomicCmpAndSwapIntT()"); +#endif +#ifndef EPICS_ATOMIC_CAS_SIZET + testDiag("Use default epicsAtomicCmpAndSwapSizeT()"); +#endif +#ifndef EPICS_ATOMIC_CAS_PTRT + testDiag("Use default epicsAtomicCmpAndSwapPtrT()"); +#endif +#endif /* __GNUC__ */ +} MAIN ( epicsAtomicTest ) { testPlan ( 31 ); + testClassify (); testIncrDecr < int > (); testIncrDecr < size_t > (); From 332fd550adf945f1146a27312caed3ec7fe2f847 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Fri, 27 Feb 2015 17:29:11 -0500 Subject: [PATCH 5/7] epicsAtomic: RTEMS ISR safe impl. for epicsAtomicLock() --- src/libCom/osi/epicsAtomic.h | 2 +- src/libCom/osi/os/RTEMS/epicsAtomicOSD.h | 65 ++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/libCom/osi/os/RTEMS/epicsAtomicOSD.h diff --git a/src/libCom/osi/epicsAtomic.h b/src/libCom/osi/epicsAtomic.h index f568c9de0..b3aad5c9c 100644 --- a/src/libCom/osi/epicsAtomic.h +++ b/src/libCom/osi/epicsAtomic.h @@ -19,7 +19,7 @@ #include "compilerSpecific.h" -#define EPICS_ATOMIC_INLINE EPICS_FUNC_INLINE +#define EPICS_ATOMIC_INLINE static EPICS_ALWAYS_INLINE #ifdef __cplusplus extern "C" { diff --git a/src/libCom/osi/os/RTEMS/epicsAtomicOSD.h b/src/libCom/osi/os/RTEMS/epicsAtomicOSD.h new file mode 100644 index 000000000..fefd2015e --- /dev/null +++ b/src/libCom/osi/os/RTEMS/epicsAtomicOSD.h @@ -0,0 +1,65 @@ + +/*************************************************************************\ +* Copyright (c) 2011 LANS LLC, as Operator of +* Los Alamos National Laboratory. +* Copyright (c) 2011 UChicago Argonne LLC, as Operator of Argonne +* National Laboratory. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ + +/* + * Author Jeffrey O. Hill + * johill@lanl.gov + */ + +#ifndef epicsAtomicOSD_h +#define epicsAtomicOSD_h + +#include +#include "epicsMMIO.h" +#include "compilerSpecific.h" +#include "epicsInterrupt.h" + +#define EPICS_ATOMIC_OS_NAME "RTEMS" + +typedef struct EpicsAtomicLockKey { + int key; +} EpicsAtomicLockKey; + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#ifndef EPICS_ATOMIC_READ_MEMORY_BARRIER +EPICS_ATOMIC_INLINE void epicsAtomicReadMemoryBarrier (void) +{ + epicsAtomicMemoryBarrierFallback(); +} +#endif + +#ifndef EPICS_ATOMIC_READ_MEMORY_BARRIER +EPICS_ATOMIC_INLINE void epicsAtomicWriteMemoryBarrier (void) +{ + rwbarr(); +} +#endif + +EPICS_ATOMIC_INLINE void epicsAtomicLock ( struct EpicsAtomicLockKey * pkey ) +{ + pkey->key = epicsInterruptLock(); +} + +EPICS_ATOMIC_INLINE void epicsAtomicUnlock ( struct EpicsAtomicLockKey * pkey ) +{ + epicsInterruptUnlock(pkey->key); +} + +#ifdef __cplusplus +} /* end of extern "C" */ +#endif /* __cplusplus */ + +#include "epicsAtomicDefault.h" + +#endif /* epicsAtomicOSD_h */ + From 73dcc2745ffaec7ce9ec51c470bafe2973dde728 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Fri, 27 Feb 2015 17:29:11 -0500 Subject: [PATCH 6/7] Fix for Solaris C++ compiler --- src/libCom/osi/compiler/solStudio/compilerSpecific.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libCom/osi/compiler/solStudio/compilerSpecific.h b/src/libCom/osi/compiler/solStudio/compilerSpecific.h index 2bdcec64d..a9d59a5bf 100644 --- a/src/libCom/osi/compiler/solStudio/compilerSpecific.h +++ b/src/libCom/osi/compiler/solStudio/compilerSpecific.h @@ -16,11 +16,12 @@ #ifndef compilerSpecific_h #define compilerSpecific_h -#ifndef __SUNPRO_C +#if !defined(__SUNPRO_C) && !defined (__SUNPRO_CC) # error Not Solaris Studio #endif -#if __SUNPRO_C<0x590 +#if (defined(__SUNPRO_C) && __SUNPRO_C < 0x590) || \ + (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590) # define EPICS_ALWAYS_INLINE inline #else # define EPICS_ALWAYS_INLINE inline __attribute__((always_inline)) From 89596fc30853d39e6d1871d67e72356ef6b92da5 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Fri, 27 Feb 2015 17:29:11 -0500 Subject: [PATCH 7/7] Fix typo in epicsAtomicTest.cpp testClassify() --- src/libCom/test/epicsAtomicTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libCom/test/epicsAtomicTest.cpp b/src/libCom/test/epicsAtomicTest.cpp index 21d56eec7..1c4dcf20f 100644 --- a/src/libCom/test/epicsAtomicTest.cpp +++ b/src/libCom/test/epicsAtomicTest.cpp @@ -256,7 +256,7 @@ static void testClassify() #else testDiag("Compiler dependent impl name undefined"); #endif -#ifdef EPICS_ATOMIC_CMPLR_NAME +#ifdef EPICS_ATOMIC_OS_NAME testDiag("OS dependent impl name %s", EPICS_ATOMIC_OS_NAME); #else testDiag("OS dependent impl name undefined");