Back to index

glibc  2.9
pthread_setschedparam.c File Reference
#include <errno.h>
#include <sched.h>
#include <string.h>
#include "pthreadP.h"
#include <lowlevellock.h>

Go to the source code of this file.


int __pthread_setschedparam (pthread_t threadid, int policy, const struct sched_param *param)

Function Documentation

int __pthread_setschedparam ( pthread_t  threadid,
int  policy,
const struct sched_param param 

Definition at line 28 of file pthread_setschedparam.c.

  struct pthread *pd = (struct pthread *) threadid;

  /* Make sure the descriptor is valid.  */
  if (INVALID_TD_P (pd))
    /* Not a valid thread handle.  */
    return ESRCH;

  int result = 0;

  lll_lock (pd->lock, LLL_PRIVATE);

  struct sched_param p;
  const struct sched_param *orig_param = param;

  /* If the thread should have higher priority because of some
     PTHREAD_PRIO_PROTECT mutexes it holds, adjust the priority.  */
  if (__builtin_expect (pd->tpp != NULL, 0)
      && pd->tpp->priomax > param->sched_priority)
      p = *param;
      p.sched_priority = pd->tpp->priomax;
      param = &p;

  /* Try to set the scheduler information.  */
  if (__builtin_expect (__sched_setscheduler (pd->tid, policy,
                                         param) == -1, 0))
    result = errno;
      /* We succeeded changing the kernel information.  Reflect this
        change in the thread descriptor.  */
      pd->schedpolicy = policy;
      memcpy (&pd->schedparam, orig_param, sizeof (struct sched_param));

  lll_unlock (pd->lock, LLL_PRIVATE);

  return result;

Here is the call graph for this function: