mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-01-18 14:53:32 +08:00
[ringbuffer] 采用局部变量,防止出现资源竞争
This commit is contained in:
parent
d57caa7e15
commit
619fa4d9d8
@ -333,11 +333,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…
x
Reference in New Issue
Block a user