-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Each entrypoint to the container bits sets up a tokio runtime, which is inefficient and duplicative. We're also likely to start using Rust async in more places. Instead, create a Tokio runtime early in our `main`, and change the CLI entrypoint to be an `async fn`. The other setup of a runtime we have is deep inside the sysroot upgrader bits, also for the container. In this case we actually have another thread (distinct from the main one where we set up Tokio) created by C/C++, so we need to pass a `tokio::runtime::Handle` across, and call `enter()` on it to set up the thread local bindings to access tokio async from there. I was initially looking at properly handling `GCancellable` with tokio and wanted to clean this up first.
- Loading branch information
Showing
6 changed files
with
69 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//! Helpers to bridge tokio to C++ | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
pub(crate) struct TokioHandle(tokio::runtime::Handle); | ||
pub(crate) struct TokioEnterGuard<'a>(tokio::runtime::EnterGuard<'a>); | ||
|
||
pub(crate) fn tokio_handle_get() -> Box<TokioHandle> { | ||
Box::new(TokioHandle(tokio::runtime::Handle::current())) | ||
} | ||
|
||
impl TokioHandle { | ||
pub(crate) fn enter(&self) -> Box<TokioEnterGuard> { | ||
Box::new(TokioEnterGuard(self.0.enter())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters