Lines Matching refs:fifo
15 int kfifo_alloc(struct kfifo_t *fifo, uint32_t size, uint64_t reserved) in kfifo_alloc() argument
17 memset(fifo, 0, sizeof(struct kfifo_t)); in kfifo_alloc()
18 fifo->buffer = kmalloc(size, 0); in kfifo_alloc()
19 if (fifo->buffer == NULL) in kfifo_alloc()
22 fifo->total_size = size; in kfifo_alloc()
35 void kfifo_init(struct kfifo_t *fifo, void *buffer, uint32_t size) in kfifo_init() argument
37 memset(fifo, 0, sizeof(struct kfifo_t)); in kfifo_init()
39 fifo->buffer = buffer; in kfifo_init()
40 fifo->total_size = size; in kfifo_init()
51 uint32_t kfifo_in(struct kfifo_t *fifo, const void *from, uint32_t size) in kfifo_in() argument
54 if (unlikely(fifo->size + size > fifo->total_size)) in kfifo_in()
60 if (fifo->in_offset + size > fifo->total_size) // 发生回环 in kfifo_in()
62 uint32_t tmp = fifo->total_size - fifo->in_offset; in kfifo_in()
63 memcpy(fifo->buffer + fifo->in_offset, from, tmp); in kfifo_in()
64 memcpy(fifo->buffer, from + tmp, size - tmp); in kfifo_in()
65 fifo->in_offset = size - tmp; in kfifo_in()
69 memcpy(fifo->buffer + fifo->in_offset, from, size); in kfifo_in()
70 fifo->in_offset += size; in kfifo_in()
73 fifo->size += size; in kfifo_in()
86 uint32_t kfifo_out(struct kfifo_t *fifo, void *to, uint32_t size) in kfifo_out() argument
90 if (unlikely(size > fifo->size)) // 判断队列中是否有这么多数据 in kfifo_out()
94 if (fifo->out_offset + size > fifo->total_size) // 发生回环 in kfifo_out()
96 uint32_t tmp = fifo->total_size - fifo->out_offset; in kfifo_out()
97 memcpy(to, fifo->buffer + fifo->out_offset, tmp); in kfifo_out()
98 memcpy(to + tmp, fifo->buffer, size - tmp); in kfifo_out()
99 fifo->out_offset = size - tmp; in kfifo_out()
103 memcpy(to, fifo->buffer + fifo->out_offset, size); in kfifo_out()
104 fifo->out_offset += size; in kfifo_out()
107 fifo->size -= size; in kfifo_out()
120 uint32_t kfifo_out_peek(struct kfifo_t *fifo, void *to, uint32_t size) in kfifo_out_peek() argument
124 if (unlikely(size > fifo->size)) // 判断队列中是否有这么多数据 in kfifo_out_peek()
128 if (fifo->out_offset + size > fifo->total_size) // 发生回环 in kfifo_out_peek()
130 uint32_t tmp = fifo->total_size - fifo->out_offset; in kfifo_out_peek()
131 memcpy(to, fifo->buffer + fifo->out_offset, tmp); in kfifo_out_peek()
132 memcpy(to + tmp, fifo->buffer, size - tmp); in kfifo_out_peek()
136 memcpy(to, fifo->buffer + fifo->out_offset, size); in kfifo_out_peek()
147 void kfifo_free_alloc(struct kfifo_t *fifo) in kfifo_free_alloc() argument
149 kfree(fifo->buffer); in kfifo_free_alloc()
150 memset(fifo, 0, sizeof(struct kfifo_t)); in kfifo_free_alloc()