mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-30 17:10:48 +01:00
SERVER-12064 SERVER-12283 Use gcc atomic builtins if available
Switch to using gcc atomic builtins for atomic operations if using a new enough gcc and clang and support is available. Otherwise, fall back to the old behaviour of existing non-portable inline assembly to continue to support builds on older versions of gcc. Signed-off-by: Benety Goh <benety@mongodb.com>
This commit is contained in:
parent
677bd638dd
commit
19cceceb78
24
SConstruct
24
SConstruct
@ -1431,6 +1431,30 @@ def doConfigure(myenv):
|
||||
if haveUUThread:
|
||||
myenv.Append(CPPDEFINES=['MONGO_HAVE___THREAD'])
|
||||
|
||||
if using_gcc() or using_clang():
|
||||
def CheckGCCAtomicBuiltins(context):
|
||||
test_body = """
|
||||
int main(int argc, char **argv) {
|
||||
int a = 0;
|
||||
int b = 0;
|
||||
int c = 0;
|
||||
|
||||
__atomic_compare_exchange(&a, &b, &c, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
context.Message('Checking for gcc atomic builtins... ')
|
||||
ret = context.TryLink(textwrap.dedent(test_body), '.cpp')
|
||||
context.Result(ret)
|
||||
return ret
|
||||
conf = Configure(myenv, help=False, custom_tests = {
|
||||
'CheckGCCAtomicBuiltins': CheckGCCAtomicBuiltins,
|
||||
})
|
||||
haveGCCAtomicBuiltins = conf.CheckGCCAtomicBuiltins()
|
||||
conf.Finish()
|
||||
if haveGCCAtomicBuiltins:
|
||||
conf.env.Append(CPPDEFINES=["HAVE_GCC_ATOMIC_BUILTINS"])
|
||||
|
||||
conf = Configure(myenv)
|
||||
libdeps.setup_conftests(conf)
|
||||
|
||||
|
@ -43,10 +43,12 @@
|
||||
#if defined(_WIN32)
|
||||
#include "mongo/platform/atomic_intrinsics_win32.h"
|
||||
#elif defined(__GNUC__)
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
#if defined(HAVE_GCC_ATOMIC_BUILTINS)
|
||||
#include "mongo/platform/atomic_intrinsics_gcc_generic.h"
|
||||
#elif defined(__i386__) || defined(__x86_64__)
|
||||
#include "mongo/platform/atomic_intrinsics_gcc_intel.h"
|
||||
#else
|
||||
#include "mongo/platform/atomic_intrinsics_gcc_generic.h"
|
||||
#error "Unsupported platform: no gcc atomic builtins or port available"
|
||||
#endif
|
||||
#else
|
||||
#error "Unsupported os/compiler family"
|
||||
|
Loading…
Reference in New Issue
Block a user