Skip to content
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

py/runtime: move MICROPY_PORT_INIT_FUNC to end of mp_init() #5511

Closed
wants to merge 1 commit into from

Conversation

dlech
Copy link
Contributor

@dlech dlech commented Jan 9, 2020

This moves the MICROPY_PORT_INIT_FUNC hook to the end of mp_init(), just before MP_THREAD_GIL_ENTER() so that everything is intialized before the hook is called.

The particular case this is trying to fix is for a MICROPY_PORT_INIT_FUNC that makes use of the GIL mutex in a background thread. The mutext must be intialized before MICROPY_PORT_INIT_FUNC is called, othwerwise we end up with a race condition where the background thread could potentially use it before it is intialized.

This moves the MICROPY_PORT_INIT_FUNC hook to the end of mp_init(), just before MP_THREAD_GIL_ENTER() so that everything is intialized before the hook is called.

The particular case this is trying to fix is for a MICROPY_PORT_INIT_FUNC that makes use of the GIL mutex in a background thread. The mutext must be intialized before MICROPY_PORT_INIT_FUNC is called, othwerwise we end up with a race condition where the background thread could potentially use it before it is intialized.
@dpgeorge dpgeorge added the py-core Relates to py/ directory in source label Jan 12, 2020
@dpgeorge
Copy link
Member

Thanks for the patch, it looks ok. The operations between where MICROPY_PORT_INIT_FUNC was previously, and where it's moved to in this patch, are mostly just assigning values to the uPy state so there should not be much functional change for those using MICROPY_PORT_INIT_FUNC. In this code-base only the windows port uses this option and there it's setting things independent to the uPy runtime, so should be safe with this change.

Merge in 339d081

@dpgeorge dpgeorge closed this Jan 12, 2020
tannewt added a commit to tannewt/circuitpython that referenced this pull request Oct 28, 2021
when the MTU of the BLE connection is smaller than the 28 bytes of
the header. (The smallest possible MTU is 20.)

Fixes micropython#5511
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
py-core Relates to py/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants