cancelpt.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /****************************************************************************
  2. * include/nuttx/cancelpt.h
  3. * Definitions related to cancellation points
  4. *
  5. * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved.
  6. * Author: Gregory Nutt <gnutt@nuttx.org>
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. * 3. Neither the name NuttX nor the names of its contributors may be
  19. * used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  29. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  30. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  32. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ****************************************************************************/
  36. #ifndef __INCLUDE_NUTTX_CANCELPT_H
  37. #define __INCLUDE_NUTTX_CANCELPT_H
  38. /****************************************************************************
  39. * Cancellation Points.
  40. *
  41. * Cancellation points shall occur when a thread is executing the following
  42. * functions:
  43. *
  44. * accept() mq_timedsend() putpmsg() sigtimedwait()
  45. * aio_suspend() msgrcv() pwrite() sigwait()
  46. * clock_nanosleep() msgsnd() read() sigwaitinfo()
  47. * close() msync() readv() sleep()
  48. * connect() nanosleep() recv() system()
  49. * creat() open() recvfrom() tcdrain()
  50. * fcntl() pause() recvmsg() usleep()
  51. * fdatasync() poll() select() wait()
  52. * fsync() pread() sem_timedwait() waitid()
  53. * getmsg() pselect() sem_wait() waitpid()
  54. * getpmsg() pthread_cond_timedwait() send() write()
  55. * lockf() pthread_cond_wait() sendmsg() writev()
  56. * mq_receive() pthread_join() sendto()
  57. * mq_send() pthread_testcancel() sigpause()
  58. * mq_timedreceive() putmsg() sigsuspend()
  59. *
  60. * Each of the above function must call enter_cancellation_point() on entry
  61. * in order to establish the cancellation point and leave_cancellation_point()
  62. * on exit. These functions are described below.
  63. *
  64. ****************************************************************************/
  65. /****************************************************************************
  66. * Included Files
  67. ****************************************************************************/
  68. #include <nuttx/config.h>
  69. #include <stdbool.h>
  70. /****************************************************************************
  71. * Public Function Prototypes
  72. ****************************************************************************/
  73. #ifdef __cplusplus
  74. #define EXTERN extern "C"
  75. extern "C"
  76. {
  77. #else
  78. #define EXTERN extern
  79. #endif
  80. /****************************************************************************
  81. * Name: enter_cancellation_point
  82. *
  83. * Description:
  84. * Called at the beginning of the cancellation point to establish the
  85. * cancellation point. This function does the following:
  86. *
  87. * 1. If deferred cancellation does not apply to this thread, nothing is
  88. * done, otherwise, it
  89. * 2. Sets state information in the caller's TCB and increments a nesting
  90. * count.
  91. * 3. If this is the outermost nesting level, it checks if there is a
  92. * pending cancellation and, if so, calls either exit() or
  93. * pthread_exit(), depending upon the type of the thread.
  94. *
  95. * Input Parameters:
  96. * None
  97. *
  98. * Returned Value:
  99. * true is returned if a cancellation is pending but cannot be performed
  100. * now due to the nesting level.
  101. *
  102. ****************************************************************************/
  103. #ifdef CONFIG_CANCELLATION_POINTS
  104. bool enter_cancellation_point(void);
  105. #else
  106. # define enter_cancellation_point() false
  107. #endif
  108. /****************************************************************************
  109. * Name: leave_cancellation_point
  110. *
  111. * Description:
  112. * Called at the end of the cancellation point. This function does the
  113. * following:
  114. *
  115. * 1. If deferred cancellation does not apply to this thread, nothing is
  116. * done, otherwise, it
  117. * 2. Clears state information in the caller's TCB and decrements a
  118. * nesting count.
  119. * 3. If this is the outermost nesting level, it checks if there is a
  120. * pending cancellation and, if so, calls either exit() or
  121. * pthread_exit(), depending upon the type of the thread.
  122. *
  123. * Input Parameters:
  124. * None
  125. *
  126. * Returned Value:
  127. * None
  128. *
  129. ****************************************************************************/
  130. #ifdef CONFIG_CANCELLATION_POINTS
  131. void leave_cancellation_point(void);
  132. #else
  133. # define leave_cancellation_point()
  134. #endif
  135. /****************************************************************************
  136. * Name: check_cancellation_point
  137. *
  138. * Description:
  139. * Returns true if:
  140. *
  141. * 1. Deferred cancellation does applies to this thread,
  142. * 2. We are within a cancellation point (i.e., the nesting level in the
  143. * TCB is greater than zero).
  144. *
  145. * Input Parameters:
  146. * None
  147. *
  148. * Returned Value:
  149. * true is returned if a cancellation is pending but cannot be performed
  150. * now due to the nesting level.
  151. *
  152. ****************************************************************************/
  153. #ifdef CONFIG_CANCELLATION_POINTS
  154. bool check_cancellation_point(void);
  155. #else
  156. # define check_cancellation_point() false
  157. #endif
  158. #undef EXTERN
  159. #ifdef __cplusplus
  160. }
  161. #endif
  162. #endif /* __INCLUDE_NUTTX_CANCELPT_H */