sched.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * Module: sched.h
  3. *
  4. * Purpose:
  5. * Provides an implementation of POSIX realtime extensions
  6. * as defined in
  7. *
  8. * POSIX 1003.1b-1993 (POSIX.1b)
  9. *
  10. * --------------------------------------------------------------------------
  11. *
  12. * Pthreads-win32 - POSIX Threads Library for Win32
  13. * Copyright(C) 1998 John E. Bossom
  14. * Copyright(C) 1999,2005 Pthreads-win32 contributors
  15. *
  16. * Contact Email: rpj@callisto.canberra.edu.au
  17. *
  18. * The current list of contributors is contained
  19. * in the file CONTRIBUTORS included with the source
  20. * code distribution. The list can also be seen at the
  21. * following World Wide Web location:
  22. * http://sources.redhat.com/pthreads-win32/contributors.html
  23. *
  24. * This library is free software; you can redistribute it and/or
  25. * modify it under the terms of the GNU Lesser General Public
  26. * License as published by the Free Software Foundation; either
  27. * version 2 of the License, or (at your option) any later version.
  28. *
  29. * This library is distributed in the hope that it will be useful,
  30. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  32. * Lesser General Public License for more details.
  33. *
  34. * You should have received a copy of the GNU Lesser General Public
  35. * License along with this library in the file COPYING.LIB;
  36. * if not, write to the Free Software Foundation, Inc.,
  37. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  38. */
  39. #if !defined(_SCHED_H)
  40. #define _SCHED_H
  41. #undef PTW32_SCHED_LEVEL
  42. #if defined(_POSIX_SOURCE)
  43. #define PTW32_SCHED_LEVEL 0
  44. /* Early POSIX */
  45. #endif
  46. #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309
  47. #undef PTW32_SCHED_LEVEL
  48. #define PTW32_SCHED_LEVEL 1
  49. /* Include 1b, 1c and 1d */
  50. #endif
  51. #if defined(INCLUDE_NP)
  52. #undef PTW32_SCHED_LEVEL
  53. #define PTW32_SCHED_LEVEL 2
  54. /* Include Non-Portable extensions */
  55. #endif
  56. #define PTW32_SCHED_LEVEL_MAX 3
  57. #if ( defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112 ) || !defined(PTW32_SCHED_LEVEL)
  58. #undef PTW32_SCHED_LEVEL
  59. #define PTW32_SCHED_LEVEL PTW32_SCHED_LEVEL_MAX
  60. /* Include everything */
  61. #endif
  62. #if defined(__GNUC__) && !defined(__declspec)
  63. # error Please upgrade your GNU compiler to one that supports __declspec.
  64. #endif
  65. /*
  66. * When building the library, you should define PTW32_BUILD so that
  67. * the variables/functions are exported correctly. When using the library,
  68. * do NOT define PTW32_BUILD, and then the variables/functions will
  69. * be imported correctly.
  70. */
  71. #if !defined(PTW32_STATIC_LIB)
  72. # if defined(PTW32_BUILD)
  73. # define PTW32_DLLPORT __declspec (dllexport)
  74. # else
  75. # define PTW32_DLLPORT __declspec (dllimport)
  76. # endif
  77. #else
  78. # define PTW32_DLLPORT
  79. #endif
  80. /*
  81. * This is a duplicate of what is in the autoconf config.h,
  82. * which is only used when building the pthread-win32 libraries.
  83. */
  84. #if !defined(PTW32_CONFIG_H)
  85. # if defined(WINCE)
  86. # define NEED_ERRNO
  87. # define NEED_SEM
  88. # endif
  89. # if defined(__MINGW64__)
  90. # define HAVE_STRUCT_TIMESPEC
  91. # define HAVE_MODE_T
  92. # elif defined(_UWIN) || defined(__MINGW32__)
  93. # define HAVE_MODE_T
  94. # endif
  95. #endif
  96. /*
  97. *
  98. */
  99. #if PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX
  100. #if defined(NEED_ERRNO)
  101. #include "need_errno.h"
  102. #else
  103. #include <errno.h>
  104. #endif
  105. #endif /* PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX */
  106. #if (defined(__MINGW64__) || defined(__MINGW32__)) || defined(_UWIN)
  107. # if PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX
  108. /* For pid_t */
  109. # include <sys/types.h>
  110. /* Required by Unix 98 */
  111. # include <time.h>
  112. # else
  113. typedef int pid_t;
  114. # endif
  115. #else
  116. typedef int pid_t;
  117. #endif
  118. /* Thread scheduling policies */
  119. enum {
  120. SCHED_OTHER = 0,
  121. SCHED_FIFO,
  122. SCHED_RR,
  123. SCHED_MIN = SCHED_OTHER,
  124. SCHED_MAX = SCHED_RR
  125. };
  126. struct sched_param {
  127. int sched_priority;
  128. };
  129. #if defined(__cplusplus)
  130. extern "C"
  131. {
  132. #endif /* __cplusplus */
  133. PTW32_DLLPORT int __cdecl sched_yield (void);
  134. PTW32_DLLPORT int __cdecl sched_get_priority_min (int policy);
  135. PTW32_DLLPORT int __cdecl sched_get_priority_max (int policy);
  136. PTW32_DLLPORT int __cdecl sched_setscheduler (pid_t pid, int policy);
  137. PTW32_DLLPORT int __cdecl sched_getscheduler (pid_t pid);
  138. /*
  139. * Note that this macro returns ENOTSUP rather than
  140. * ENOSYS as might be expected. However, returning ENOSYS
  141. * should mean that sched_get_priority_{min,max} are
  142. * not implemented as well as sched_rr_get_interval.
  143. * This is not the case, since we just don't support
  144. * round-robin scheduling. Therefore I have chosen to
  145. * return the same value as sched_setscheduler when
  146. * SCHED_RR is passed to it.
  147. */
  148. #define sched_rr_get_interval(_pid, _interval) \
  149. ( errno = ENOTSUP, (int) -1 )
  150. #if defined(__cplusplus)
  151. } /* End of extern "C" */
  152. #endif /* __cplusplus */
  153. #undef PTW32_SCHED_LEVEL
  154. #undef PTW32_SCHED_LEVEL_MAX
  155. #endif /* !_SCHED_H */