xref: /relibc/pthreads-emb/sched.h (revision 714af18cbe52336f4ff71fe91bfb035d5efaef7d)
1062c5bc4SJason Schmidlapp /*
2062c5bc4SJason Schmidlapp  * Module: sched.h
3062c5bc4SJason Schmidlapp  *
4062c5bc4SJason Schmidlapp  * Purpose:
5062c5bc4SJason Schmidlapp  *      Provides an implementation of POSIX realtime extensions
6062c5bc4SJason Schmidlapp  *      as defined in
7062c5bc4SJason Schmidlapp  *
8062c5bc4SJason Schmidlapp  *              POSIX 1003.1b-1993      (POSIX.1b)
9062c5bc4SJason Schmidlapp  *
10062c5bc4SJason Schmidlapp  * --------------------------------------------------------------------------
11062c5bc4SJason Schmidlapp  *
12062c5bc4SJason Schmidlapp  *      Pthreads-embedded (PTE) - POSIX Threads Library for embedded systems
13062c5bc4SJason Schmidlapp  *      Copyright(C) 2008 Jason Schmidlapp
14062c5bc4SJason Schmidlapp  *
15062c5bc4SJason Schmidlapp  *      Contact Email: jschmidlapp@users.sourceforge.net
16062c5bc4SJason Schmidlapp  *
17062c5bc4SJason Schmidlapp  *
18062c5bc4SJason Schmidlapp  *      Pthreads-embedded (PTE) - POSIX Threads Library for embedded systems
19062c5bc4SJason Schmidlapp  *      Copyright(C) 2008 Jason Schmidlapp
20062c5bc4SJason Schmidlapp  *
21062c5bc4SJason Schmidlapp  *      Contact Email: jschmidlapp@users.sourceforge.net
22062c5bc4SJason Schmidlapp  *
23062c5bc4SJason Schmidlapp  *
24062c5bc4SJason Schmidlapp  *      Based upon Pthreads-win32 - POSIX Threads Library for Win32
25062c5bc4SJason Schmidlapp  *      Copyright(C) 1998 John E. Bossom
26062c5bc4SJason Schmidlapp  *      Copyright(C) 1999,2005 Pthreads-win32 contributors
27062c5bc4SJason Schmidlapp  *
28062c5bc4SJason Schmidlapp  *      Contact Email: rpj@callisto.canberra.edu.au
29062c5bc4SJason Schmidlapp  *
30062c5bc4SJason Schmidlapp  *      The original list of contributors to the Pthreads-win32 project
31062c5bc4SJason Schmidlapp  *      is contained in the file CONTRIBUTORS.ptw32 included with the
32062c5bc4SJason Schmidlapp  *      source code distribution. The list can also be seen at the
33062c5bc4SJason Schmidlapp  *      following World Wide Web location:
34062c5bc4SJason Schmidlapp  *      http://sources.redhat.com/pthreads-win32/contributors.html
35062c5bc4SJason Schmidlapp  *
36062c5bc4SJason Schmidlapp  *      This library is free software; you can redistribute it and/or
37062c5bc4SJason Schmidlapp  *      modify it under the terms of the GNU Lesser General Public
38062c5bc4SJason Schmidlapp  *      License as published by the Free Software Foundation; either
39062c5bc4SJason Schmidlapp  *      version 2 of the License, or (at your option) any later version.
40062c5bc4SJason Schmidlapp  *
41062c5bc4SJason Schmidlapp  *      This library is distributed in the hope that it will be useful,
42062c5bc4SJason Schmidlapp  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
43062c5bc4SJason Schmidlapp  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
44062c5bc4SJason Schmidlapp  *      Lesser General Public License for more details.
45062c5bc4SJason Schmidlapp  *
46062c5bc4SJason Schmidlapp  *      You should have received a copy of the GNU Lesser General Public
47062c5bc4SJason Schmidlapp  *      License along with this library in the file COPYING.LIB;
48062c5bc4SJason Schmidlapp  *      if not, write to the Free Software Foundation, Inc.,
49062c5bc4SJason Schmidlapp  *      59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
50062c5bc4SJason Schmidlapp  */
51062c5bc4SJason Schmidlapp #ifndef _SCHED_H
52062c5bc4SJason Schmidlapp #define _SCHED_H
53062c5bc4SJason Schmidlapp 
54*714af18cSJason Schmidlapp #include <pte_types.h>
55062c5bc4SJason Schmidlapp 
56062c5bc4SJason Schmidlapp #undef PTE_LEVEL
57062c5bc4SJason Schmidlapp 
58062c5bc4SJason Schmidlapp #if defined(_POSIX_SOURCE)
59062c5bc4SJason Schmidlapp #define PTE_LEVEL 0
60062c5bc4SJason Schmidlapp /* Early POSIX */
61062c5bc4SJason Schmidlapp #endif
62062c5bc4SJason Schmidlapp 
63062c5bc4SJason Schmidlapp #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309
64062c5bc4SJason Schmidlapp #undef PTE_LEVEL
65062c5bc4SJason Schmidlapp #define PTE_LEVEL 1
66062c5bc4SJason Schmidlapp /* Include 1b, 1c and 1d */
67062c5bc4SJason Schmidlapp #endif
68062c5bc4SJason Schmidlapp 
69062c5bc4SJason Schmidlapp #if defined(INCLUDE_NP)
70062c5bc4SJason Schmidlapp #undef PTE_LEVEL
71062c5bc4SJason Schmidlapp #define PTE_LEVEL 2
72062c5bc4SJason Schmidlapp /* Include Non-Portable extensions */
73062c5bc4SJason Schmidlapp #endif
74062c5bc4SJason Schmidlapp 
75062c5bc4SJason Schmidlapp #define PTE_LEVEL_MAX 3
76062c5bc4SJason Schmidlapp 
77062c5bc4SJason Schmidlapp #if !defined(PTE_LEVEL)
78062c5bc4SJason Schmidlapp #define PTE_LEVEL PTE_LEVEL_MAX
79062c5bc4SJason Schmidlapp /* Include everything */
80062c5bc4SJason Schmidlapp #endif
81062c5bc4SJason Schmidlapp 
82062c5bc4SJason Schmidlapp /*
83062c5bc4SJason Schmidlapp  *
84062c5bc4SJason Schmidlapp  */
85062c5bc4SJason Schmidlapp 
86062c5bc4SJason Schmidlapp /* Thread scheduling policies */
87062c5bc4SJason Schmidlapp 
88062c5bc4SJason Schmidlapp enum
89062c5bc4SJason Schmidlapp {
90062c5bc4SJason Schmidlapp   SCHED_OTHER = 0,
91062c5bc4SJason Schmidlapp   SCHED_FIFO,
92062c5bc4SJason Schmidlapp   SCHED_RR,
93062c5bc4SJason Schmidlapp   SCHED_MIN   = SCHED_OTHER,
94062c5bc4SJason Schmidlapp   SCHED_MAX   = SCHED_RR
95062c5bc4SJason Schmidlapp };
96062c5bc4SJason Schmidlapp 
97062c5bc4SJason Schmidlapp struct sched_param
98062c5bc4SJason Schmidlapp   {
99062c5bc4SJason Schmidlapp     int sched_priority;
100062c5bc4SJason Schmidlapp   };
101062c5bc4SJason Schmidlapp 
102062c5bc4SJason Schmidlapp #ifdef __cplusplus
103062c5bc4SJason Schmidlapp extern "C"
104062c5bc4SJason Schmidlapp   {
105062c5bc4SJason Schmidlapp #endif                          /* __cplusplus */
106062c5bc4SJason Schmidlapp 
107062c5bc4SJason Schmidlapp     int sched_yield (void);
108062c5bc4SJason Schmidlapp 
109062c5bc4SJason Schmidlapp     int sched_get_priority_min (int policy);
110062c5bc4SJason Schmidlapp 
111062c5bc4SJason Schmidlapp     int sched_get_priority_max (int policy);
112062c5bc4SJason Schmidlapp 
113062c5bc4SJason Schmidlapp     int sched_setscheduler (pid_t pid, int policy);
114062c5bc4SJason Schmidlapp 
115062c5bc4SJason Schmidlapp     /*
116062c5bc4SJason Schmidlapp      * Note that this macro returns ENOTSUP rather than
117062c5bc4SJason Schmidlapp      * ENOSYS as might be expected. However, returning ENOSYS
118062c5bc4SJason Schmidlapp      * should mean that sched_get_priority_{min,max} are
119062c5bc4SJason Schmidlapp      * not implemented as well as sched_rr_get_interval.
120062c5bc4SJason Schmidlapp      * This is not the case, since we just don't support
121062c5bc4SJason Schmidlapp      * round-robin scheduling. Therefore I have chosen to
122062c5bc4SJason Schmidlapp      * return the same value as sched_setscheduler when
123062c5bc4SJason Schmidlapp      * SCHED_RR is passed to it.
124062c5bc4SJason Schmidlapp      */
125062c5bc4SJason Schmidlapp #define sched_rr_get_interval(_pid, _interval) \
126062c5bc4SJason Schmidlapp   ( errno = ENOTSUP, (int) -1 )
127062c5bc4SJason Schmidlapp 
128062c5bc4SJason Schmidlapp 
129062c5bc4SJason Schmidlapp #ifdef __cplusplus
130062c5bc4SJason Schmidlapp   }                               /* End of extern "C" */
131062c5bc4SJason Schmidlapp #endif                          /* __cplusplus */
132062c5bc4SJason Schmidlapp 
133062c5bc4SJason Schmidlapp #undef PTE_LEVEL
134062c5bc4SJason Schmidlapp #undef PTE_LEVEL_MAX
135062c5bc4SJason Schmidlapp 
136062c5bc4SJason Schmidlapp #endif                          /* !_SCHED_H */
137062c5bc4SJason Schmidlapp 
138