diff --git a/src/libbson/src/bson/bson-compat.h b/src/libbson/src/bson/bson-compat.h index eb28dcd3eab..e2dacfdcf5b 100644 --- a/src/libbson/src/bson/bson-compat.h +++ b/src/libbson/src/bson/bson-compat.h @@ -169,19 +169,6 @@ typedef signed char bool; #endif -#if defined(__GNUC__) -#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) -#define bson_sync_synchronize() __sync_synchronize () -#elif defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(__x86_64__) -#define bson_sync_synchronize() asm volatile ("mfence" ::: "memory") -#else -#define bson_sync_synchronize() asm volatile ("sync" ::: "memory") -#endif -#elif defined(_MSC_VER) -#define bson_sync_synchronize() MemoryBarrier () -#endif - - #if !defined(va_copy) && defined(__va_copy) #define va_copy(dst, src) __va_copy (dst, src) #endif @@ -216,6 +203,13 @@ typedef signed char bool; #define BSON_IF_POSIX(...) __VA_ARGS__ #endif +static BSON_INLINE void BSON_GNUC_DEPRECATED +bson_sync_synchronize (void) +{ + BSON_IF_MSVC (MemoryBarrier ();) + BSON_IF_GNU_LIKE (__sync_synchronize ();) +} + BSON_END_DECLS diff --git a/src/libbson/tests/test-bson-sync.c b/src/libbson/tests/test-bson-sync.c new file mode 100644 index 00000000000..b37642f909b --- /dev/null +++ b/src/libbson/tests/test-bson-sync.c @@ -0,0 +1,38 @@ +/* + * Copyright 2009-present MongoDB, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include // BEGIN_IGNORE_DEPRECATIONS + +#include "TestSuite.h" + +static void +test_bson_sync_synchronize (void) +{ + BEGIN_IGNORE_DEPRECATIONS + + // This doesn't test for correct functionality, only that it exists and can be called + bson_sync_synchronize (); + + END_IGNORE_DEPRECATIONS +} + +void +test_bson_sync_install (TestSuite *suite) +{ + TestSuite_Add (suite, "/bson/sync/synchronize", test_bson_sync_synchronize); +} diff --git a/src/libmongoc/CMakeLists.txt b/src/libmongoc/CMakeLists.txt index 2347bca9075..65a2224b3a6 100644 --- a/src/libmongoc/CMakeLists.txt +++ b/src/libmongoc/CMakeLists.txt @@ -1037,6 +1037,7 @@ set (test-libmongoc-sources ${mongo-c-driver_SOURCE_DIR}/src/libbson/tests/test-bson-cmp.c ${mongo-c-driver_SOURCE_DIR}/src/libbson/tests/test-bson-corpus.c ${mongo-c-driver_SOURCE_DIR}/src/libbson/tests/test-bson-error.c + ${mongo-c-driver_SOURCE_DIR}/src/libbson/tests/test-bson-sync.c ${mongo-c-driver_SOURCE_DIR}/src/libbson/tests/test-bson-version.c ${mongo-c-driver_SOURCE_DIR}/src/libbson/tests/test-bson.c ${mongo-c-driver_SOURCE_DIR}/src/libbson/tests/test-clock.c diff --git a/src/libmongoc/tests/test-libmongoc-main.c b/src/libmongoc/tests/test-libmongoc-main.c index f38ab7431c7..a64bed0e6b3 100644 --- a/src/libmongoc/tests/test-libmongoc-main.c +++ b/src/libmongoc/tests/test-libmongoc-main.c @@ -30,6 +30,7 @@ main (int argc, char *argv[]) TEST_INSTALL (test_bson_corpus_install); TEST_INSTALL (test_bson_error_install); TEST_INSTALL (test_bson_install); + TEST_INSTALL (test_bson_sync_install); TEST_INSTALL (test_bson_version_install); TEST_INSTALL (test_clock_install); TEST_INSTALL (test_decimal128_install);