mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 20:26:42 +01:00
jack device mutex -> rwlock
This commit is contained in:
parent
52ea78a466
commit
33de8bbf1d
4 changed files with 17 additions and 13 deletions
|
|
@ -5,7 +5,7 @@ pub struct JackDevice {
|
|||
/// The active JACK client of this device.
|
||||
pub client: DynamicAsyncClient,
|
||||
/// The device state, encapsulated for sharing between threads.
|
||||
pub state: Arc<Mutex<Box<dyn Device>>>,
|
||||
pub state: Arc<RwLock<Box<dyn Device>>>,
|
||||
/// Unowned copies of the device's JACK ports, for connecting to the device.
|
||||
/// The "real" readable/writable `Port`s are owned by the `state`.
|
||||
pub ports: UnownedJackPorts,
|
||||
|
|
@ -22,8 +22,12 @@ ports!(JackDevice {
|
|||
});
|
||||
impl JackDevice {
|
||||
/// Returns a locked mutex of the state's contents.
|
||||
pub fn state (&self) -> MutexGuard<Box<dyn Device>> {
|
||||
self.state.lock().unwrap()
|
||||
pub fn state (&self) -> LockResult<RwLockReadGuard<Box<dyn Device>>> {
|
||||
self.state.read()
|
||||
}
|
||||
/// Returns a locked mutex of the state's contents.
|
||||
pub fn state_mut (&self) -> LockResult<RwLockWriteGuard<Box<dyn Device>>> {
|
||||
self.state.write()
|
||||
}
|
||||
pub fn connect_midi_in (&self, index: usize, port: &Port<Unowned>) -> Usually<()> {
|
||||
Ok(self.client.as_client().connect_ports(port, self.midi_ins()?[index])?)
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ impl Jack {
|
|||
.map(|p|Ok(p.name()?)).collect::<Usually<Vec<_>>>()?;
|
||||
let audio_ins = owned_ports.audio_ins.values()
|
||||
.map(|p|Ok(p.name()?)).collect::<Usually<Vec<_>>>()?;
|
||||
let state = Arc::new(Mutex::new(state(owned_ports) as Box<dyn Device>));
|
||||
let state = Arc::new(RwLock::new(state(owned_ports) as Box<dyn Device>));
|
||||
let client = self.client.activate_async(
|
||||
Notifications(Box::new({
|
||||
let _state = state.clone();
|
||||
|
|
@ -53,7 +53,7 @@ impl Jack {
|
|||
ClosureProcessHandler::new(Box::new({
|
||||
let state = state.clone();
|
||||
move|c: &Client, s: &ProcessScope|{
|
||||
state.lock().unwrap().process(c, s)
|
||||
state.write().unwrap().process(c, s)
|
||||
}
|
||||
}) as BoxedProcessHandler)
|
||||
)?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue