Skip to content

Commit 71475df

Browse files
author
Micah Scott @ MongoDB
authored
CDRIVER-4220 simplify and test obsolete bson_sync_synchronize API (#1766)
The bson_sync_synchronize() macro in bson_compat has long been superseded by bson_atomic_thread_fence(), and all of bson_atomic is now deprecated. This change replaces bson_sync_synchronize with a deprecated inline function, preparing for its removal in the next major version. * bson-compat: replace bson_sync_synchronize macro with deprecated inline * tests: trivial test for bson_sync_synchronize
1 parent 3c354f0 commit 71475df

File tree

4 files changed

+47
-13
lines changed

4 files changed

+47
-13
lines changed

src/libbson/src/bson/bson-compat.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,6 @@ typedef signed char bool;
169169
#endif
170170

171171

172-
#if defined(__GNUC__)
173-
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
174-
#define bson_sync_synchronize() __sync_synchronize ()
175-
#elif defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(__x86_64__)
176-
#define bson_sync_synchronize() asm volatile ("mfence" ::: "memory")
177-
#else
178-
#define bson_sync_synchronize() asm volatile ("sync" ::: "memory")
179-
#endif
180-
#elif defined(_MSC_VER)
181-
#define bson_sync_synchronize() MemoryBarrier ()
182-
#endif
183-
184-
185172
#if !defined(va_copy) && defined(__va_copy)
186173
#define va_copy(dst, src) __va_copy (dst, src)
187174
#endif
@@ -216,6 +203,13 @@ typedef signed char bool;
216203
#define BSON_IF_POSIX(...) __VA_ARGS__
217204
#endif
218205

206+
static BSON_INLINE void BSON_GNUC_DEPRECATED
207+
bson_sync_synchronize (void)
208+
{
209+
BSON_IF_MSVC (MemoryBarrier ();)
210+
BSON_IF_GNU_LIKE (__sync_synchronize ();)
211+
}
212+
219213

220214
BSON_END_DECLS
221215

src/libbson/tests/test-bson-sync.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2009-present MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
18+
#include <bson/bson.h>
19+
#include <common-macros-private.h> // BEGIN_IGNORE_DEPRECATIONS
20+
21+
#include "TestSuite.h"
22+
23+
static void
24+
test_bson_sync_synchronize (void)
25+
{
26+
BEGIN_IGNORE_DEPRECATIONS
27+
28+
// This doesn't test for correct functionality, only that it exists and can be called
29+
bson_sync_synchronize ();
30+
31+
END_IGNORE_DEPRECATIONS
32+
}
33+
34+
void
35+
test_bson_sync_install (TestSuite *suite)
36+
{
37+
TestSuite_Add (suite, "/bson/sync/synchronize", test_bson_sync_synchronize);
38+
}

src/libmongoc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,7 @@ set (test-libmongoc-sources
10401040
${mongo-c-driver_SOURCE_DIR}/src/libbson/tests/test-bson-cmp.c
10411041
${mongo-c-driver_SOURCE_DIR}/src/libbson/tests/test-bson-corpus.c
10421042
${mongo-c-driver_SOURCE_DIR}/src/libbson/tests/test-bson-error.c
1043+
${mongo-c-driver_SOURCE_DIR}/src/libbson/tests/test-bson-sync.c
10431044
${mongo-c-driver_SOURCE_DIR}/src/libbson/tests/test-bson-version.c
10441045
${mongo-c-driver_SOURCE_DIR}/src/libbson/tests/test-bson.c
10451046
${mongo-c-driver_SOURCE_DIR}/src/libbson/tests/test-clock.c

src/libmongoc/tests/test-libmongoc-main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ main (int argc, char *argv[])
3030
TEST_INSTALL (test_bson_corpus_install);
3131
TEST_INSTALL (test_bson_error_install);
3232
TEST_INSTALL (test_bson_install);
33+
TEST_INSTALL (test_bson_sync_install);
3334
TEST_INSTALL (test_bson_version_install);
3435
TEST_INSTALL (test_clock_install);
3536
TEST_INSTALL (test_decimal128_install);

0 commit comments

Comments
 (0)