Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
55fb4db
copy `bson-cmp.h` to `mcd-cmp.h`
kevinAlbs Oct 3, 2024
c6cbf2a
rename symbols in `mcd-cmp.h`
kevinAlbs Oct 9, 2024
563a3e7
do not include private libbson header in common
kevinAlbs Oct 7, 2024
5bb1894
include `common-prelude.h`
kevinAlbs Oct 9, 2024
e141535
add `test-mcd-cmp.c`
kevinAlbs Oct 7, 2024
81272c2
use ASSERT, rather than BSON_ASSERT
kevinAlbs Oct 10, 2024
d87896f
deprecate functions in `bson-cmp.h`
kevinAlbs Oct 3, 2024
37b5b04
note deprecated
kevinAlbs Oct 7, 2024
a1c96a4
update NEWS
kevinAlbs Oct 7, 2024
f3352f8
replace `bson_cmp` with comparison in fuzz test
kevinAlbs Oct 7, 2024
4ae9664
replace use of deprecated functions
kevinAlbs Oct 9, 2024
9d218e0
remove use of `bson_in_range` in public examples
kevinAlbs Oct 9, 2024
d20b8ef
ignore deprecation warnings
kevinAlbs Oct 8, 2024
6dfa07f
copy `bson-atomic.(h|c)` to `mcd-atomic.(h|c)`
kevinAlbs Oct 9, 2024
839db51
rename symbols in `mcd-atomic.(h|c)`
kevinAlbs Oct 9, 2024
16369a6
remove `BSON_EXPORT`
kevinAlbs Oct 9, 2024
63218ed
include `common-prelude.h`
kevinAlbs Oct 9, 2024
1543c41
remove `BSON_BEGIN_DECLS`
kevinAlbs Oct 9, 2024
4465707
do not use private libbson headers
kevinAlbs Oct 9, 2024
c85111c
remove private deprecated API
kevinAlbs Oct 9, 2024
b567b47
deprecate atomic APIs
kevinAlbs Oct 9, 2024
b97b103
ignore deprecations within `bson-atomic.(h|c)`
kevinAlbs Oct 9, 2024
ae118e5
replace use of `bson-atomic.h` with `mcd-atomic.h`
kevinAlbs Oct 9, 2024
928cfc6
note deprecated
kevinAlbs Oct 9, 2024
82787f8
update NEWS
kevinAlbs Oct 9, 2024
28bc5a9
remove unused include of `bson-atomic.h`
kevinAlbs Oct 9, 2024
d4faaee
use prefix
kevinAlbs Oct 9, 2024
603077e
add `mcd-atomic.c`
kevinAlbs Oct 10, 2024
5d20c12
copy test-atomic.c to test-mcd-atomic.c
kevinAlbs Oct 10, 2024
77a479e
remove unnecessary check of `>= 0`
kevinAlbs Oct 11, 2024
6206dcf
add `u` suffix; remove unnecessary cast
kevinAlbs Oct 11, 2024
7a242d7
add missing period to NEWS
kevinAlbs Oct 11, 2024
ca1cb96
relocate NEWS entries to src/libbson/NEWS
kevinAlbs Oct 11, 2024
dd4774f
deprecate `bson_memory_order`
kevinAlbs Oct 11, 2024
670832d
remove deprecation attribute from `_` prefixed symbols
kevinAlbs Oct 11, 2024
f08f054
revert changes to `mongoc-stream-tls-secure-transport.c`
kevinAlbs Oct 11, 2024
0a8a289
update test name
kevinAlbs Oct 11, 2024
73c05c2
rename `mcd-cmp.h` to `common-cmp-private.h`
kevinAlbs Oct 11, 2024
360ab59
replace `mcd-cmp.h` with `common-cmp-private.h`
kevinAlbs Oct 11, 2024
d4a0e06
replace `mcd_cmp` with `mcommon_cmp`
kevinAlbs Oct 11, 2024
1d1ebf3
replace `mcd_in_range` with `mcommon_in_range`
kevinAlbs Oct 11, 2024
4ccc800
rename `test-mcd-cmp.c` to `test-common-cmp.c`
kevinAlbs Oct 11, 2024
1be81c8
rename `mcd-atomic.h` to `common-atomic-private.h`
kevinAlbs Oct 11, 2024
1613682
replace `mcd-atomic.h` with `common-atomic-private.h`
kevinAlbs Oct 11, 2024
f14c527
replace `mcd_memory` with `mcommon_memory`
kevinAlbs Oct 11, 2024
3a96638
update macro names in common-atomic-private.h
kevinAlbs Oct 11, 2024
7f380ae
replace `mcd_atomic` with `mcommon_atomic`
kevinAlbs Oct 11, 2024
398cbb6
replace `_mcd_emul` with `_mcommon_emul`
kevinAlbs Oct 11, 2024
8efa4f1
replace `mcd_thrd_yield` with `mcommon_thrd_yield`
kevinAlbs Oct 11, 2024
2886316
replace "mcd" with "mcommon" in test name of `test-mcommon-cmp.c`
kevinAlbs Oct 11, 2024
4fff740
update test name in `test-mcd-atomic.c`
kevinAlbs Oct 11, 2024
7e4dded
rename `test-mcd-atomic.c` to `test-common-atomic.c`
kevinAlbs Oct 11, 2024
4b1903c
update macro guards
kevinAlbs Oct 14, 2024
9754ab9
replace `BSON_GNUC_DEPRECATED_FOR` with `BSON_GNUC_DEPRECATED`
kevinAlbs Oct 14, 2024
871e2cb
Merge branch 'master' into deprecate-utils.C5702
kevinAlbs Oct 14, 2024
d301485
update `bson_in_range_*` post-merge
kevinAlbs Oct 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
libmongoc 1.29.0 (unreleased)
=============================

