aio_signal.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /****************************************************************************
  2. * fs/aio/aio_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 <sys/types.h>
  25. #include <sched.h>
  26. #include <signal.h>
  27. #include <aio.h>
  28. #include <assert.h>
  29. #include <errno.h>
  30. #include <debug.h>
  31. #include <nuttx/signal.h>
  32. #include "aio/aio.h"
  33. #ifdef CONFIG_FS_AIO
  34. /****************************************************************************
  35. * Public Functions
  36. ****************************************************************************/
  37. /****************************************************************************
  38. * Name: aio_signal
  39. *
  40. * Description:
  41. * Signal the client that an I/O has completed.
  42. *
  43. * Input Parameters:
  44. * pid - ID of the task to signal
  45. * aiocbp - Pointer to the asynchronous I/O state structure that includes
  46. * information about how to signal the client
  47. *
  48. * Returned Value:
  49. * Zero (OK) if the client was successfully signalled. Otherwise, a
  50. * negated errno value is returned.
  51. *
  52. * Assumptions:
  53. * This function runs only in the context of the worker thread.
  54. *
  55. ****************************************************************************/
  56. int aio_signal(pid_t pid, FAR struct aiocb *aiocbp)
  57. {
  58. union sigval value;
  59. int status;
  60. int ret;
  61. DEBUGASSERT(aiocbp);
  62. ret = OK; /* Assume success */
  63. /* Signal the client */
  64. ret = nxsig_notification(pid, &aiocbp->aio_sigevent,
  65. SI_ASYNCIO, &aiocbp->aio_sigwork);
  66. if (ret < 0)
  67. {
  68. ferr("ERROR: nxsig_notification failed: %d\n", ret);
  69. }
  70. /* Send the poll signal in any event in case the caller is waiting
  71. * on sig_suspend();
  72. */
  73. value.sival_ptr = aiocbp;
  74. status = nxsig_queue(pid, SIGPOLL, value);
  75. if (status < 0)
  76. {
  77. ferr("ERROR: nxsig_queue #2 failed: %d\n", status);
  78. if (ret >= OK)
  79. {
  80. ret = status;
  81. }
  82. }
  83. /* Make sure that errno is set correctly on return */
  84. if (ret < 0)
  85. {
  86. set_errno(-ret);
  87. return ERROR;
  88. }
  89. return OK;
  90. }
  91. #endif /* CONFIG_FS_AIO */