jamesmunns / bbqueue

A SPSC, lockless, no_std, thread safe, queue, based on BipBuffers
Apache License 2.0
417 stars 51 forks source link

Add commit_and_grant convenience methods #56

Open jamesmunns opened 4 years ago

jamesmunns commented 4 years ago

Often you want to commit a grant (read or write), then immediately get the next grant, if possible. We should add an interface that lets you do that in one operation.

This would be particularly useful for "self reloading" DMA operations, where the "end of DMA interrupt" could immediately retrigger the next DMA transaction to start.

jamesmunns commented 4 years ago

Note: This might be a little awkward, because the commit methods are on the GRANT, not the Producer/Consumer.

We could still add methods that take ownership of the grant in the Producer/Consumer, and potentially return the next one.

something like (on the consumer):

let (_producer, mut consumer) = BBQUEUE.try_split().unwrap();

// first grant
let mut grantr = consumer.read().unwrap();
foo(&grantr);

while let Some(grantr) = consumer.commit_and_read(grantr) {
    // read some data...
    foo(&grantr);
}