workqueue.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. */
  9. #ifndef WORKQUEUE_H__
  10. #define WORKQUEUE_H__
  11. #include <rtthread.h>
  12. /* workqueue implementation */
  13. struct rt_workqueue
  14. {
  15. rt_list_t work_list;
  16. struct rt_work *work_current; /* current work */
  17. struct rt_semaphore sem;
  18. rt_thread_t work_thread;
  19. };
  20. struct rt_work
  21. {
  22. rt_list_t list;
  23. void (*work_func)(struct rt_work* work, void* work_data);
  24. void *work_data;
  25. };
  26. #ifdef RT_USING_HEAP
  27. /**
  28. * WorkQueue for DeviceDriver
  29. */
  30. struct rt_workqueue *rt_workqueue_create(const char* name, rt_uint16_t stack_size, rt_uint8_t priority);
  31. rt_err_t rt_workqueue_destroy(struct rt_workqueue* queue);
  32. rt_err_t rt_workqueue_dowork(struct rt_workqueue* queue, struct rt_work* work);
  33. rt_err_t rt_workqueue_cancel_work(struct rt_workqueue* queue, struct rt_work* work);
  34. rt_err_t rt_workqueue_cancel_work_sync(struct rt_workqueue* queue, struct rt_work* work);
  35. rt_inline void rt_work_init(struct rt_work* work, void (*work_func)(struct rt_work* work, void* work_data),
  36. void* work_data)
  37. {
  38. rt_list_init(&(work->list));
  39. work->work_func = work_func;
  40. work->work_data = work_data;
  41. }
  42. #endif
  43. #endif