jamesmunns / bbqueue

A SPSC, lockless, no_std, thread safe, queue, based on BipBuffers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add commit_and_grant convenience methods

jamesmunns opened this issue · comments

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.

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);
}