Back to index

glibc  2.9
pthread_getschedparam.c
Go to the documentation of this file.
00001 /* Copyright (C) 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <errno.h>
00021 #include <string.h>
00022 #include "pthreadP.h"
00023 #include <lowlevellock.h>
00024 
00025 
00026 int
00027 __pthread_getschedparam (threadid, policy, param)
00028      pthread_t threadid;
00029      int *policy;
00030      struct sched_param *param;
00031 {
00032   struct pthread *pd = (struct pthread *) threadid;
00033 
00034   /* Make sure the descriptor is valid.  */
00035   if (INVALID_TD_P (pd))
00036     /* Not a valid thread handle.  */
00037     return ESRCH;
00038 
00039   int result = 0;
00040 
00041   lll_lock (pd->lock, LLL_PRIVATE);
00042 
00043   /* The library is responsible for maintaining the values at all
00044      times.  If the user uses a interface other than
00045      pthread_setschedparam to modify the scheduler setting it is not
00046      the library's problem.  In case the descriptor's values have
00047      not yet been retrieved do it now.  */
00048   if ((pd->flags & ATTR_FLAG_SCHED_SET) == 0)
00049     {
00050       if (__sched_getparam (pd->tid, &pd->schedparam) != 0)
00051        result = 1;
00052       else
00053        pd->flags |= ATTR_FLAG_SCHED_SET;
00054     }
00055 
00056   if ((pd->flags & ATTR_FLAG_POLICY_SET) == 0)
00057     {
00058       pd->schedpolicy = __sched_getscheduler (pd->tid);
00059       if (pd->schedpolicy == -1)
00060        result = 1;
00061       else
00062        pd->flags |= ATTR_FLAG_POLICY_SET;
00063     }
00064 
00065   if (result == 0)
00066     {
00067       *policy = pd->schedpolicy;
00068       memcpy (param, &pd->schedparam, sizeof (struct sched_param));
00069     }
00070 
00071   lll_unlock (pd->lock, LLL_PRIVATE);
00072 
00073   return result;
00074 }
00075 strong_alias (__pthread_getschedparam, pthread_getschedparam)