Skip to content

Commit

Permalink
make RingBuffer Send + Sync so that the FrameDecoder is Send + Sync
Browse files Browse the repository at this point in the history
  • Loading branch information
KillingSpark committed Feb 18, 2024
1 parent 4688f44 commit a16e38b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/decoding/ringbuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ pub struct RingBuffer {
tail: usize,
}

// SAFETY: RingBuffer does not hold any thread specific values -> it can be sent to another thread -> RingBuffer is Send
unsafe impl Send for RingBuffer {}
// SAFETY: Ringbuffer does not provide unsyncronized interior mutability which makes &RingBuffer Send -> RingBuffer is Sync
unsafe impl Sync for RingBuffer {}

impl RingBuffer {
pub fn new() -> Self {
RingBuffer {
Expand Down
12 changes: 12 additions & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ fn assure_error_impl() {
let _err: &dyn std::error::Error = &FrameDecoderError::NotYetInitialized;
}

#[cfg(all(test, feature = "std"))]
#[allow(dead_code)]
fn assure_decoder_send_sync() {
// not a real test just there to throw an compiler error if FrameDecoder is Send + Sync

use crate::frame_decoder::FrameDecoder;
let decoder = FrameDecoder::new();
std::thread::spawn(move || {
drop(decoder);
});
}

#[test]
fn skippable_frame() {
use crate::frame;
Expand Down

0 comments on commit a16e38b

Please sign in to comment.