Merge pull request #4905 from mysterywolf/rb
[ringbuffer] rt_ringbuffer_data_len采用局部变量承接,防止出现资源竞争
This commit is contained in:
commit
69cd36b5d0
|
@ -335,11 +335,15 @@ rt_size_t rt_ringbuffer_data_len(struct rt_ringbuffer *rb)
|
|||
return rb->buffer_size;
|
||||
case RT_RINGBUFFER_HALFFULL:
|
||||
default:
|
||||
if (rb->write_index > rb->read_index)
|
||||
return rb->write_index - rb->read_index;
|
||||
{
|
||||
rt_size_t wi = rb->write_index, ri = rb->read_index;
|
||||
|
||||
if (wi > ri)
|
||||
return wi - ri;
|
||||
else
|
||||
return rb->buffer_size - (rb->read_index - rb->write_index);
|
||||
};
|
||||
return rb->buffer_size - (ri - wi);
|
||||
}
|
||||
}
|
||||
}
|
||||
RTM_EXPORT(rt_ringbuffer_data_len);
|
||||
|
||||
|
|
Loading…
Reference in New Issue