]> git.lizzy.rs Git - rust.git/commit
libsync: Add safer abstraction for SPSC queue.
authorKevin Butler <haqkrs@gmail.com>
Fri, 25 Jul 2014 19:58:27 +0000 (20:58 +0100)
committerKevin Butler <haqkrs@gmail.com>
Fri, 1 Aug 2014 19:09:03 +0000 (20:09 +0100)
commit7b817b6ab97f31d96dc935278fa4d34e4b510782
treecb6f23e65aa1564fdd92c2baa60e0e95a4e6ad8c
parent624885810344184f7040892637250c35ceaf8db7
libsync: Add safer abstraction for SPSC queue.

The current spsc implementation doesn't enforce single-producer
single-consumer usage and also allows unsafe memory use through
peek & pop.

For safer usage, `spsc_queue::queue` now returns a pair of owned objects which
only allow consumer or producer behaviours through an `Arc`.
Through restricting the mutability of the receiver to `mut` the
peek and pop behaviour becomes safe again, with the compiler
complaining about usage which could lead to problems.

To fix code broken from this, update:
Queue::new(x) -> unsafe { Queue::new(x) }

[breaking-change]
src/libsync/comm/stream.rs
src/libsync/spsc_queue.rs