Skip to content

PHPC-1997: Migrate to new libbson atomic API #1272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 5, 2021

Conversation

jmikola
Copy link
Member

@jmikola jmikola commented Nov 5, 2021

@@ -3789,7 +3789,7 @@ PHP_GSHUTDOWN_FUNCTION(mongodb)
* is the last thread, MSHUTDOWN has been called, persistent clients from
* all threads have been destroyed, and it is now safe to shutdown libmongoc
* and restore libbson's original vtable. */
if (bson_atomic_int_add(&phongo_num_threads, -1) == 0) {
if (bson_atomic_int32_fetch_sub(&phongo_num_threads, 1, bson_memory_order_seq_cst) - 1 == 0) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vector-of-bool: Would you mind sanity-checking these two lines? In the one above, I'm just doing an increment and don't need the return value. Here's we're decrementing and checking the return value, so I believe I need to also subtract from the result since the __atomic_fetch_OP built-ins return the original value (in contrast to __atomic_OP_fetch variants).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is correct: The value returned will be the value from before the operation completes.

Copy link

@vector-of-bool vector-of-bool left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jmikola jmikola merged commit a8a2210 into mongodb:master Nov 5, 2021
@jmikola jmikola deleted the phpc-1997 branch November 5, 2021 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants