xref: /relibc/pthreads-emb/pthread_getschedparam.c (revision a12978ccca4c576f02971f5cfc2cbefe23e4daba)
1062c5bc4SJason Schmidlapp /*
2062c5bc4SJason Schmidlapp  * sched_getschedparam.c
3062c5bc4SJason Schmidlapp  *
4062c5bc4SJason Schmidlapp  * Description:
5062c5bc4SJason Schmidlapp  * POSIX thread functions that deal with thread scheduling.
6062c5bc4SJason Schmidlapp  *
7062c5bc4SJason Schmidlapp  * --------------------------------------------------------------------------
8062c5bc4SJason Schmidlapp  *
9062c5bc4SJason Schmidlapp  *      Pthreads-embedded (PTE) - POSIX Threads Library for embedded systems
10062c5bc4SJason Schmidlapp  *      Copyright(C) 2008 Jason Schmidlapp
11062c5bc4SJason Schmidlapp  *
12062c5bc4SJason Schmidlapp  *      Contact Email: jschmidlapp@users.sourceforge.net
13062c5bc4SJason Schmidlapp  *
14062c5bc4SJason Schmidlapp  *
15062c5bc4SJason Schmidlapp  *      Based upon Pthreads-win32 - POSIX Threads Library for Win32
16062c5bc4SJason Schmidlapp  *      Copyright(C) 1998 John E. Bossom
17062c5bc4SJason Schmidlapp  *      Copyright(C) 1999,2005 Pthreads-win32 contributors
18062c5bc4SJason Schmidlapp  *
19062c5bc4SJason Schmidlapp  *      Contact Email: rpj@callisto.canberra.edu.au
20062c5bc4SJason Schmidlapp  *
21062c5bc4SJason Schmidlapp  *      The original list of contributors to the Pthreads-win32 project
22062c5bc4SJason Schmidlapp  *      is contained in the file CONTRIBUTORS.ptw32 included with the
23062c5bc4SJason Schmidlapp  *      source code distribution. The list can also be seen at the
24062c5bc4SJason Schmidlapp  *      following World Wide Web location:
25062c5bc4SJason Schmidlapp  *      http://sources.redhat.com/pthreads-win32/contributors.html
26062c5bc4SJason Schmidlapp  *
27062c5bc4SJason Schmidlapp  *      This library is free software; you can redistribute it and/or
28062c5bc4SJason Schmidlapp  *      modify it under the terms of the GNU Lesser General Public
29062c5bc4SJason Schmidlapp  *      License as published by the Free Software Foundation; either
30062c5bc4SJason Schmidlapp  *      version 2 of the License, or (at your option) any later version.
31062c5bc4SJason Schmidlapp  *
32062c5bc4SJason Schmidlapp  *      This library is distributed in the hope that it will be useful,
33062c5bc4SJason Schmidlapp  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
34062c5bc4SJason Schmidlapp  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
35062c5bc4SJason Schmidlapp  *      Lesser General Public License for more details.
36062c5bc4SJason Schmidlapp  *
37062c5bc4SJason Schmidlapp  *      You should have received a copy of the GNU Lesser General Public
38062c5bc4SJason Schmidlapp  *      License along with this library in the file COPYING.LIB;
39062c5bc4SJason Schmidlapp  *      if not, write to the Free Software Foundation, Inc.,
40062c5bc4SJason Schmidlapp  *      59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
41062c5bc4SJason Schmidlapp  */
42062c5bc4SJason Schmidlapp 
43062c5bc4SJason Schmidlapp #include "pthread.h"
44062c5bc4SJason Schmidlapp #include "implement.h"
45062c5bc4SJason Schmidlapp #include "sched.h"
46062c5bc4SJason Schmidlapp 
47062c5bc4SJason Schmidlapp int
pthread_getschedparam(pthread_t thread,int * policy,struct sched_param * param)48062c5bc4SJason Schmidlapp pthread_getschedparam (pthread_t thread, int *policy,
49062c5bc4SJason Schmidlapp                        struct sched_param *param)
50062c5bc4SJason Schmidlapp {
51062c5bc4SJason Schmidlapp   int result;
52062c5bc4SJason Schmidlapp 
53062c5bc4SJason Schmidlapp   /* Validate the thread id. */
54062c5bc4SJason Schmidlapp   result = pthread_kill (thread, 0);
55062c5bc4SJason Schmidlapp   if (0 != result)
56062c5bc4SJason Schmidlapp     {
57062c5bc4SJason Schmidlapp       return result;
58062c5bc4SJason Schmidlapp     }
59062c5bc4SJason Schmidlapp 
60062c5bc4SJason Schmidlapp   /*
61062c5bc4SJason Schmidlapp    * Validate the policy and param args.
62062c5bc4SJason Schmidlapp    * Check that a policy constant wasn't passed rather than &policy.
63062c5bc4SJason Schmidlapp    */
64062c5bc4SJason Schmidlapp   if (policy <= (int *) SCHED_MAX || param == NULL)
65062c5bc4SJason Schmidlapp     {
66062c5bc4SJason Schmidlapp       return EINVAL;
67062c5bc4SJason Schmidlapp     }
68062c5bc4SJason Schmidlapp 
69062c5bc4SJason Schmidlapp   /* Fill out the policy. */
70062c5bc4SJason Schmidlapp   *policy = SCHED_OTHER;
71062c5bc4SJason Schmidlapp 
72062c5bc4SJason Schmidlapp   /*
73062c5bc4SJason Schmidlapp    * This function must return the priority value set by
74062c5bc4SJason Schmidlapp    * the most recent pthread_setschedparam() or pthread_create()
75062c5bc4SJason Schmidlapp    * for the target thread. It must not return the actual thread
76062c5bc4SJason Schmidlapp    * priority as altered by any system priority adjustments etc.
77062c5bc4SJason Schmidlapp    */
78*a12978ccSJeremy Soller   param->sched_priority = ((pte_thread_t *)thread)->sched_priority;
79062c5bc4SJason Schmidlapp 
80062c5bc4SJason Schmidlapp   return 0;
81062c5bc4SJason Schmidlapp }
82