Back to index

glibc  2.9
pthread_setschedprio.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_setschedprio (pthread_t threadid, int prio)

Function Documentation

int pthread_setschedprio ( pthread_t  threadid,
int  prio 

Definition at line 29 of file pthread_setschedprio.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;
  struct sched_param param;
  param.sched_priority = prio;

  lll_lock (pd->lock, LLL_PRIVATE);

  /* 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 > prio)
    param.sched_priority = pd->tpp->priomax;

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

  lll_unlock (pd->lock, LLL_PRIVATE);

  return result;

Here is the call graph for this function: