queue.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. *
  3. * Embedded Linux library
  4. *
  5. * Copyright (C) 2011-2014 Intel Corporation. All rights reserved.
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. */
  22. #ifndef __ELL_QUEUE_H
  23. #define __ELL_QUEUE_H
  24. #include <stdbool.h>
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. typedef void (*l_queue_foreach_func_t) (void *data, void *user_data);
  29. typedef void (*l_queue_destroy_func_t) (void *data);
  30. typedef int (*l_queue_compare_func_t) (const void *a, const void *b,
  31. void *user_data);
  32. typedef bool (*l_queue_match_func_t) (const void *a, const void *b);
  33. typedef bool (*l_queue_remove_func_t) (void *data, void *user_data);
  34. struct l_queue;
  35. struct l_queue_entry {
  36. void *data;
  37. struct l_queue_entry *next;
  38. };
  39. struct l_queue *l_queue_new(void);
  40. void l_queue_destroy(struct l_queue *queue,
  41. l_queue_destroy_func_t destroy);
  42. void l_queue_clear(struct l_queue *queue,
  43. l_queue_destroy_func_t destroy);
  44. bool l_queue_push_tail(struct l_queue *queue, void *data);
  45. bool l_queue_push_head(struct l_queue *queue, void *data);
  46. void *l_queue_pop_head(struct l_queue *queue);
  47. void *l_queue_peek_head(struct l_queue *queue);
  48. void *l_queue_peek_tail(struct l_queue *queue);
  49. bool l_queue_insert(struct l_queue *queue, void *data,
  50. l_queue_compare_func_t function, void *user_data);
  51. void *l_queue_find(struct l_queue *queue,
  52. l_queue_match_func_t function, const void *user_data);
  53. bool l_queue_remove(struct l_queue *queue, void *data);
  54. void *l_queue_remove_if(struct l_queue *queue,
  55. l_queue_match_func_t function, const void *user_data);
  56. bool l_queue_reverse(struct l_queue *queue);
  57. void l_queue_foreach(struct l_queue *queue,
  58. l_queue_foreach_func_t function, void *user_data);
  59. unsigned int l_queue_foreach_remove(struct l_queue *queue,
  60. l_queue_remove_func_t function, void *user_data);
  61. unsigned int l_queue_length(struct l_queue *queue);
  62. bool l_queue_isempty(struct l_queue *queue);
  63. const struct l_queue_entry *l_queue_get_entries(const struct l_queue *queue);
  64. #ifdef __cplusplus
  65. }
  66. #endif
  67. #endif /* __ELL_QUEUE_H */