Back to index

glibc  2.9
Functions
getpriority.c File Reference
#include <limits.h>
#include <hurd.h>
#include <hurd/resource.h>

Go to the source code of this file.

Functions

int getpriority (enum __priority_which which, id_t who)

Function Documentation

int getpriority ( enum __priority_which  which,
id_t  who 
)

Definition at line 28 of file getpriority.c.

{
  error_t err, onerr;
  int maxpri = INT_MIN;
  struct procinfo *pip;            /* Just for sizeof.  */
  int pibuf[sizeof *pip + 2 * sizeof (pip->threadinfos[0])], *pi = pibuf;
  size_t pisize = sizeof pibuf / sizeof pibuf[0];

  error_t getonepriority (pid_t pid, struct procinfo *pip)
    {
      if (pip)
       onerr = 0;
      else
       {
         int *oldpi = pi;
         size_t oldpisize = pisize;
         char *tw = 0;
         size_t twsz = 0;
         int flags = PI_FETCH_TASKINFO;
         onerr = __USEPORT (PROC, __proc_getprocinfo (port, pid, &flags,
                                                 &pi, &pisize,
                                                 &tw, &twsz));
         if (twsz)
           __vm_deallocate (__mach_task_self (), (vm_address_t) tw, twsz);
         if (pi != oldpi && oldpi != pibuf)
           /* Old buffer from last call was not reused; free it.  */
           __vm_deallocate (__mach_task_self (),
                          (vm_address_t) oldpi, oldpisize * sizeof pi[0]);
         pip = (struct procinfo *) pi;
       }
#ifdef TASK_SCHED_TIMESHARE_INFO
      if (!onerr && pip->timeshare_base_info.base_priority > maxpri)
       maxpri = pip->timeshare_base_info.base_priority;
#else
      if (!onerr && pip->taskinfo.base_priority > maxpri)
       maxpri = pip->taskinfo.base_priority;
#endif
      return 0;
    }

  onerr = 0;
  err = _hurd_priority_which_map (which, who,
                              getonepriority, PI_FETCH_TASKINFO);

  if (pi != pibuf)
    __vm_deallocate (__mach_task_self (),
                   (vm_address_t) pi, pisize * sizeof pi[0]);

  if (!err && maxpri == INT_MIN)
    /* No error, but no pids found.  */
    err = onerr ?: ESRCH;

  if (err)
    return __hurd_fail (err);

  return MACH_PRIORITY_TO_NICE (maxpri);
}

Here is the call graph for this function: