From d7fb5d54441d556052564fe92277662d263ee28a Mon Sep 17 00:00:00 2001 From: Grissiom Date: Fri, 9 Jan 2015 10:11:32 +0800 Subject: vbus: remove the rt_ prefix in the watermark queue source file --- components/vbus/rt_watermark_queue.c | 71 ----------------- components/vbus/rt_watermark_queue.h | 149 ----------------------------------- components/vbus/vbus.c | 2 +- components/vbus/watermark_queue.c | 71 +++++++++++++++++ components/vbus/watermark_queue.h | 149 +++++++++++++++++++++++++++++++++++ 5 files changed, 221 insertions(+), 221 deletions(-) delete mode 100644 components/vbus/rt_watermark_queue.c delete mode 100644 components/vbus/rt_watermark_queue.h create mode 100644 components/vbus/watermark_queue.c create mode 100644 components/vbus/watermark_queue.h diff --git a/components/vbus/rt_watermark_queue.c b/components/vbus/rt_watermark_queue.c deleted file mode 100644 index 329e9f331c..0000000000 --- a/components/vbus/rt_watermark_queue.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Water Gauge - * - * COPYRIGHT (C) 2014-2015, Shanghai Real-Thread Technology Co., Ltd - * http://www.rt-thread.com - * - * This file is part of RT-Thread (http://www.rt-thread.org) - * - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Change Logs: - * Date Author Notes - * 2014-04-16 Grissiom first version - */ - -#include -#include - -#include "rt_watermark_queue.h" - -void rt_wm_que_set_mark(struct rt_watermark_queue *wg, - unsigned int low, unsigned int high) -{ - RT_ASSERT(low <= high); - - wg->high_mark = high; - wg->low_mark = low; -} - -void rt_wm_que_init(struct rt_watermark_queue *wg, - unsigned int low, unsigned int high) -{ - rt_wm_que_set_mark(wg, low, high); - rt_list_init(&wg->suspended_threads); - wg->level = 0; -} - -void rt_wm_que_dump(struct rt_watermark_queue *wg) -{ - struct rt_list_node *node; - - rt_kprintf("wg %p: low: %d, high: %d, cur: %d\n", - wg, wg->low_mark, wg->high_mark, wg->level); - rt_kprintf("thread suspend:"); - for (node = wg->suspended_threads.next; - node != &wg->suspended_threads; - node = node->next) - { - rt_thread_t thread; - - thread = rt_list_entry(wg->suspended_threads.next, - struct rt_thread, - tlist); - rt_kprintf(" %.*s", RT_NAME_MAX, thread->name); - } - rt_kprintf("\n"); -} diff --git a/components/vbus/rt_watermark_queue.h b/components/vbus/rt_watermark_queue.h deleted file mode 100644 index 1fd51e07c2..0000000000 --- a/components/vbus/rt_watermark_queue.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Thread queue with water mark - * - * COPYRIGHT (C) 2014-2015, Shanghai Real-Thread Technology Co., Ltd - * http://www.rt-thread.com - * - * This file is part of RT-Thread (http://www.rt-thread.org) - * - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Change Logs: - * Date Author Notes - * 2014-04-16 Grissiom first version - */ - -struct rt_watermark_queue -{ - /* Current water level. */ - unsigned int level; - unsigned int high_mark; - unsigned int low_mark; - rt_list_t suspended_threads; -}; - -/** Init the struct rt_watermark_queue. - */ -void rt_wm_que_init(struct rt_watermark_queue *wg, - unsigned int low, unsigned int high); -void rt_wm_que_set_mark(struct rt_watermark_queue *wg, - unsigned int low, unsigned int high); -void rt_wm_que_dump(struct rt_watermark_queue *wg); - -/* Water marks are often used in performance critical places. Benchmark shows - * inlining functions will have 10% performance gain in some situation(for - * example, VBus). So keep the inc/dec compact and inline. */ - -/** Increase the water level. - * - * It should be called in the thread that want to raise the water level. If the - * current level is above the high mark, the thread will be suspended up to - * @timeout ticks. - * - * @return RT_EOK if water level increased successfully. -RT_EFULL on @timeout - * is zero and the level is above water mark. -RT_ETIMEOUT if timeout occurred. - */ -rt_inline rt_err_t rt_wm_que_inc(struct rt_watermark_queue *wg, - int timeout) -{ - rt_base_t ilvl; - - /* Assert as early as possible. */ - if (timeout != 0) - { - RT_DEBUG_IN_THREAD_CONTEXT; - } - - ilvl = rt_hw_interrupt_disable(); - - while (wg->level > wg->high_mark) - { - rt_thread_t thread; - - if (timeout == 0) - { - rt_hw_interrupt_enable(ilvl); - return -RT_EFULL; - } - - thread = rt_thread_self(); - thread->error = RT_EOK; - rt_thread_suspend(thread); - rt_list_insert_after(&wg->suspended_threads, &thread->tlist); - if (timeout > 0) - { - rt_timer_control(&(thread->thread_timer), - RT_TIMER_CTRL_SET_TIME, - &timeout); - rt_timer_start(&(thread->thread_timer)); - } - rt_hw_interrupt_enable(ilvl); - rt_schedule(); - if (thread->error != RT_EOK) - return thread->error; - - ilvl = rt_hw_interrupt_disable(); - } - - wg->level++; - - if (wg->level == 0) - { - wg->level = ~0; - } - - rt_hw_interrupt_enable(ilvl); - - return RT_EOK; -} - -/** Decrease the water level. - * - * It should be called by the consumer that drain the water out. If the water - * level reached low mark, all the thread suspended in this queue will be waken - * up. It's safe to call this function in interrupt context. - */ -rt_inline void rt_wm_que_dec(struct rt_watermark_queue *wg) -{ - int need_sched = 0; - rt_base_t ilvl; - - if (wg->level == 0) - return; - - ilvl = rt_hw_interrupt_disable(); - wg->level--; - if (wg->level == wg->low_mark) - { - /* There should be spaces between the low mark and high mark, so it's - * safe to resume all the threads. */ - while (!rt_list_isempty(&wg->suspended_threads)) - { - rt_thread_t thread; - - thread = rt_list_entry(wg->suspended_threads.next, - struct rt_thread, - tlist); - rt_thread_resume(thread); - need_sched = 1; - } - } - rt_hw_interrupt_enable(ilvl); - - if (need_sched) - rt_schedule(); -} diff --git a/components/vbus/vbus.c b/components/vbus/vbus.c index 7005e52513..4ff4f05f37 100644 --- a/components/vbus/vbus.c +++ b/components/vbus/vbus.c @@ -162,7 +162,7 @@ rt_inline int _chn_connected(unsigned char chnr) } #ifdef RT_VBUS_USING_FLOW_CONTROL -#include +#include struct rt_watermark_queue _chn_wm_que[RT_VBUS_CHANNEL_NR]; void rt_vbus_set_post_wm(unsigned char chnr, unsigned int low, unsigned int high) { diff --git a/components/vbus/watermark_queue.c b/components/vbus/watermark_queue.c new file mode 100644 index 0000000000..9a55d402d9 --- /dev/null +++ b/components/vbus/watermark_queue.c @@ -0,0 +1,71 @@ +/* + * Water Gauge + * + * COPYRIGHT (C) 2014-2015, Shanghai Real-Thread Technology Co., Ltd + * http://www.rt-thread.com + * + * This file is part of RT-Thread (http://www.rt-thread.org) + * + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Change Logs: + * Date Author Notes + * 2014-04-16 Grissiom first version + */ + +#include +#include + +#include "watermark_queue.h" + +void rt_wm_que_set_mark(struct rt_watermark_queue *wg, + unsigned int low, unsigned int high) +{ + RT_ASSERT(low <= high); + + wg->high_mark = high; + wg->low_mark = low; +} + +void rt_wm_que_init(struct rt_watermark_queue *wg, + unsigned int low, unsigned int high) +{ + rt_wm_que_set_mark(wg, low, high); + rt_list_init(&wg->suspended_threads); + wg->level = 0; +} + +void rt_wm_que_dump(struct rt_watermark_queue *wg) +{ + struct rt_list_node *node; + + rt_kprintf("wg %p: low: %d, high: %d, cur: %d\n", + wg, wg->low_mark, wg->high_mark, wg->level); + rt_kprintf("thread suspend:"); + for (node = wg->suspended_threads.next; + node != &wg->suspended_threads; + node = node->next) + { + rt_thread_t thread; + + thread = rt_list_entry(wg->suspended_threads.next, + struct rt_thread, + tlist); + rt_kprintf(" %.*s", RT_NAME_MAX, thread->name); + } + rt_kprintf("\n"); +} diff --git a/components/vbus/watermark_queue.h b/components/vbus/watermark_queue.h new file mode 100644 index 0000000000..1fd51e07c2 --- /dev/null +++ b/components/vbus/watermark_queue.h @@ -0,0 +1,149 @@ +/* + * Thread queue with water mark + * + * COPYRIGHT (C) 2014-2015, Shanghai Real-Thread Technology Co., Ltd + * http://www.rt-thread.com + * + * This file is part of RT-Thread (http://www.rt-thread.org) + * + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Change Logs: + * Date Author Notes + * 2014-04-16 Grissiom first version + */ + +struct rt_watermark_queue +{ + /* Current water level. */ + unsigned int level; + unsigned int high_mark; + unsigned int low_mark; + rt_list_t suspended_threads; +}; + +/** Init the struct rt_watermark_queue. + */ +void rt_wm_que_init(struct rt_watermark_queue *wg, + unsigned int low, unsigned int high); +void rt_wm_que_set_mark(struct rt_watermark_queue *wg, + unsigned int low, unsigned int high); +void rt_wm_que_dump(struct rt_watermark_queue *wg); + +/* Water marks are often used in performance critical places. Benchmark shows + * inlining functions will have 10% performance gain in some situation(for + * example, VBus). So keep the inc/dec compact and inline. */ + +/** Increase the water level. + * + * It should be called in the thread that want to raise the water level. If the + * current level is above the high mark, the thread will be suspended up to + * @timeout ticks. + * + * @return RT_EOK if water level increased successfully. -RT_EFULL on @timeout + * is zero and the level is above water mark. -RT_ETIMEOUT if timeout occurred. + */ +rt_inline rt_err_t rt_wm_que_inc(struct rt_watermark_queue *wg, + int timeout) +{ + rt_base_t ilvl; + + /* Assert as early as possible. */ + if (timeout != 0) + { + RT_DEBUG_IN_THREAD_CONTEXT; + } + + ilvl = rt_hw_interrupt_disable(); + + while (wg->level > wg->high_mark) + { + rt_thread_t thread; + + if (timeout == 0) + { + rt_hw_interrupt_enable(ilvl); + return -RT_EFULL; + } + + thread = rt_thread_self(); + thread->error = RT_EOK; + rt_thread_suspend(thread); + rt_list_insert_after(&wg->suspended_threads, &thread->tlist); + if (timeout > 0) + { + rt_timer_control(&(thread->thread_timer), + RT_TIMER_CTRL_SET_TIME, + &timeout); + rt_timer_start(&(thread->thread_timer)); + } + rt_hw_interrupt_enable(ilvl); + rt_schedule(); + if (thread->error != RT_EOK) + return thread->error; + + ilvl = rt_hw_interrupt_disable(); + } + + wg->level++; + + if (wg->level == 0) + { + wg->level = ~0; + } + + rt_hw_interrupt_enable(ilvl); + + return RT_EOK; +} + +/** Decrease the water level. + * + * It should be called by the consumer that drain the water out. If the water + * level reached low mark, all the thread suspended in this queue will be waken + * up. It's safe to call this function in interrupt context. + */ +rt_inline void rt_wm_que_dec(struct rt_watermark_queue *wg) +{ + int need_sched = 0; + rt_base_t ilvl; + + if (wg->level == 0) + return; + + ilvl = rt_hw_interrupt_disable(); + wg->level--; + if (wg->level == wg->low_mark) + { + /* There should be spaces between the low mark and high mark, so it's + * safe to resume all the threads. */ + while (!rt_list_isempty(&wg->suspended_threads)) + { + rt_thread_t thread; + + thread = rt_list_entry(wg->suspended_threads.next, + struct rt_thread, + tlist); + rt_thread_resume(thread); + need_sched = 1; + } + } + rt_hw_interrupt_enable(ilvl); + + if (need_sched) + rt_schedule(); +} -- cgit v1.3.1