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. */
| 39 | * is zero and the level is above water mark. -RT_ETIMEOUT if timeout occurred. |
| 40 | */ |
| 41 | rt_inline rt_err_t rt_wm_que_inc(struct rt_watermark_queue *wg, |
| 42 | int timeout) |
| 43 | { |
| 44 | rt_base_t level; |
| 45 | |
| 46 | /* Assert as early as possible. */ |
| 47 | if (timeout != 0) |
| 48 | { |
| 49 | RT_DEBUG_IN_THREAD_CONTEXT; |
| 50 | } |
| 51 | |
| 52 | level = rt_hw_interrupt_disable(); |
| 53 | |
| 54 | while (wg->level > wg->high_mark) |
| 55 | { |
| 56 | rt_thread_t thread; |
| 57 | |
| 58 | if (timeout == 0) |
| 59 | { |
| 60 | rt_hw_interrupt_enable(level); |
| 61 | return -RT_EFULL; |
| 62 | } |
| 63 | |
| 64 | thread = rt_thread_self(); |
| 65 | thread->error = RT_EOK; |
| 66 | rt_thread_suspend(thread); |
| 67 | rt_list_insert_after(&wg->suspended_threads, &RT_THREAD_LIST_NODE(thread)); |
| 68 | if (timeout > 0) |
| 69 | { |
| 70 | rt_tick_t timeout_tick = timeout; |
| 71 | rt_timer_control(&(thread->thread_timer), |
| 72 | RT_TIMER_CTRL_SET_TIME, |
| 73 | &timeout_tick); |
| 74 | rt_timer_start(&(thread->thread_timer)); |
| 75 | } |
| 76 | rt_hw_interrupt_enable(level); |
| 77 | rt_schedule(); |
| 78 | if (thread->error != RT_EOK) |
| 79 | return thread->error; |
| 80 | |
| 81 | level = rt_hw_interrupt_disable(); |
| 82 | } |
| 83 | |
| 84 | wg->level++; |
| 85 | |
| 86 | if (wg->level == 0) |
| 87 | { |
| 88 | wg->level = ~0; |
| 89 | } |
| 90 | |
| 91 | rt_hw_interrupt_enable(level); |
| 92 | |
| 93 | return RT_EOK; |
| 94 | } |
| 95 | |
| 96 | /** Decrease the water level. |
| 97 | * |
no test coverage detected