home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / library / rcs / setpriority.c,v < prev    next >
Encoding:
Text File  |  1992-07-04  |  2.3 KB  |  96 lines

  1. head    1.1;
  2. access;
  3. symbols
  4.     version39-41:1.1;
  5. locks;
  6. comment    @ *  @;
  7.  
  8.  
  9. 1.1
  10. date    92.05.14.19.55.40;    author mwild;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @set process priority (**IX like, negative means high priority)
  17. @
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/*
  26.  *  This file is part of ixemul.library for the Amiga.
  27.  *  Copyright (C) 1991, 1992  Markus M. Wild
  28.  *
  29.  *  This library is free software; you can redistribute it and/or
  30.  *  modify it under the terms of the GNU Library General Public
  31.  *  License as published by the Free Software Foundation; either
  32.  *  version 2 of the License, or (at your option) any later version.
  33.  *
  34.  *  This library is distributed in the hope that it will be useful,
  35.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  36.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  37.  *  Library General Public License for more details.
  38.  *
  39.  *  You should have received a copy of the GNU Library General Public
  40.  *  License along with this library; if not, write to the Free
  41.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  42.  *
  43.  *  $Id$
  44.  *
  45.  *  $Log$
  46.  */
  47.  
  48. #define KERNEL
  49. #include "ixemul.h"
  50.  
  51. /* REMARK: all priorities are negated, since on the Amiga, lower
  52.  * priorities mean less power, not more power.. */
  53.  
  54. int
  55. setpriority(int which, int who, int prio)
  56. {
  57.   if (prio < PRIO_MIN) prio = PRIO_MIN;
  58.   else if (prio > PRIO_MAX) prio = PRIO_MAX;
  59.  
  60.   if (who < PRIO_PROCESS || who > PRIO_USER)
  61.     {
  62.       errno = EINVAL;
  63.       return -1;
  64.     }
  65.  
  66.   if (which == PRIO_USER || who == 0)
  67.     {
  68.       struct Task *myself = (struct Task *)FindTask(0);
  69.       /* in this case I ignore the 'which' argument, and just set
  70.        * my own Priority */
  71.       SetTaskPri(0, -prio);
  72.       return 0;
  73.     }
  74.  
  75.   /* so we look for processes. I ignore a difference between processes
  76.    * and process-groups.. */
  77.  
  78.   /* try to validate, that the given pid is really a task-pointer */
  79.   /* a pointer has to be word-aligned */
  80.   if (!(who & 1))
  81.     {
  82.       struct Task *task = (struct Task *)who;
  83.       /* it must have a node-type of either NT_PROCESS or NT_TASK */
  84.       if (task->tc_Node.ln_Type == NT_PROCESS ||
  85.           task->tc_Node.ln_Type == NT_TASK)
  86.     {
  87.       /* so we have to believe, this is really a task */
  88.       SetTaskPri(task, -prio);
  89.       return 0;
  90.     }
  91.     }
  92.   errno = ESRCH;
  93.   return -1;
  94. }
  95. @
  96.