| 48 | } |
| 49 | |
| 50 | static void _workqueue_thread_entry(void *parameter) |
| 51 | { |
| 52 | rt_base_t level; |
| 53 | struct rt_work *work; |
| 54 | struct rt_workqueue *queue; |
| 55 | rt_tick_t current_tick; |
| 56 | rt_int32_t delay_tick; |
| 57 | void (*work_func)(struct rt_work *work, void *work_data); |
| 58 | void *work_data; |
| 59 | |
| 60 | queue = (struct rt_workqueue *)parameter; |
| 61 | RT_ASSERT(queue != RT_NULL); |
| 62 | |
| 63 | while (1) |
| 64 | { |
| 65 | level = rt_spin_lock_irqsave(&(queue->spinlock)); |
| 66 | |
| 67 | /* timer check */ |
| 68 | current_tick = rt_tick_get(); |
| 69 | delay_tick = RT_WAITING_FOREVER; |
| 70 | while (!rt_list_isempty(&(queue->delayed_list))) |
| 71 | { |
| 72 | work = rt_list_entry(queue->delayed_list.next, struct rt_work, list); |
| 73 | if ((current_tick - work->timeout_tick) < RT_TICK_MAX / 2) |
| 74 | { |
| 75 | rt_list_remove(&(work->list)); |
| 76 | rt_list_insert_after(queue->work_list.prev, &(work->list)); |
| 77 | work->flags &= ~RT_WORK_STATE_SUBMITTING; |
| 78 | work->flags |= RT_WORK_STATE_PENDING; |
| 79 | } |
| 80 | else |
| 81 | { |
| 82 | delay_tick = work->timeout_tick - current_tick; |
| 83 | break; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | if (rt_list_isempty(&(queue->work_list))) |
| 88 | { |
| 89 | rt_spin_unlock_irqrestore(&(queue->spinlock), level); |
| 90 | /* wait for work completion */ |
| 91 | rt_completion_wait(&(queue->wakeup_completion), delay_tick); |
| 92 | continue; |
| 93 | } |
| 94 | |
| 95 | /* we have work to do with. */ |
| 96 | work = rt_list_entry(queue->work_list.next, struct rt_work, list); |
| 97 | rt_list_remove(&(work->list)); |
| 98 | queue->work_current = work; |
| 99 | work->flags &= ~RT_WORK_STATE_PENDING; |
| 100 | work->workqueue = RT_NULL; |
| 101 | work_func = work->work_func; |
| 102 | work_data = work->work_data; |
| 103 | rt_spin_unlock_irqrestore(&(queue->spinlock), level); |
| 104 | |
| 105 | /* do work */ |
| 106 | work_func(work, work_data); |
| 107 | /* clean current work */ |
nothing calls this directly
no test coverage detected