Skip to content

Commit

Permalink
fix: Correct a timing issue with a RwLock in JoyHub devices
Browse files Browse the repository at this point in the history
  • Loading branch information
blackspherefollower authored and qdot committed Apr 20, 2024
1 parent d146969 commit 07ddf2c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions buttplug/src/server/device/protocol/joyhub.rs
Expand Up @@ -57,7 +57,7 @@ fn vibes_changed(
new_commands: &[Option<(ActuatorType, u32)>],
exclude: Vec<usize>,
) -> bool {
let old_commands = old_commands_lock.try_read().expect("locks should work");
let old_commands = old_commands_lock.read().expect("locks should work");
if old_commands.len() != new_commands.len() {
return true;
}
Expand Down Expand Up @@ -135,7 +135,7 @@ impl ProtocolHandler for JoyHub {
async_manager::spawn(async move { delayed_constrict_handler(dev, cmd.1 as u8).await });
cmd2 = None;
} else {
let mut command_writer = self.last_cmds.try_write().expect("Locks should work");
let mut command_writer = self.last_cmds.write().expect("Locks should work");
*command_writer = commands.to_vec();

return Ok(vec![HardwareWriteCmd::new(
Expand All @@ -155,7 +155,7 @@ impl ProtocolHandler for JoyHub {
}
}

let mut command_writer = self.last_cmds.try_write().expect("Locks should work");
let mut command_writer = self.last_cmds.write().expect("Locks should work");
*command_writer = commands.to_vec();
Ok(vec![HardwareWriteCmd::new(
Endpoint::Tx,
Expand Down
8 changes: 4 additions & 4 deletions buttplug/src/server/device/protocol/joyhub_v2.rs
Expand Up @@ -50,7 +50,7 @@ fn vibes_changed(
new_commands: &[Option<(ActuatorType, u32)>],
exclude: Vec<usize>,
) -> bool {
let old_commands = old_commands_lock.try_read().expect("locks should work");
let old_commands = old_commands_lock.read().expect("locks should work");
if old_commands.len() != new_commands.len() {
return true;
}
Expand Down Expand Up @@ -128,7 +128,7 @@ impl ProtocolHandler for JoyHubV2 {
async_manager::spawn(async move { delayed_constrict_handler(dev, cmd.1 as u8).await });
cmd2 = None;
} else {
let mut command_writer = self.last_cmds.try_write().expect("Locks should work");
let mut command_writer = self.last_cmds.write().expect("Locks should work");
*command_writer = commands.to_vec();

return Ok(vec![HardwareWriteCmd::new(
Expand All @@ -148,7 +148,7 @@ impl ProtocolHandler for JoyHubV2 {
async_manager::spawn(async move { delayed_constrict_handler(dev, cmd.1 as u8).await });
cmd3 = None;
} else {
let mut command_writer = self.last_cmds.try_write().expect("Locks should work");
let mut command_writer = self.last_cmds.write().expect("Locks should work");
*command_writer = commands.to_vec();

return Ok(vec![HardwareWriteCmd::new(
Expand All @@ -161,7 +161,7 @@ impl ProtocolHandler for JoyHubV2 {
}
}

let mut command_writer = self.last_cmds.try_write().expect("Locks should work");
let mut command_writer = self.last_cmds.write().expect("Locks should work");
*command_writer = commands.to_vec();
Ok(vec![HardwareWriteCmd::new(
Endpoint::Tx,
Expand Down

0 comments on commit 07ddf2c

Please sign in to comment.