-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid spawning a disposal thread per driver (#151)
Adds a new field to Config, disposer, an Option<Sender<DisposalMessage>> responsible for dropping the DisposalMessage on a separate thread. If this is not set, and the Config is passed into manager::Songbird, a thread is spawned for this purpose (which previously was spawned per driver). If this is not set, and the Config is passed directly into Driver or Call, a thread is spawned locally, which is the current behavior as there is no where to store the Sender. This disposer is then used in Driver as previously, to run possibly blocking destructors (which should only block the disposal thread). I cannot see this disposal thread getting overloaded, but if it is the DisposalMessages will simply be queued in the flume channel until it can be dropped. Co-authored-by: Kyle Simpson <[email protected]>
- Loading branch information
1 parent
03b0803
commit be3a4e9
Showing
4 changed files
with
78 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,39 @@ | ||
use super::message::*; | ||
use flume::Receiver; | ||
use tracing::instrument; | ||
use flume::{Receiver, Sender}; | ||
use tracing::{instrument, trace}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct DisposalThread(Sender<DisposalMessage>); | ||
|
||
impl Default for DisposalThread { | ||
fn default() -> Self { | ||
Self::run() | ||
} | ||
} | ||
|
||
impl DisposalThread { | ||
pub fn run() -> Self { | ||
let (mix_tx, mix_rx) = flume::unbounded(); | ||
std::thread::spawn(move || { | ||
trace!("Disposal thread started."); | ||
runner(mix_rx); | ||
trace!("Disposal thread finished."); | ||
}); | ||
|
||
Self(mix_tx) | ||
} | ||
|
||
pub(super) fn dispose(&self, message: DisposalMessage) { | ||
drop(self.0.send(message)) | ||
} | ||
} | ||
|
||
/// The mixer's disposal thread is also synchronous, due to tracks, | ||
/// inputs, etc. being based on synchronous I/O. | ||
/// | ||
/// The mixer uses this to offload heavy and expensive drop operations | ||
/// to prevent deadline misses. | ||
#[instrument(skip(mix_rx))] | ||
pub(crate) fn runner(mix_rx: Receiver<DisposalMessage>) { | ||
fn runner(mix_rx: Receiver<DisposalMessage>) { | ||
while mix_rx.recv().is_ok() {} | ||
} |
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