kandi X-RAY | kfifo Summary
kandi X-RAY | kfifo Summary
内核的kfifo
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of kfifo
kfifo Key Features
kfifo Examples and Code Snippets
Community Discussions
Trending Discussions on kfifo
QUESTION
Does kfifo is Circlar queue?
In Circlar queue WIKI (https://en.wikipedia.org/wiki/Circular_buffer) said "it were connected end-to-end.". but in linux-4.16.12\lib\kfifo.c
...ANSWER
Answered 2018-Nov-27 at 11:24The Wikipedia page you mentioned states that a circular buffer behaves as if the buffer was connected end to end. In practice, circular buffer is simply an array of a certain fixed length, with two index pointers (usually called head
and tail
, or in
and out
) representing the "boundaries" of the written data. To avoid writing outside the buffer bounds, all arithmetic operations on these indices are done modulo length of the buffer.
Usually, the meaning of the pointers is:
head
orin
index, indicates the next available slot for writing, andtail
orout
index, indicates the last read ("removed") slot.
There are also two boundary states:
- if
tail
is equal tohead
, then the buffer is empty. - if incrementing the
tail
modulo buffer length would maketail
andhead
equal, then the buffer is full.
Most implementations will keep the indices within the buffer bounds using one of these approaches:
QUESTION
In kfifo.h kfifo_get calls kfifo_is_empty which checks if __kfifo->in == __kfifo_out. Meanwhile kfifo_put does __kfifo->in++ after adding data. Since this is a lockless implementation of circular buffer with 1 reader and writer what prevents the writer from corrupting the data while kfifo_is_empty is reading the value of __kfifo->in?
...ANSWER
Answered 2017-Sep-29 at 08:20There is no problem here.
In short, the reader may see in
not equal to out
only after data has been transferred into the kfifo. This is achived by executing barrier before incrementing in
counter at the writer side.
QUESTION
I am writing a patch to bcache Linux module and struggle to find generic LIFO implementation in Linux core. I have found several FIFO implementations both on defines and without. However, nothing alike for LIFO.
Where can one find one? Preferably C not asm and not based on defines, but any should work.
If no abstract LIFO is provided, what are the easiest structures to implement LIFO on (generic stack realization in Linux core for instance)?
...ANSWER
Answered 2017-Apr-08 at 16:37If the LIFO has fixed maximum depth, and is not dynamically allocated, then it is simply something like
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install kfifo
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page