wqueue.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /****************************************************************************
  2. * sched/wqueue/wqueue.h
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. ****************************************************************************/
  19. #ifndef __SCHED_WQUEUE_WQUEUE_H
  20. #define __SCHED_WQUEUE_WQUEUE_H
  21. /****************************************************************************
  22. * Included Files
  23. ****************************************************************************/
  24. #include <nuttx/config.h>
  25. #include <sys/types.h>
  26. #include <stdbool.h>
  27. #include <queue.h>
  28. #include <nuttx/clock.h>
  29. #ifdef CONFIG_SCHED_WORKQUEUE
  30. /****************************************************************************
  31. * Pre-processor Definitions
  32. ****************************************************************************/
  33. /* Kernel thread names */
  34. #define HPWORKNAME "hpwork"
  35. #define LPWORKNAME "lpwork"
  36. /****************************************************************************
  37. * Public Type Definitions
  38. ****************************************************************************/
  39. /* This represents one worker */
  40. struct kworker_s
  41. {
  42. pid_t pid; /* The task ID of the worker thread */
  43. volatile bool busy; /* True: Worker is not available */
  44. };
  45. /* This structure defines the state of one kernel-mode work queue */
  46. struct kwork_wqueue_s
  47. {
  48. struct dq_queue_s q; /* The queue of pending work */
  49. struct kworker_s worker[1]; /* Describes a worker thread */
  50. };
  51. /* This structure defines the state of one high-priority work queue. This
  52. * structure must be cast-compatible with kwork_wqueue_s.
  53. */
  54. #ifdef CONFIG_SCHED_HPWORK
  55. struct hp_wqueue_s
  56. {
  57. struct dq_queue_s q; /* The queue of pending work */
  58. /* Describes each thread in the high priority queue's thread pool */
  59. struct kworker_s worker[CONFIG_SCHED_HPNTHREADS];
  60. };
  61. #endif
  62. /* This structure defines the state of one low-priority work queue. This
  63. * structure must be cast compatible with kwork_wqueue_s
  64. */
  65. #ifdef CONFIG_SCHED_LPWORK
  66. struct lp_wqueue_s
  67. {
  68. struct dq_queue_s q; /* The queue of pending work */
  69. /* Describes each thread in the low priority queue's thread pool */
  70. struct kworker_s worker[CONFIG_SCHED_LPNTHREADS];
  71. };
  72. #endif
  73. /****************************************************************************
  74. * Public Data
  75. ****************************************************************************/
  76. #ifdef CONFIG_SCHED_HPWORK
  77. /* The state of the kernel mode, high priority work queue. */
  78. extern struct hp_wqueue_s g_hpwork;
  79. #endif
  80. #ifdef CONFIG_SCHED_LPWORK
  81. /* The state of the kernel mode, low priority work queue(s). */
  82. extern struct lp_wqueue_s g_lpwork;
  83. #endif
  84. /****************************************************************************
  85. * Public Function Prototypes
  86. ****************************************************************************/
  87. /****************************************************************************
  88. * Name: work_start_highpri
  89. *
  90. * Description:
  91. * Start the high-priority, kernel-mode work queue.
  92. *
  93. * Input Parameters:
  94. * None
  95. *
  96. * Returned Value:
  97. * The task ID of the worker thread is returned on success. A negated
  98. * errno value is returned on failure.
  99. *
  100. ****************************************************************************/
  101. #ifdef CONFIG_SCHED_HPWORK
  102. int work_start_highpri(void);
  103. #endif
  104. /****************************************************************************
  105. * Name: work_start_lowpri
  106. *
  107. * Description:
  108. * Start the low-priority, kernel-mode worker thread(s)
  109. *
  110. * Input Parameters:
  111. * None
  112. *
  113. * Returned Value:
  114. * The task ID of the worker thread is returned on success. A negated
  115. * errno value is returned on failure.
  116. *
  117. ****************************************************************************/
  118. #ifdef CONFIG_SCHED_LPWORK
  119. int work_start_lowpri(void);
  120. #endif
  121. /****************************************************************************
  122. * Name: work_process
  123. *
  124. * Description:
  125. * This is the logic that performs actions placed on any work list. This
  126. * logic is the common underlying logic to all work queues. This logic is
  127. * part of the internal implementation of each work queue; it should not
  128. * be called from application level logic.
  129. *
  130. * Input Parameters:
  131. * wqueue - Describes the work queue to be processed
  132. * wndx - The worker thread index
  133. *
  134. * Returned Value:
  135. * None
  136. *
  137. ****************************************************************************/
  138. void work_process(FAR struct kwork_wqueue_s *wqueue, int wndx);
  139. /****************************************************************************
  140. * Name: work_initialize_notifier
  141. *
  142. * Description:
  143. * Set up the notification data structures for normal operation.
  144. *
  145. ****************************************************************************/
  146. #ifdef CONFIG_WQUEUE_NOTIFIER
  147. void work_initialize_notifier(void);
  148. #endif
  149. #endif /* CONFIG_SCHED_WORKQUEUE */
  150. #endif /* __SCHED_WQUEUE_WQUEUE_H */