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