home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / EXTRAS / UUCODE / UUPC / TEST / UPC12ES2.ZIP / UUCICO / prtyos2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-12  |  4.5 KB  |  144 lines

  1. /*--------------------------------------------------------------------*/
  2. /*       p r t y o s 2 . c                                            */
  3. /*                                                                    */
  4. /*       Set task priority for OS/2 tasks under UUPC/extended         */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*    Changes Copyright (c) 1989-1993 by Kendra Electronic            */
  9. /*    Wonderworks.                                                    */
  10. /*                                                                    */
  11. /*    All rights reserved except those explicitly granted by the      */
  12. /*    UUPC/extended license agreement.                                */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*--------------------------------------------------------------------*/
  16. /*                          RCS Information                           */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*
  20.  *    $Id: prtyos2.c 1.4 1993/10/12 01:33:23 ahd Exp $
  21.  *
  22.  *    Revision history:
  23.  *    $Log: prtyos2.c $
  24.  * Revision 1.4  1993/10/12  01:33:23  ahd
  25.  * Normalize comments to PL/I style
  26.  *
  27.  * Revision 1.3  1993/10/03  22:34:33  ahd
  28.  * Alter format of numbers printed
  29.  *
  30.  * Revision 1.2  1993/09/29  04:52:03  ahd
  31.  * Pass priority values as parameters
  32.  *
  33.  * Revision 1.1  1993/09/25  03:07:56  ahd
  34.  * Initial revision
  35.  *
  36.  */
  37.  
  38. /*--------------------------------------------------------------------*/
  39. /*                        System include files                        */
  40. /*--------------------------------------------------------------------*/
  41.  
  42. #include <stdio.h>
  43.  
  44. #define INCL_NOPMAPI
  45. #define INCL_BASE
  46. #include <os2.h>
  47.  
  48. /*--------------------------------------------------------------------*/
  49. /*                    UUPC/extended include files                     */
  50. /*--------------------------------------------------------------------*/
  51.  
  52. #include "lib.h"
  53. #include "pos2err.h"
  54.  
  55. /*--------------------------------------------------------------------*/
  56. /*                          Local variables                           */
  57. /*--------------------------------------------------------------------*/
  58.  
  59. currentfile();
  60.  
  61. #ifndef __OS2__
  62. typedef USHORT APIRET ;  /* Define older API return type              */
  63. #endif
  64.  
  65. #ifdef __OS2__
  66. static ULONG usPrevPriority;
  67. #else
  68. static USHORT usPrevPriority;
  69. #endif
  70.  
  71. static boolean restore = FALSE;
  72.  
  73. /*--------------------------------------------------------------------*/
  74. /*       s e t P r t y                                                */
  75. /*                                                                    */
  76. /*       Set priority to configuration defined value                  */
  77. /*--------------------------------------------------------------------*/
  78.  
  79. void setPrty( const KEWSHORT priorityIn, const KEWSHORT prioritydeltaIn )
  80. {
  81.    USHORT priority = (priorityIn == 999) ?
  82.                            PRTYC_FOREGROUNDSERVER : (USHORT) priorityIn;
  83.    USHORT prioritydelta = (prioritydeltaIn == 999) ?
  84.                            0 : (USHORT) (prioritydeltaIn + PRTYD_MINIMUM);
  85.  
  86.    APIRET rc;
  87.  
  88. #ifdef __OS2__
  89.  
  90.    PTIB ptib;
  91.    PPIB ppib;
  92.  
  93.    rc = DosGetInfoBlocks( &ptib, &ppib);
  94.    if ( !rc )
  95.       usPrevPriority = (ptib->tib_ptib2)->tib2_ulpri;
  96. #else
  97.    rc = DosGetPrty(PRTYS_PROCESS, &usPrevPriority, 0);
  98. #endif
  99.  
  100.    if (rc)
  101.    {
  102.       printOS2error( "DosGetPrty", rc );
  103.       panic();
  104.    } /*if */
  105.    else
  106.       restore = TRUE;
  107.  
  108.    rc = DosSetPrty(PRTYS_PROCESS, priority, prioritydelta, 0);
  109.  
  110.    if (rc)
  111.    {
  112.       printmsg(0,"setPrty: Unable to set priority %hu,%hu for task",
  113.                    priority, prioritydelta);
  114.       printOS2error( "DosSetPrty", rc );
  115.  
  116.    } /*if */
  117.  
  118. } /* SetPrty */
  119.  
  120. /*--------------------------------------------------------------------*/
  121. /*       r e s e t P r t y                                            */
  122. /*                                                                    */
  123. /*       Restore priority saved by SetPrty                            */
  124. /*--------------------------------------------------------------------*/
  125.  
  126. void resetPrty( void )
  127. {
  128.  
  129.    APIRET rc;
  130.  
  131.    if ( !restore )
  132.       return;
  133.  
  134.    rc = DosSetPrty(PRTYS_PROCESS,
  135.                    usPrevPriority >> 8 ,
  136.                    usPrevPriority & 0xff, 0);
  137.  
  138.    if (rc)
  139.       printOS2error( "DosSetPrty", rc );
  140.  
  141.    restore = FALSE;
  142.  
  143. } /* resetPrty */
  144.