jamesmunns / bbqueue

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`grant_max` does not reserve the largest contiguous buffer available

jonas-schievink opened this issue · comments

This might just be a documentation issue, but I was assuming that grant_max should behave identically to grant wrt. the successful case. An example:

use bbqueue::*;

fn main() {
    let bbq = bbq!(1000).unwrap();

    let size = 999;
    let grant = bbq.grant(size).unwrap();
    bbq.commit(size, grant);
    let grant = bbq.read().unwrap();
    bbq.release(size, grant);

    let grant = bbq.grant_max(500).unwrap();
    println!("{}", grant.len());
    bbq.commit(0, grant);
}

This consumes and then frees all but 1 Byte of the queue. Then it tries to obtain a 500-byte grant using grant_max. I would expect this to succeed and return the requested 500-byte grant, since there's a large 999-byte area that's still free. Instead it returns a grant of length 1.

Using grant instead will successfully grant 500 bytes.

The docs have been updated in #37, and work on new grant types is tracked in #38.