watermark_queue.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Water Gauge
  3. *
  4. * COPYRIGHT (C) 2014-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. * 2014-04-16 Grissiom first version
  28. */
  29. #include <rthw.h>
  30. #include <rtthread.h>
  31. #include "watermark_queue.h"
  32. void rt_wm_que_set_mark(struct rt_watermark_queue *wg,
  33. unsigned int low, unsigned int high)
  34. {
  35. RT_ASSERT(low <= high);
  36. wg->high_mark = high;
  37. wg->low_mark = low;
  38. }
  39. void rt_wm_que_init(struct rt_watermark_queue *wg,
  40. unsigned int low, unsigned int high)
  41. {
  42. rt_wm_que_set_mark(wg, low, high);
  43. rt_list_init(&wg->suspended_threads);
  44. wg->level = 0;
  45. }
  46. void rt_wm_que_dump(struct rt_watermark_queue *wg)
  47. {
  48. struct rt_list_node *node;
  49. rt_kprintf("wg %p: low: %d, high: %d, cur: %d\n",
  50. wg, wg->low_mark, wg->high_mark, wg->level);
  51. rt_kprintf("thread suspend:");
  52. for (node = wg->suspended_threads.next;
  53. node != &wg->suspended_threads;
  54. node = node->next)
  55. {
  56. rt_thread_t thread;
  57. thread = rt_list_entry(wg->suspended_threads.next,
  58. struct rt_thread,
  59. tlist);
  60. rt_kprintf(" %.*s", RT_NAME_MAX, thread->name);
  61. }
  62. rt_kprintf("\n");
  63. }