| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- /* Copyright (C) 2021 Rain */
- /* This file is part of XNIX. */
- /*
- XNIX is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) and later version.
- */
- /*
- XNIX is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- */
- /*
- You should have received a copy of the GNU General Public License
- along with XNIX. If not, see <https://www.gnu.org/licenses/>.
- */
- #include <kernel/init.h>
- #include <kernel/types.h>
- #include <kernel/schk.h>
- #include <lib/fifo.h>
- void fifo_init(struct fifo *fifo, __fifo_buf_t *buf, int total) {
- schk_init();
- fifo->buf = buf;
- fifo->total = total;
-
- fifo->next_wr = fifo->next_rd = 0;
- fifo->need_read = 0;
- schk_leave();
- return;
- }
- __fifo_buf_t fifo_get(struct fifo *fifo) {
- schk_init();
- __fifo_buf_t res;
- if (!fifo->need_read)
- return 0;
- fifo->need_read--;
- res = fifo->buf[fifo->next_rd++];
- if (fifo->next_rd == fifo->total)
- fifo->next_rd = 0;
- schk_leave();
- return res;
- }
- void fifo_put(struct fifo *fifo, __fifo_buf_t value) {
- schk_init();
- fifo->buf[fifo->next_wr++] = value;
- fifo->need_read++;
- if (fifo->next_wr == fifo->total)
- fifo->next_wr = 0;
- schk_leave();
- return;
- }
|