Skip to content
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

Add Send + Sync to Aligner, along with unit test. #55

Merged
merged 1 commit into from
Mar 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,12 @@ impl Aligner {
}
}

mod send {
use crate::Aligner;
unsafe impl Sync for Aligner {}
unsafe impl Send for Aligner {}
}

/* TODO: This stopped working when we switched to not storing raw pointers but the structs themselves
// Since Rust is now handling the structs, I think memory gets freed that way, maybe this is no longer
// necessary?
Expand Down Expand Up @@ -1347,7 +1353,7 @@ mod tests {
);
assert_eq!(
align.cigar_str,
Some(String::from("14M2D4M3I37M1D85M1D48MS9"))
Some(String::from("14M2D4M3I37M1D85M1D48M9S"))
);
assert_eq!(
align.md,
Expand Down Expand Up @@ -1543,6 +1549,52 @@ mod tests {
}
}

#[test]
fn test_send() {
let seq = "CGGCACCAGGTTAAAATCTGAGTGCTGCAATAGGCGATTACAGTACAGCACCCAGCCTCCGAAATTCTTTAACGGTCGTCGTCTCGATACTGCCACTATGCCTTTATATTATTGTCTTCAGGTGATGCTGCAGATCGTGCAGACGGGTGGCTTTAGTGTTGTGGGATGCATAGCTATTGACGGATCTTTGTCAATTGACAGAAATACGGGTCTCTGGTTTGACATGAAGGTCCAACTGTAATAACTGATTTTATCTGTGGGTGATGCGTTTCTCGGACAACCACGACCGCGACCAGACTTAAGTCTGGGCGCGGTCGTGGTTGTCCGAGAAACGCATCACCCACAGATAAAATCAGTTATTACAGTTGGACCTTTATGTCAAACCAGAGACCCGTATTTC";
let query = "GGTCGTCGTCTCGATACTGCCACTATGCCTTTATATTATTGTCTTCAGGTGATGCTGCAGATCGTGCAGACGGGTGGCTTTAGTGTTGTGGGATGCATAGCTATTGACGGATCTTTGTCAATTGACAGAAATACGGGTCTCTGGTTTGACATGAAGGTCCAACTGTAATAACTGATTTTATCTGTGGGTGATGCGTTTCTCGGACAACCACGACCGCGACCAGACTTAAGTCTGGGCGCGGTCGTGGTT";
let aligner = Aligner::builder().short();
let aligner = std::sync::Arc::new(aligner.with_seq(seq.as_bytes()).unwrap());
let alignments = aligner
.map(query.as_bytes(), false, false, None, None)
.unwrap();
assert_eq!(alignments.len(), 2);

let (send, recv) = std::sync::mpsc::channel::<Vec<Mapping>>();
let receiver = std::thread::spawn(move || -> Vec<Vec<Mapping>> {
let mut ret = Vec::new();
while let Ok(batch) = recv.recv() {
ret.push(batch);
}
ret
});
let new_send = send.clone();
let new_aligner = aligner.clone();
let sender = std::thread::spawn(move || {
new_send
.send(
new_aligner
.map(query.as_bytes(), false, false, None, None)
.expect("Failed to map"),
)
.expect("Failed to send")
});
let new_sender = std::thread::spawn(move || {
send.send(
aligner
.map(query.as_bytes(), false, false, None, None)
.expect("Failed to map"),
)
.expect("Failed to send")
});
drop(sender);
drop(new_sender);
let received = receiver.join().unwrap();
assert_eq!(received[0], alignments);
assert_eq!(received[1], alignments);
assert_eq!(received.len(), 2);
}

#[test]
fn test_struct_config() {
let mut sr = Aligner::builder().sr();
Expand Down
Loading