home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 330_03 / tskmain.c < prev    next >
C/C++ Source or Header  |  1990-10-12  |  6KB  |  236 lines

  1. /*
  2.    --- Version 2.2 90-10-12 10:33 ---
  3.  
  4.    TSKMAIN.C - CTask - Install/remove tasker front-end functions.
  5.  
  6.    CTask - a Multitasking Kernel for C
  7.  
  8.    Public Domain Software written by
  9.       Thomas Wagner
  10.       Ferrari electronic Gmbh
  11.       Beusselstrasse 27
  12.       D-1000 Berlin 21
  13.       Germany
  14.  
  15.    No rights reserved.
  16.  
  17.    Version 2.1 separates the functions previously collected in tskmain.c into
  18.          tskmain.c - Front ends for installation/removal
  19.          tskinst.c - Install/Remove main kernel
  20.          tskgrp.c  - Create/remove groups
  21.          tsktask.c - Task creation and deletion
  22.          tsktutl.c - Task utilities (get/set priority etc.)
  23.          tskutil.c - General utilities (preemption, t_delay)
  24.  
  25.    The split was made to allow better tuning of code space, and to
  26.    better support code sharing and secondary invocations.
  27.  
  28.    For code share linking without group creation, none of the routines
  29.    are needed, all necessary local code is in 'tskres.asm'.
  30.  
  31.    For secondary invocations with code sharing and group creation, only 
  32.    the tskmain and tskgrp routines are needed in the secondary (plus
  33.    the linkage routines in 'tskres'. All other routines can be shared.
  34.  
  35.    For secondary invocations without code sharing, some of the 
  36.    initialization code is not needed (installing the primary kernel
  37.    tasks and the interrupt handlers). This unneeded code is in 'tskinst',
  38.    which will not be linked if the 'SECONDARY' define is specified on
  39.    compilation of the tskmain module.
  40. */
  41.  
  42. /* --------------------------------------------------------------------- */
  43.  
  44. #include "tsk.h"
  45. #include "tsklocal.h"
  46. #include "tskdeb.h"
  47.  
  48. #if (DEBUG)
  49. #include "tskprf.h"
  50. #include "kbd.h"
  51. #endif
  52.  
  53. /* 
  54.    Installation flags. Local to the group.
  55. */
  56.  
  57. word Neardata tsk_instflags;
  58.  
  59. /* 
  60.    Global variable block. For secondary invocations, only the 'group'
  61.    gcb within this block is used. The real global variable block is
  62.    always indirectly accessed through the tsk_global pointer, and is the
  63.    same through all invocations.
  64.    Interrupt handlers and other system-related routines that
  65.    are only present in the primary invocation use this block directly.
  66. */
  67.  
  68. ctask_globvars Neardata tsk_glob_rec;
  69.  
  70. /*
  71.    Ctask active flag. Is 1 when CTask was installed, 0 otherwise.
  72.    Added in version 2.1 to support replacement alloc/free functions
  73.    as suggested by Joe Urso.
  74. */
  75.  
  76. int ctask_active = 0;
  77.  
  78. /* --------------------------------------------------------------------- */
  79.  
  80. /*
  81.    Debug support added in version 2.1 (moved here in version 2.2):
  82.       The DEB_TSKDIS define enables scheduler task display,
  83.       the DEB_FLASHERS define enables interrupt counting on the
  84.       display. Each entry has an associated hotkey entry, and
  85.       a common hotkey function, to toggle the display enable variable.
  86. */
  87.  
  88. #if (DEBUG & DEB_TSKDIS)
  89. local tlink tdebhotkey;
  90. int Neardata tsk_debtask = 1;
  91. #endif
  92. #if (DEBUG & DEB_FLASHERS)
  93. local tlink fdebhotkey;
  94. int Neardata tsk_debflash = 1;
  95. #endif
  96. #if (DEBUG)
  97. dword Neardata tsk_dtposn;
  98. #endif
  99.  
  100. #if ((DEBUG & (DEB_TSKDIS | DEB_FLASHERS)) && HOTKEYS)
  101. void Taskfunc debhotkey_proc (tlinkptr elem)
  102. {
  103.    *((wordptr)elem->user_parm) = !*((wordptr)elem->user_parm);
  104. }
  105. #endif
  106.  
  107. /* --------------------------------------------------------------------- */
  108.  
  109. /*
  110.    install_tasker
  111. */
  112.  
  113. int Globalfunc install_tasker (byte varpri, int speedup, word flags
  114.                                TN(byteptr name))
  115. {
  116. #if (GROUPS)
  117.    tcbptr ct;
  118. #endif
  119.    int rc;
  120.  
  121.    tsk_instflags = flags;
  122.  
  123. #if (DEBUG)
  124.   #if (DEBUG & DEB_SECOND)
  125.    tsk_set_dualdis ();
  126.   #else
  127.    tsk_set_currdis ();
  128.   #endif
  129.    if (tsk_regen_s)
  130.       {
  131.       tsk_setpos (0, 0);
  132.       tsk_rputc ('\f');
  133.       tsk_setpos (1, 0);
  134.       tsk_dtposn = tsk_regen;
  135.       }
  136. #endif
  137. #if (DEBUG & DEB_TSKDIS)
  138.    if (tsk_regen_s)
  139.       {
  140.       tsk_setpos (0, 0);
  141.       tsk_rprintf (DEBLINTD);
  142.       }
  143. #endif
  144. #if (DEBUG & DEB_FLASHERS)
  145.    if (tsk_regen_s)
  146.       {
  147.       tsk_setpos (0, DEBP_CNTSCHED / 2);
  148.       tsk_rprintf (DEBLINFL);
  149.       tsk_setpos (1, DEBP_CNTSCHED / 2);
  150.       tsk_rprintf (DEBINIFL);
  151.       }
  152. #endif
  153.  
  154. #if (GROUPS)
  155.  
  156.    tsk_memcpy (tsk_glob_rec.id, tsk_version, 8);
  157.  
  158.    if (ctask_resident ())
  159.       {
  160.       tsk_glob_rec.group.main_ptr = ct = GLOBDATA current_task;
  161.       tsk_create_group (&tsk_glob_rec.group, name);
  162.  
  163. #if (DOS)
  164.       tsk_glob_rec.group.save_psp = ct->base_psp;
  165.       tsk_glob_rec.group.save_sssp = ct->psp_sssp;
  166.       ct->base_psp = tsk_getpsp ();
  167. #endif
  168.  
  169. #if (TSK_DYNAMIC && TSK_DYNLOAD)
  170.       create_resource (&alloc_resource TN("ALLOCRSC"));
  171. #endif
  172.  
  173.       rc = 1;
  174.       }
  175.    else
  176.       {
  177. #if defined(SECONDARY)
  178.       return -1;
  179. #else
  180.       tsk_install_main (varpri, speedup, flags TN(name));
  181.       rc = 0;
  182. #endif
  183.       }
  184. #else
  185.    tsk_install_main (varpri, speedup, flags TN(name));
  186.    rc = 0;
  187. #endif /* groups */
  188.  
  189.    ctask_active = 1;
  190.  
  191. #if ((DEBUG & DEB_TSKDIS) && HOTKEYS)
  192.    create_hotkey_entry (&tdebhotkey, SCAN_T, 
  193.                         KF1_ALT | KF1_CONTROL | KF1_LEFTSHIFT, KF1_CONTROL | KF1_LEFTSHIFT,
  194.                         0, 0,
  195.                         0, 0,
  196.                         (farptr)debhotkey_proc, TKIND_PROC, 1, (farptr)&tsk_debtask);
  197. #endif
  198. #if ((DEBUG & DEB_FLASHERS) && HOTKEYS)
  199.    create_hotkey_entry (&fdebhotkey, SCAN_F, 
  200.                         KF1_ALT | KF1_CONTROL | KF1_LEFTSHIFT, KF1_CONTROL | KF1_LEFTSHIFT,
  201.                         0, 0,
  202.                         0, 0,
  203.                         (farptr)debhotkey_proc, TKIND_PROC, 1, (farptr)&tsk_debflash);
  204. #endif
  205.  
  206.    return rc;
  207. }
  208.  
  209.  
  210. /*
  211.    remove_tasker
  212.       Front-end for remove_group/tsk_remove_tasker.
  213.       Kills the current task group, and/or un-installs CTask.
  214. */
  215.  
  216. void Globalfunc remove_tasker (void)
  217. {
  218.  
  219. #if (GROUPS)
  220.    if (tsk_remove_group (GLOBDATA current_task->group, 0) == 1)
  221.       {
  222. #if defined(SECONDARY)
  223.       return;
  224. #else
  225.       tsk_kill_group (GLOBDATA current_task->group);
  226.       tsk_remove_tasker ();
  227. #endif
  228.       }
  229. #else
  230.    tsk_remove_tasker ();
  231. #endif
  232.  
  233.    ctask_active = 0;
  234. }
  235.  
  236.