kwork_signal.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /****************************************************************************
  2. * sched/wqueue/work_signal.c
  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. ****************************************************************************/
  20. /****************************************************************************
  21. * Included Files
  22. ****************************************************************************/
  23. #include <nuttx/config.h>
  24. #include <signal.h>
  25. #include <errno.h>
  26. #include <nuttx/wqueue.h>
  27. #include <nuttx/signal.h>
  28. #include "wqueue/wqueue.h"
  29. #ifdef CONFIG_SCHED_WORKQUEUE
  30. /****************************************************************************
  31. * Public Functions
  32. ****************************************************************************/
  33. /****************************************************************************
  34. * Name: work_signal
  35. *
  36. * Description:
  37. * Signal the worker thread to process the work queue now. This function
  38. * is used internally by the work logic but could also be used by the
  39. * user to force an immediate re-assessment of pending work.
  40. *
  41. * Input Parameters:
  42. * qid - The work queue ID
  43. *
  44. * Returned Value:
  45. * Zero (OK) on success, a negated errno value on failure
  46. *
  47. ****************************************************************************/
  48. int work_signal(int qid)
  49. {
  50. FAR struct kwork_wqueue_s *work;
  51. int threads;
  52. int i;
  53. /* Get the process ID of the worker thread */
  54. #ifdef CONFIG_SCHED_HPWORK
  55. if (qid == HPWORK)
  56. {
  57. work = (FAR struct kwork_wqueue_s *)&g_hpwork;
  58. threads = CONFIG_SCHED_HPNTHREADS;
  59. }
  60. else
  61. #endif
  62. #ifdef CONFIG_SCHED_LPWORK
  63. if (qid == LPWORK)
  64. {
  65. work = (FAR struct kwork_wqueue_s *)&g_lpwork;
  66. threads = CONFIG_SCHED_LPNTHREADS;
  67. }
  68. else
  69. #endif
  70. {
  71. return -EINVAL;
  72. }
  73. /* Find an IDLE worker thread */
  74. for (i = 0; i < threads; i++)
  75. {
  76. /* Is this worker thread busy? */
  77. if (!work->worker[i].busy)
  78. {
  79. /* No.. select this thread */
  80. break;
  81. }
  82. }
  83. /* If all of the IDLE threads are busy, then just return successfully */
  84. if (i >= threads)
  85. {
  86. return OK;
  87. }
  88. /* Otherwise, signal the first IDLE thread found */
  89. return nxsig_kill(work->worker[i].pid, SIGWORK);
  90. }
  91. #endif /* CONFIG_SCHED_WORKQUEUE */