Compilation issue on `mipsel-unknown-linux-musl` target
matszczygiel opened this issue · 0 comments
matszczygiel commented
Hello,
I was recently compiling rtp crate for mipsel-unknown-linux-musl
target and got compilation error about AtomicU64
not being defined.
As it turns out, this specific architecture does not support atomic operations on u64
, so rust stdlib does not provide it.
Moreover during inspecton I noticed some synchronization problems with SequencerImpl::next_sequence_number
. It is possible that
self.roll_over_count
may accidentally be incremented by 2 when this method is called from multiple threads.
I will open a pull request which fixes that using simple Mutex
,. It also fixes the compilation issue on mipsel
target.
#[derive(Debug, Clone)]
struct SequencerImpl {
sequence_number: Arc<AtomicU16>,
roll_over_count: Arc<AtomicU64>,
}
impl Sequencer for SequencerImpl {
/// NextSequenceNumber increment and returns a new sequence number for
/// building RTP packets
fn next_sequence_number(&self) -> u16 {
let sequence_number = self.sequence_number.load(Ordering::SeqCst);
if sequence_number == u16::MAX {
self.roll_over_count.fetch_add(1, Ordering::SeqCst);
self.sequence_number.store(0, Ordering::SeqCst);
0
} else {
self.sequence_number
.store(sequence_number + 1, Ordering::SeqCst);
sequence_number + 1
}
}
/// RollOverCount returns the amount of times the 16bit sequence number
/// has wrapped
fn roll_over_count(&self) -> u64 {
self.roll_over_count.load(Ordering::SeqCst)
}
fn clone_to(&self) -> Box<dyn Sequencer + Send + Sync> {
Box::new(self.clone())
}
}