Deprecated:

* Compiling with `BSON_MEMCHECK` defined is deprecated.
* `bson_string_t` and associated functions.

Platform Support:

Expand Down
3 changes: 2 additions & 1 deletion src/common/bson-dsl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

#include "bson/bson.h"
#include <common-cmp-private.h>

enum {
/// Toggle this value to enable/disable debug output for all bsonDSL
Expand Down Expand Up @@ -118,7 +119,7 @@ BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\""))
_bsonDSL_begin ("\"%s\" => [%s]", String, _bsonDSL_strElide (30, Element)); \
const char *_bbString = (String); \
const uint64_t length = (Len); \
if (bson_in_range_unsigned (int, length)) { \
if (mcommon_in_range_unsigned (int, length)) { \
_bbCtx.key = _bbString; \
_bbCtx.key_len = (int) length; \
_bsonValueOperation (Element); \
Expand Down
621 changes: 621 additions & 0 deletions src/common/common-atomic-private.h

Large diffs are not rendered by default.

251 changes: 251 additions & 0 deletions src/common/common-atomic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
/*
* 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 <common-atomic-private.h>

#ifdef BSON_OS_UNIX
/* For sched_yield() */
#include <sched.h>
#endif

void
mcommon_thrd_yield (void)
{
BSON_IF_WINDOWS (SwitchToThread ();)
BSON_IF_POSIX (sched_yield ();)
}

/**
* Some platforms do not support compiler intrinsics for atomic operations.
* We emulate that here using a spin lock and regular arithmetic operations
*/
static int8_t gEmulAtomicLock = 0;

static void
_lock_emul_atomic (void)
{
int i;
if (mcommon_atomic_int8_compare_exchange_weak (&gEmulAtomicLock, 0, 1, mcommon_memory_order_acquire) == 0) {
/* Successfully took the spinlock */
return;
}
/* Failed. Try taking ten more times, then begin sleeping. */
for (i = 0; i < 10; ++i) {
if (mcommon_atomic_int8_compare_exchange_weak (&gEmulAtomicLock, 0, 1, mcommon_memory_order_acquire) == 0) {
/* Succeeded in taking the lock */
return;
}
}
/* Still don't have the lock. Spin and yield */
while (mcommon_atomic_int8_compare_exchange_weak (&gEmulAtomicLock, 0, 1, mcommon_memory_order_acquire) != 0) {
mcommon_thrd_yield ();
}
}

static void
_unlock_emul_atomic (void)
{
int64_t rv = mcommon_atomic_int8_exchange (&gEmulAtomicLock, 0, mcommon_memory_order_release);
BSON_ASSERT (rv == 1 && "Released atomic lock while not holding it");
}

int64_t
_mcommon_emul_atomic_int64_fetch_add (volatile int64_t *p, int64_t n, enum mcommon_memory_order _unused)
{
int64_t ret;

BSON_UNUSED (_unused);

_lock_emul_atomic ();
ret = *p;
*p += n;
_unlock_emul_atomic ();
return ret;
}

int64_t
_mcommon_emul_atomic_int64_exchange (volatile int64_t *p, int64_t n, enum mcommon_memory_order _unused)
{
int64_t ret;

BSON_UNUSED (_unused);

_lock_emul_atomic ();
ret = *p;
*p = n;
_unlock_emul_atomic ();
return ret;
}

int64_t
_mcommon_emul_atomic_int64_compare_exchange_strong (volatile int64_t *p,
int64_t expect_value,
int64_t new_value,
enum mcommon_memory_order _unused)
{
int64_t ret;

BSON_UNUSED (_unused);

_lock_emul_atomic ();
ret = *p;
if (ret == expect_value) {
*p = new_value;
}
_unlock_emul_atomic ();
return ret;
}

int64_t
_mcommon_emul_atomic_int64_compare_exchange_weak (volatile int64_t *p,
int64_t expect_value,
int64_t new_value,
enum mcommon_memory_order order)
{
/* We're emulating. We can't do a weak version. */
return _mcommon_emul_atomic_int64_compare_exchange_strong (p, expect_value, new_value, order);
}


int32_t
_mcommon_emul_atomic_int32_fetch_add (volatile int32_t *p, int32_t n, enum mcommon_memory_order _unused)
{
int32_t ret;

BSON_UNUSED (_unused);

_lock_emul_atomic ();
ret = *p;
*p += n;
_unlock_emul_atomic ();
return ret;
}

int32_t
_mcommon_emul_atomic_int32_exchange (volatile int32_t *p, int32_t n, enum mcommon_memory_order _unused)
{
int32_t ret;

BSON_UNUSED (_unused);

_lock_emul_atomic ();
ret = *p;
*p = n;
_unlock_emul_atomic ();
return ret;
}

int32_t
_mcommon_emul_atomic_int32_compare_exchange_strong (volatile int32_t *p,
int32_t expect_value,
int32_t new_value,
enum mcommon_memory_order _unused)
{
int32_t ret;

BSON_UNUSED (_unused);

_lock_emul_atomic ();
ret = *p;
if (ret == expect_value) {
*p = new_value;
}
_unlock_emul_atomic ();
return ret;
}

int32_t
_mcommon_emul_atomic_int32_compare_exchange_weak (volatile int32_t *p,
int32_t expect_value,
int32_t new_value,
enum mcommon_memory_order order)
{
/* We're emulating. We can't do a weak version. */
return _mcommon_emul_atomic_int32_compare_exchange_strong (p, expect_value, new_value, order);
}


int
_mcommon_emul_atomic_int_fetch_add (volatile int *p, int n, enum mcommon_memory_order _unused)
{
int ret;

BSON_UNUSED (_unused);

_lock_emul_atomic ();
ret = *p;
*p += n;
_unlock_emul_atomic ();
return ret;
}

int
_mcommon_emul_atomic_int_exchange (volatile int *p, int n, enum mcommon_memory_order _unused)
{
int ret;

BSON_UNUSED (_unused);

_lock_emul_atomic ();
ret = *p;
*p = n;
_unlock_emul_atomic ();
return ret;
}

int
_mcommon_emul_atomic_int_compare_exchange_strong (volatile int *p,
int expect_value,
int new_value,
enum mcommon_memory_order _unused)
{
int ret;

BSON_UNUSED (_unused);

_lock_emul_atomic ();
ret = *p;
if (ret == expect_value) {
*p = new_value;
}
_unlock_emul_atomic ();
return ret;
}

int
_mcommon_emul_atomic_int_compare_exchange_weak (volatile int *p,
int expect_value,
int new_value,
enum mcommon_memory_order order)
{
/* We're emulating. We can't do a weak version. */
return _mcommon_emul_atomic_int_compare_exchange_strong (p, expect_value, new_value, order);
}

void *
_mcommon_emul_atomic_ptr_exchange (void *volatile *p, void *n, enum mcommon_memory_order _unused)
{
void *ret;

BSON_UNUSED (_unused);

_lock_emul_atomic ();
ret = *p;
*p = n;
_unlock_emul_atomic ();
return ret;
}
Loading