aio_queue.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /****************************************************************************
  2. * fs/aio/aio_queue.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 <sched.h>
  25. #include <aio.h>
  26. #include <errno.h>
  27. #include <debug.h>
  28. #include <nuttx/wqueue.h>
  29. #include "aio/aio.h"
  30. #ifdef CONFIG_FS_AIO
  31. /****************************************************************************
  32. * Private Functions
  33. ****************************************************************************/
  34. /****************************************************************************
  35. * Name: aio_queue
  36. *
  37. * Description:
  38. * Schedule the asynchronous I/O on the low priority work queue
  39. *
  40. * Input Parameters:
  41. * arg - Worker argument. In this case, a pointer to an instance of
  42. * struct aiocb cast to void *.
  43. *
  44. * Returned Value:
  45. * Zero (OK) on success. Otherwise, -1 is returned and the errno is set
  46. * appropriately.
  47. *
  48. ****************************************************************************/
  49. int aio_queue(FAR struct aio_container_s *aioc, worker_t worker)
  50. {
  51. int ret;
  52. #ifdef CONFIG_PRIORITY_INHERITANCE
  53. /* Prohibit context switches until we complete the queuing */
  54. sched_lock();
  55. /* Make sure that the low-priority worker thread is running at at least
  56. * the priority specified for this action.
  57. */
  58. lpwork_boostpriority(aioc->aioc_prio);
  59. #endif
  60. /* Schedule the work on the low priority worker thread */
  61. ret = work_queue(LPWORK, &aioc->aioc_work, worker, aioc, 0);
  62. if (ret < 0)
  63. {
  64. FAR struct aiocb *aiocbp = aioc->aioc_aiocbp;
  65. DEBUGASSERT(aiocbp);
  66. #ifdef CONFIG_PRIORITY_INHERITANCE
  67. lpwork_restorepriority(aioc->aioc_prio);
  68. #endif
  69. aiocbp->aio_result = ret;
  70. set_errno(-ret);
  71. ret = ERROR;
  72. }
  73. #ifdef CONFIG_PRIORITY_INHERITANCE
  74. /* Now the low-priority work queue might run at its new priority */
  75. sched_unlock();
  76. #endif
  77. return ret;
  78. }
  79. #endif /* CONFIG_FS_AIO */