From 59ff8953992aa37d436ee4869e4d440eff098b9c Mon Sep 17 00:00:00 2001 From: Micah Scott Date: Fri, 11 Oct 2024 14:24:42 -0700 Subject: [PATCH 1/5] bson-compat: replace bson_sync_synchronize macro with deprecated inline --- src/libbson/src/bson/bson-compat.h | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/libbson/src/bson/bson-compat.h b/src/libbson/src/bson/bson-compat.h index eb28dcd3eab..ca2c2e8c3da 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,14 @@ typedef signed char bool; #define BSON_IF_POSIX(...) __VA_ARGS__ #endif +static BSON_INLINE void +BSON_GNUC_DEPRECATED_FOR ("bson_atomic_thread_fence") +bson_sync_synchronize (void) +{ + BSON_IF_MSVC (MemoryBarrier ();) + BSON_IF_GNU_LIKE (__sync_synchronize ();) +} + BSON_END_DECLS From daf012e6ced663490cc4a0469a64a1a67ffa9080 Mon Sep 17 00:00:00 2001 From: Micah Scott Date: Fri, 11 Oct 2024 14:26:19 -0700 Subject: [PATCH 2/5] tests: trivial test for bson_sync_synchronize --- src/libbson/tests/test-bson-sync.c | 38 +++++++++++++++++++++++ src/libmongoc/CMakeLists.txt | 1 + src/libmongoc/tests/test-libmongoc-main.c | 1 + 3 files changed, 40 insertions(+) create mode 100644 src/libbson/tests/test-bson-sync.c diff --git a/src/libbson/tests/test-bson-sync.c b/src/libbson/tests/test-bson-sync.c new file mode 100644 index 00000000000..5173f28cfcf --- /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); +} \ No newline at end of file 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); From fbd1f8762a80c5ccf5891bd3d01a884c34839331 Mon Sep 17 00:00:00 2001 From: Micah Scott Date: Fri, 11 Oct 2024 15:09:12 -0700 Subject: [PATCH 3/5] test-bson-sync: newline for end-of-file --- src/libbson/tests/test-bson-sync.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libbson/tests/test-bson-sync.c b/src/libbson/tests/test-bson-sync.c index 5173f28cfcf..878bac8d8b9 100644 --- a/src/libbson/tests/test-bson-sync.c +++ b/src/libbson/tests/test-bson-sync.c @@ -35,4 +35,4 @@ void test_bson_sync_install (TestSuite *suite) { TestSuite_Add (suite, "/bson/sync/synchronize", test_bson_sync_synchronize); -} \ No newline at end of file +} From d218ab95f55179698d9dbaed2814284b18c12e81 Mon Sep 17 00:00:00 2001 From: Micah Scott Date: Fri, 11 Oct 2024 15:45:56 -0700 Subject: [PATCH 4/5] bson-compat: prefer DEPRECATED over DEPRECATED_FOR, atomic is on the way out --- src/libbson/src/bson/bson-compat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libbson/src/bson/bson-compat.h b/src/libbson/src/bson/bson-compat.h index ca2c2e8c3da..aaf29f1c459 100644 --- a/src/libbson/src/bson/bson-compat.h +++ b/src/libbson/src/bson/bson-compat.h @@ -204,7 +204,7 @@ typedef signed char bool; #endif static BSON_INLINE void -BSON_GNUC_DEPRECATED_FOR ("bson_atomic_thread_fence") +BSON_GNUC_DEPRECATED bson_sync_synchronize (void) { BSON_IF_MSVC (MemoryBarrier ();) From 0ddbaa4ad55db563dfe1f65de424f103720f82c4 Mon Sep 17 00:00:00 2001 From: Micah Scott Date: Fri, 11 Oct 2024 15:46:48 -0700 Subject: [PATCH 5/5] clang-format-all --- src/libbson/src/bson/bson-compat.h | 3 +-- src/libbson/tests/test-bson-sync.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libbson/src/bson/bson-compat.h b/src/libbson/src/bson/bson-compat.h index aaf29f1c459..e2dacfdcf5b 100644 --- a/src/libbson/src/bson/bson-compat.h +++ b/src/libbson/src/bson/bson-compat.h @@ -203,8 +203,7 @@ typedef signed char bool; #define BSON_IF_POSIX(...) __VA_ARGS__ #endif -static BSON_INLINE void -BSON_GNUC_DEPRECATED +static BSON_INLINE void BSON_GNUC_DEPRECATED bson_sync_synchronize (void) { BSON_IF_MSVC (MemoryBarrier ();) diff --git a/src/libbson/tests/test-bson-sync.c b/src/libbson/tests/test-bson-sync.c index 878bac8d8b9..b37642f909b 100644 --- a/src/libbson/tests/test-bson-sync.c +++ b/src/libbson/tests/test-bson-sync.c @@ -26,7 +26,7 @@ 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(); + bson_sync_synchronize (); END_IGNORE_DEPRECATIONS }