xref: /nrf52832-nimble/rt-thread/components/vbus/watermark_queue.c (revision 104654410c56c573564690304ae786df310c91fc)
1 /*
2  * COPYRIGHT (C) 2018, Real-Thread Information Technology Ltd
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2014-04-16     Grissiom     first version
9  */
10 
11 #include <rthw.h>
12 #include <rtthread.h>
13 
14 #include "watermark_queue.h"
15 
rt_wm_que_set_mark(struct rt_watermark_queue * wg,unsigned int low,unsigned int high)16 void rt_wm_que_set_mark(struct rt_watermark_queue *wg,
17                              unsigned int low, unsigned int high)
18 {
19     RT_ASSERT(low <= high);
20 
21     wg->high_mark = high;
22     wg->low_mark = low;
23 }
24 
rt_wm_que_init(struct rt_watermark_queue * wg,unsigned int low,unsigned int high)25 void rt_wm_que_init(struct rt_watermark_queue *wg,
26                          unsigned int low, unsigned int high)
27 {
28     rt_wm_que_set_mark(wg, low, high);
29     rt_list_init(&wg->suspended_threads);
30     wg->level = 0;
31 }
32 
rt_wm_que_dump(struct rt_watermark_queue * wg)33 void rt_wm_que_dump(struct rt_watermark_queue *wg)
34 {
35     struct rt_list_node *node;
36 
37     rt_kprintf("wg %p: low: %d, high: %d, cur: %d\n",
38                wg, wg->low_mark, wg->high_mark, wg->level);
39     rt_kprintf("thread suspend:");
40     for (node = wg->suspended_threads.next;
41          node != &wg->suspended_threads;
42          node = node->next)
43     {
44         rt_thread_t thread;
45 
46         thread = rt_list_entry(wg->suspended_threads.next,
47                                struct rt_thread,
48                                tlist);
49         rt_kprintf(" %.*s", RT_NAME_MAX, thread->name);
50     }
51     rt_kprintf("\n");
52 }
53