* @brief Create a work queue with a thread inside. * * @param name is a name of the work queue thread. * * @param stack_size is stack size of the work queue thread. * * @param priority is a priority of the work queue thread. * * @return Return a pointer to the workqueue object. It will return RT_NULL if failed. */
| 215 | * @return Return a pointer to the workqueue object. It will return RT_NULL if failed. |
| 216 | */ |
| 217 | struct rt_workqueue *rt_workqueue_create(const char *name, rt_uint16_t stack_size, rt_uint8_t priority) |
| 218 | { |
| 219 | struct rt_workqueue *queue = RT_NULL; |
| 220 | |
| 221 | queue = (struct rt_workqueue *)RT_KERNEL_MALLOC(sizeof(struct rt_workqueue)); |
| 222 | if (queue != RT_NULL) |
| 223 | { |
| 224 | /* initialize work list */ |
| 225 | rt_list_init(&(queue->work_list)); |
| 226 | rt_list_init(&(queue->delayed_list)); |
| 227 | queue->work_current = RT_NULL; |
| 228 | rt_sem_init(&(queue->sem), "wqueue", 0, RT_IPC_FLAG_FIFO); |
| 229 | rt_completion_init(&(queue->wakeup_completion)); |
| 230 | |
| 231 | /* create the work thread */ |
| 232 | queue->work_thread = rt_thread_create(name, _workqueue_thread_entry, queue, stack_size, priority, 10); |
| 233 | if (queue->work_thread == RT_NULL) |
| 234 | { |
| 235 | rt_sem_detach(&(queue->sem)); |
| 236 | RT_KERNEL_FREE(queue); |
| 237 | return RT_NULL; |
| 238 | } |
| 239 | |
| 240 | rt_spin_lock_init(&(queue->spinlock)); |
| 241 | rt_thread_startup(queue->work_thread); |
| 242 | } |
| 243 | |
| 244 | return queue; |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * @brief Destroy a work queue. |
no test coverage detected