pthread.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /****************************************************************************
  2. * include/nuttx/pthread.h
  3. * Non-standard, NuttX-specific pthread-related declarations.
  4. *
  5. * Copyright (C) 2011, 2015-2016 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_PTHREAD_H
  37. #define __INCLUDE_NUTTX_PTHREAD_H
  38. /****************************************************************************
  39. * Included Files
  40. ****************************************************************************/
  41. #include <nuttx/config.h>
  42. #include <pthread.h>
  43. #include <sched.h>
  44. /****************************************************************************
  45. * Pre-processor Definitions
  46. ****************************************************************************/
  47. /* Default pthread attribute initializer */
  48. #if CONFIG_RR_INTERVAL == 0
  49. # define PTHREAD_DEFAULT_POLICY SCHED_FIFO
  50. #else
  51. # define PTHREAD_DEFAULT_POLICY SCHED_RR
  52. #endif
  53. /* A lot of hassle to use the old-fashioned struct initializers. But this
  54. * gives us backward compatibility with some very old compilers.
  55. */
  56. #if defined(CONFIG_SCHED_SPORADIC) && defined(CONFIG_SMP)
  57. # define PTHREAD_ATTR_INITIALIZER \
  58. { \
  59. PTHREAD_DEFAULT_PRIORITY, /* priority */ \
  60. PTHREAD_DEFAULT_POLICY, /* policy */ \
  61. PTHREAD_EXPLICIT_SCHED, /* inheritsched */ \
  62. PTHREAD_CREATE_JOINABLE, /* detachstate */ \
  63. 0, /* low_priority */ \
  64. 0, /* max_repl */ \
  65. 0, /* affinity */ \
  66. NULL, /* stackaddr */ \
  67. PTHREAD_STACK_DEFAULT, /* stacksize */ \
  68. {0, 0}, /* repl_period */ \
  69. {0, 0} /* budget */ \
  70. }
  71. #elif defined(CONFIG_SCHED_SPORADIC)
  72. # define PTHREAD_ATTR_INITIALIZER \
  73. { \
  74. PTHREAD_DEFAULT_PRIORITY, /* priority */ \
  75. PTHREAD_DEFAULT_POLICY, /* policy */ \
  76. PTHREAD_EXPLICIT_SCHED, /* inheritsched */ \
  77. PTHREAD_CREATE_JOINABLE, /* detachstate */ \
  78. 0, /* low_priority */ \
  79. 0, /* max_repl */ \
  80. NULL, /* stackaddr */ \
  81. PTHREAD_STACK_DEFAULT, /* stacksize */ \
  82. {0, 0}, /* repl_period */ \
  83. {0, 0}, /* budget */ \
  84. }
  85. #elif defined(CONFIG_SMP)
  86. # define PTHREAD_ATTR_INITIALIZER \
  87. { \
  88. PTHREAD_DEFAULT_PRIORITY, /* priority */ \
  89. PTHREAD_DEFAULT_POLICY, /* policy */ \
  90. PTHREAD_EXPLICIT_SCHED, /* inheritsched */ \
  91. PTHREAD_CREATE_JOINABLE, /* detachstate */ \
  92. 0, /* affinity */ \
  93. NULL, /* stackaddr */ \
  94. PTHREAD_STACK_DEFAULT, /* stacksize */ \
  95. }
  96. #else
  97. # define PTHREAD_ATTR_INITIALIZER \
  98. { \
  99. PTHREAD_DEFAULT_PRIORITY, /* priority */ \
  100. PTHREAD_DEFAULT_POLICY, /* policy */ \
  101. PTHREAD_EXPLICIT_SCHED, /* inheritsched */ \
  102. PTHREAD_CREATE_JOINABLE, /* detachstate */ \
  103. NULL, /* stackaddr */ \
  104. PTHREAD_STACK_DEFAULT, /* stacksize */ \
  105. }
  106. #endif
  107. /****************************************************************************
  108. * Public Data
  109. ****************************************************************************/
  110. #ifdef __cplusplus
  111. #define EXTERN extern "C"
  112. extern "C"
  113. {
  114. #else
  115. #define EXTERN extern
  116. #endif
  117. /* Default pthread attributes. This global can only be shared within the
  118. * kernel- or within the user- address space.
  119. */
  120. EXTERN const pthread_attr_t g_default_pthread_attr;
  121. /****************************************************************************
  122. * Public Function Prototypes
  123. ****************************************************************************/
  124. #undef EXTERN
  125. #ifdef __cplusplus
  126. }
  127. #endif
  128. #endif /* __INCLUDE_NUTTX_PTHREAD_H */