prio_queue.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Priority Queue
  3. *
  4. * COPYRIGHT (C) 2013-2015, Shanghai Real-Thread Technology Co., Ltd
  5. * http://www.rt-thread.com
  6. *
  7. * This file is part of RT-Thread (http://www.rt-thread.org)
  8. *
  9. * All rights reserved.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License along
  22. * with this program; if not, write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  24. *
  25. * Change Logs:
  26. * Date Author Notes
  27. * 2013-11-04 Grissiom add comment
  28. */
  29. #ifndef __PRIO_QUEUE_H__
  30. #define __PRIO_QUEUE_H__
  31. #include <rtthread.h>
  32. #define RT_PRIO_QUEUE_PRIO_MAX 32
  33. struct rt_prio_queue_item;
  34. struct rt_prio_queue {
  35. rt_uint32_t bitmap;
  36. struct rt_prio_queue_item *head[RT_PRIO_QUEUE_PRIO_MAX];
  37. struct rt_prio_queue_item *tail[RT_PRIO_QUEUE_PRIO_MAX];
  38. /* push thread suspend on the mempool, not queue */
  39. rt_list_t suspended_pop_list;
  40. rt_size_t item_sz;
  41. struct rt_mempool pool;
  42. };
  43. rt_err_t rt_prio_queue_init(struct rt_prio_queue *que,
  44. const char *name,
  45. void *buf,
  46. rt_size_t bufsz,
  47. rt_size_t itemsz);
  48. void rt_prio_queue_detach(struct rt_prio_queue *que);
  49. rt_err_t rt_prio_queue_push(struct rt_prio_queue *que,
  50. rt_uint8_t prio,
  51. void *data,
  52. rt_int32_t timeout);
  53. rt_err_t rt_prio_queue_pop(struct rt_prio_queue *que,
  54. void *data,
  55. rt_int32_t timeout);
  56. #ifdef RT_USING_HEAP
  57. struct rt_prio_queue* rt_prio_queue_create(const char *name,
  58. rt_size_t item_nr,
  59. rt_size_t item_sz);
  60. void rt_prio_queue_delete(struct rt_prio_queue *que);
  61. #endif
  62. void rt_prio_queue_dump(struct rt_prio_queue *que);
  63. #endif /* end of include guard: __PRIO_QUEUE_H__ */