Skip to content

Use native code for pthread_cleanup_push/pop. NFC #14484

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 1 commit into from
Jun 19, 2021

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Jun 18, 2021

This change reverts one of our musl patches so that
pthread_cleanup_push/pop are now implemented as macros as in upstream
musl.

pthread_cleanup_push/pop are now handled separately to
__cxa_atexit_thread, which is technically a bug fix. Without this fix,
calling __cxa_atexit_thread in the middle of push/pop block would end up
pop'ing the wrong thing at the end.

Overall this reduces the API surface of our JS API and increases the
amount of code we share with musl, while also reducing the cost of
pthread_cleanup_push/pop. Now, they never involve any allocation or
calls to JS!

@sbc100 sbc100 force-pushed the pthread_cleanup_push_pop branch 2 times, most recently from 3ee3c7a to 294a9e2 Compare June 18, 2021 16:56
@sbc100 sbc100 requested review from kleisauke and kripken June 18, 2021 16:57
@sbc100
Copy link
Collaborator Author

sbc100 commented Jun 18, 2021

I'm pretty happy with how this change turned out!

@sbc100 sbc100 force-pushed the pthread_cleanup_push_pop branch from 294a9e2 to 6360f7c Compare June 18, 2021 17:47
@sbc100 sbc100 requested a review from dschuff June 18, 2021 17:48
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Nice!

@sbc100 sbc100 force-pushed the pthread_cleanup_push_pop branch from 6360f7c to 845a01c Compare June 18, 2021 20:37
Copy link
Collaborator

@kleisauke kleisauke left a comment

Choose a reason for hiding this comment

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

LGTM!

@sbc100 sbc100 force-pushed the pthread_cleanup_push_pop branch from 845a01c to 3c466d6 Compare June 18, 2021 21:18
@sbc100 sbc100 enabled auto-merge (squash) June 18, 2021 21:20
@sbc100 sbc100 force-pushed the pthread_cleanup_push_pop branch from 3c466d6 to 22683fc Compare June 18, 2021 22:16
This change reverts one of our musl patches so that
`pthread_cleanup_push/pop` are now implemented as macros as in upstream
musl.

`pthread_cleanup_push/pop` are now handled separately to
`__cxa_atexit_thread`, which is technically a bug fix.  Without this fix,
calling `__cxa_atexit_thread` in the middle of push/pop block would end up
pop'ing the wrong thing at the end.

Overall this reduces the API surface of our JS API and increases the
amount of code we share with musl, while also reducing the cost of
`pthread_cleanup_push/pop.`  Now, they never involve any allocation or
calls to JS!
@sbc100 sbc100 force-pushed the pthread_cleanup_push_pop branch from 22683fc to c2e0862 Compare June 18, 2021 23:17
@sbc100 sbc100 merged commit f46fbc5 into main Jun 19, 2021
@sbc100 sbc100 deleted the pthread_cleanup_push_pop branch June 19, 2021 00:07
sbc100 added a commit that referenced this pull request Jun 19, 2021
Rather than using a separate JS array use pthread TLS key which get
cleaned during `__pthread_tsd_run_dtors`.

Followup to #14484 and #14464 which both move more of the cleanup
handling for threads and processes onto the native side.
sbc100 added a commit that referenced this pull request Jun 19, 2021
Rather than using a separate JS array use pthread TLS key which get
cleaned during `__pthread_tsd_run_dtors`.

Followup to #14484 and #14464 which both move more of the cleanup
handling for threads and processes onto the native side.
sbc100 added a commit that referenced this pull request Jun 19, 2021
Rather than using a separate JS array use pthread TLS key which get
cleaned during `__pthread_tsd_run_dtors`.

Followup to #14484 and #14464 which both move more of the cleanup
handling for threads and processes onto the native side.
sbc100 added a commit that referenced this pull request Jun 22, 2021
Rather than using a separate JS array use pthread TLS key which get
cleaned during `__pthread_tsd_run_dtors`.

Followup to #14484 and #14464 which both move more of the cleanup
handling for threads and processes onto the native side.
sbc100 added a commit that referenced this pull request Jun 22, 2021
Rather than using a separate JS array use pthread TLS key which get
cleaned during `__pthread_tsd_run_dtors`.

