fifo.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* FIFO common header.
  2. Copyright (C) 2015 Kunihiro Ishiguro
  3. This file is part of Quagga.
  4. Quagga is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by the
  6. Free Software Foundation; either version 2, or (at your option) any
  7. later version.
  8. Quagga is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Zebra; see the file COPYING. If not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. 02111-1307, USA. */
  16. #ifndef __LIB_FIFO_H__
  17. #define __LIB_FIFO_H__
  18. /* FIFO -- first in first out structure and macros. */
  19. struct fifo
  20. {
  21. struct fifo *next;
  22. struct fifo *prev;
  23. u_int32_t count;
  24. };
  25. #define FIFO_INIT(F) \
  26. do { \
  27. struct fifo *Xfifo = (struct fifo *)(F); \
  28. Xfifo->next = Xfifo->prev = Xfifo; \
  29. } while (0)
  30. #define FIFO_ADD(F,N) \
  31. do { \
  32. struct fifo *Xfifo = (struct fifo *)(F); \
  33. struct fifo *Xnode = (struct fifo *)(N); \
  34. Xnode->next = Xfifo; \
  35. Xnode->prev = Xfifo->prev; \
  36. Xfifo->prev = Xfifo->prev->next = Xnode; \
  37. } while (0)
  38. #define FIFO_DEL(N) \
  39. do { \
  40. struct fifo *Xnode = (struct fifo *)(N); \
  41. Xnode->prev->next = Xnode->next; \
  42. Xnode->next->prev = Xnode->prev; \
  43. } while (0)
  44. #define FIFO_HEAD(F) \
  45. ((((struct fifo *)(F))->next == (struct fifo *)(F)) \
  46. ? NULL : (F)->next)
  47. #define FIFO_EMPTY(F) \
  48. (((struct fifo *)(F))->next == (struct fifo *)(F))
  49. #define FIFO_TOP(F) \
  50. (FIFO_EMPTY(F) ? NULL : ((struct fifo *)(F))->next)
  51. #endif /* __LIB_FIFO_H__ */