-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1270 Fix "ring buffer too small for writing block" error
by replacing the old ring buffer with a new one when its space is exhausted (allocation happens in worker thread)
- Loading branch information
Showing
6 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -47,3 +47,5 @@ pub mod panic_util; | |
|
||
mod approx_f64; | ||
pub use approx_f64::*; | ||
|
||
pub mod replenishment_channel; |
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,49 @@ | ||
use futures::future::BoxFuture; | ||
use tokio::sync::mpsc::Receiver; | ||
use tracing::debug; | ||
|
||
/// An orchestration (task and receiver) to be used to supply the receiver with spare parts that might or might not be | ||
/// necessary. | ||
/// | ||
/// This is usually used in scenarios where the consumer lives in a thread that is not allowed to allocate | ||
/// (for example, real-time threads). | ||
pub struct ReplenishmentOrchestration<T, F> { | ||
pub task: F, | ||
pub receiver: ReplenishmentReceiver<T>, | ||
} | ||
|
||
/// Creates an orchestration. | ||
/// | ||
/// The capacity should be very low, depending on how many spare items you want to create. | ||
pub fn orchestrate_replenishment<T>( | ||
capacity: usize, | ||
mut create_next_item: impl FnMut() -> T + Send + 'static, | ||
) -> ReplenishmentOrchestration<T, BoxFuture<'static, ()>> | ||
where | ||
T: Send + 'static, | ||
{ | ||
let (sender, receiver) = tokio::sync::mpsc::channel::<T>(capacity); | ||
let task = async move { | ||
while let Ok(permit) = sender.reserve().await { | ||
debug!("Replenishment channel has capacity. Create next item."); | ||
let item = create_next_item(); | ||
permit.send(item); | ||
} | ||
}; | ||
ReplenishmentOrchestration { | ||
receiver: ReplenishmentReceiver { receiver }, | ||
task: Box::pin(task), | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct ReplenishmentReceiver<T> { | ||
receiver: Receiver<T>, | ||
} | ||
|
||
impl<T> ReplenishmentReceiver<T> { | ||
/// Returns the next available item if one is available. | ||
pub fn request_item(&mut self) -> Option<T> { | ||
self.receiver.try_recv().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
Submodule playtime-clip-engine
updated
from e2c862 to 676eb6