-
Notifications
You must be signed in to change notification settings - Fork 197
Asynchronous unmounting methods for BackgroundSession #688
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -566,6 +566,15 @@ pub struct BackgroundSession { | |
| mount: Option<Mount>, | ||
| } | ||
|
|
||
| /// A set of relevant threads during an asynchronous unmounting process. | ||
| #[derive(Debug)] | ||
| pub struct BackgroundUnmount { | ||
| /// The unmounting thread | ||
| pub unmount_thread: JoinHandle<io::Result<()>>, | ||
| /// The session thread that hosts the filesystem | ||
| pub session_thread: JoinHandle<io::Result<()>>, | ||
| } | ||
|
|
||
| impl BackgroundSession { | ||
| /// Unmount the filesystem and join the background thread. | ||
| pub fn umount_and_join(mut self) -> io::Result<()> { | ||
|
|
@@ -591,4 +600,26 @@ impl BackgroundSession { | |
| ) | ||
| })? | ||
| } | ||
|
|
||
| /// Unmount the filesystem and return the background thread for manual joining. This is useful for asynchronous daemons that coordinate access to multiple filesystems. | ||
| pub fn umount_no_join(mut self) -> io::Result<JoinHandle<io::Result<()>>> { | ||
| if let Some(mount) = self.mount.take() { | ||
| mount.umount()?; | ||
| } | ||
| Ok(self.guard) | ||
| } | ||
|
|
||
| /// Unmount the filesystem from a separate thread and return the background thread for manual joining. This allows the main thread to continue doing useful work while reporting errors in the background, and for implementing structured concurrency by giving the filesystem threads an opportunity to be joined. | ||
| pub fn umount_background(mut self) -> BackgroundUnmount { | ||
| let unmount_thread = thread::spawn(move || { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In processes that have exhausted their thread quota or hit OS limits, Useful? React with 👍 / 👎. |
||
| if let Some(mount) = self.mount.take() { | ||
| mount.umount()?; | ||
| } | ||
| Ok(()) | ||
| }); | ||
| BackgroundUnmount { | ||
| unmount_thread, | ||
| session_thread: self.guard, | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this new public return type lives inside the private
sessionmodule whilesrc/lib.rsonly re-exportsBackgroundSession, downstream crates can receive the value by inference but cannot name it in their own function signatures, struct fields, or imports. Sinceumount_backgroundis a public API intended for batching/structured concurrency, re-exportBackgroundUnmountfrom the crate root alongsideBackgroundSession.Useful? React with 👍 / 👎.