Followup to #14484 and #14464 which both move more of the cleanup
handling for threads and processes onto the native side.
self->cancelbuf = cb;
static thread_local bool registerd = false;
if (!registerd) {
__cxa_thread_atexit(__run_cleanup_handlers, NULL, &__dso_handle);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we set registerd (typo: registered) to true here? Noticed this during the review of #14489.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sbc100 added a commit that referenced this pull request Jun 23, 2021
Rather than using a separate JS array use pthread TLS key which get
cleaned during `__pthread_tsd_run_dtors`.

Followup to #14484 and #14464 which both move more of the cleanup
handling for threads and processes onto the native side.
sbc100 added a commit that referenced this pull request Jun 23, 2021
Rather than using a separate JS array use pthread TLS key which get
cleaned during `__pthread_tsd_run_dtors`.

Followup to #14484 and #14464 which both move more of the cleanup
handling for threads and processes onto the native side.
sbc100 added a commit that referenced this pull request Jun 28, 2021
Rather than using a separate JS array use pthread TLS key which get
cleaned during `__pthread_tsd_run_dtors`.

Followup to #14484 and #14464 which both move more of the cleanup
handling for threads and processes onto the native side.
sbc100 added a commit that referenced this pull request Jun 29, 2021
Rather than using a separate JS array use pthread TLS key which get
cleaned during `__pthread_tsd_run_dtors`.

Followup to #14484 and #14464 which both move more of the cleanup
handling for threads and processes onto the native side.
sbc100 added a commit that referenced this pull request Jun 30, 2021
Rather than using a separate JS array use pthread TLS key which get
cleaned during `__pthread_tsd_run_dtors`.

Followup to #14484 and #14464 which both move more of the cleanup
handling for threads and processes onto the native side.
sbc100 added a commit that referenced this pull request Oct 4, 2021
Rather than using a separate JS array use pthread TLS key which get
cleaned during `__pthread_tsd_run_dtors`.

Followup to #14484 and #14464 which both move more of the cleanup
handling for threads and processes onto the native side.
sbc100 added a commit that referenced this pull request Oct 4, 2021
Rather than using a separate JS array use pthread TLS key which get
cleaned during `__pthread_tsd_run_dtors`.

Followup to #14484 and #14464 which both move more of the cleanup
handling for threads and processes onto the native side.
sbc100 added a commit that referenced this pull request Oct 4, 2021
Rather than using a separate JS array use pthread TLS key which get
cleaned during `__pthread_tsd_run_dtors`.

Followup to #14484 and #14464 which both move more of the cleanup
handling for threads and processes onto the native side.
sbc100 added a commit that referenced this pull request Oct 4, 2021
Rather than using a separate JS array use pthread TLS key which get
cleaned during `__pthread_tsd_run_dtors`.

Followup to #14484 and #14464 which both move more of the cleanup
handling for threads and processes onto the native side.
sbc100 added a commit that referenced this pull request Oct 4, 2021
Rather than using a separate JS array use pthread TLS key which get
cleaned during `__pthread_tsd_run_dtors`.

Followup to #14484 and #14464 which both move more of the cleanup
handling for threads and processes onto the native side.
sbc100 added a commit that referenced this pull request Oct 4, 2021
Rather than using a separate JS array use pthread TLS key which get
cleaned during `__pthread_tsd_run_dtors`.

Followup to #14484 and #14464 which both move more of the cleanup
handling for threads and processes onto the native side.
sbc100 added a commit that referenced this pull request Oct 4, 2021
Use libc++abi's version of __cxa_thread_atexit.

Followup to #14484 and #14464 which both move more of the cleanup
handling for threads and processes onto the native side.

Depends on #15210.
sbc100 added a commit that referenced this pull request Aug 12, 2022
Rather than using a separate JS array use pthread TLS key which get
cleaned during `__pthread_tsd_run_dtors`.

Followup to #14484 and #14464 which both move more of the cleanup
handling for threads and processes onto the native side.
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.

3 participants