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

rt: unify entering a runtime with Handle::enter #5163

Merged
merged 2 commits into from Nov 3, 2022
Merged

Commits on Nov 3, 2022

  1. rt: unify entering a runtime with Handle::enter

    This is a frist step towards unifying the concepts of "entering a
    runtime" and setting `Handle::current`.
    
    Previously, these two operation were performed separately at each call
    site (runtime block_on, ...). This is error prone and also requires
    multiple accesses to the thread-local variable. Additionally, "entering
    the runtime" conflated the concept of entering a blocking region. For
    example, calling `mpsc::Receiver::recv_blocking` performed the "enter
    the runtime" step. This was done to prevent blocking a runtime as the
    operation will panic when called from an existing runtime.
    
    To untangle these concepts, the patch splits out each logical operation
    into its own call. In total, there are three "enter" operations:
    
    * `set_current_handle`
    * `enter_runtime`
    * `enter_blocking_region`
    
    There are some behavior changes with each of these functions, but they
    should not translate to public behavior changes. The most signifcant is
    `enter_blocking_region` does not change the value of the thread-local
    variable, which means the function can be re-entered. Since
    `enter_blocking_region` is an internal-only function and we do not
    actually re-enter, this has no public facing impact.
    
    Because `enter_runtime` takes a `&Handle` in order to combine the
    `set_current_handle` operation with entering a runtime, the patch
    exposes an annoyance with the current `scheduler::Handle` struct layout.
    A new instance of `scheduler::Handle` must be constructed at each call
    to `enter_runtime`. We can explore cleaning this up later.
    
    This patch also does not combine the "entered runtime" thread-local
    variable with the "context" thread-local variable. To keep the patch
    smaller, this has been punted to a follow up change.
    carllerche committed Nov 3, 2022
    Copy the full SHA
    67fa5ac View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    296b8bc View commit details
    Browse the repository at this point in the history