home *** CD-ROM | disk | FTP | other *** search
/ Frostbyte's 1980s DOS Shareware Collection / floppyshareware.zip / floppyshareware / DOOG / CTASK.ZIP / TSKLOCAL.H < prev    next >
C/C++ Source or Header  |  1989-12-20  |  7KB  |  224 lines

  1. /*
  2.     --- Version 2.0 89-12-15 15:08 ---
  3.  
  4.    TSKLOCAL.H - CTask - Internal definitions and prototypes.
  5.  
  6.    Public Domain Software written by
  7.       Thomas Wagner
  8.       Patschkauer Weg 31
  9.       D-1000 Berlin 33
  10.       West Germany
  11.  
  12.    CAUTION: Routines defined here may *not* be called from outside the
  13.             CTask kernel.
  14. */
  15.  
  16. /*
  17.    struct task_stack describes the contents of a tasks stack after creation.
  18.    The first 2 words are the registers to be restored by the scheduler.
  19.    Only the segment register is significant initially.
  20.    The next three words contain the function address plus the CPU flags
  21.    setup as if an interrupt had occurred at the function's entry address.
  22.  
  23.    This setup is the same as the stack of an interrupted task after
  24.    scheduling.
  25.  
  26.    The following two words contain a dummy return address, which points
  27.    to the routine "killretn". Thus, if the task main function should ever
  28.    return, the task is automatically killed. The last doubleword is
  29.    used for the optional argument to the task.
  30. */
  31.  
  32. struct task_stack {
  33.                   word     r_bx;
  34.                   word     r_ds;
  35.                   funcptr  retn;
  36.                   word     r_flags;
  37.                   funcptr  dummyret;
  38.                   farptr   arg;
  39.                   };
  40.  
  41. #if (CLOCK_MSEC)
  42. extern dword near tsk_timeout (dword tout);
  43. #else
  44. #define tsk_timeout(tout)  tout
  45. #endif
  46.  
  47. extern void near tsk_enqueue (queheadptr head, queptr elem);
  48. extern void near tsk_dequeue (queptr elem);
  49. extern void near tsk_enqtimer (queptr elem, dword tout);
  50. extern void near tsk_deqtimer (queptr elem);
  51. extern void near tsk_putqueue (queheadptr q, queptr elem);
  52.  
  53. extern void near tsk_install_timer (word divisor, word sys_ticks);
  54. extern void near tsk_remove_timer (void);
  55. extern void near tsk_chain_timer (void);
  56.  
  57. extern void near tsk_install_dos (void);
  58. extern void near tsk_remove_dos (void);
  59.  
  60. extern void near tsk_install_kbd (void);
  61. extern void near tsk_remove_kbd (void);
  62.  
  63. extern void near tsk_install_bios (void);
  64. extern void near tsk_remove_bios (void);
  65.  
  66. extern void near tsk_install_int17 (void);
  67. extern void near tsk_remove_int17 (void);
  68.  
  69. extern int near tsk_remove_group (gcbptr group, int freemem);
  70. extern void near tsk_free_mem (word psp);
  71.  
  72. extern void far tsk_emergency_exit (void);
  73.  
  74. #if (TURBO)
  75. #define tsk_dseg()   _DS
  76. #else
  77. extern word near tsk_dseg (void);
  78. #endif
  79.  
  80. extern word near tsk_flags (void);
  81.  
  82. extern void near tsk_runable (tcbptr task);
  83. extern void near tsk_runable_all (queheadptr que);
  84. extern void near tsk_wait (queheadptr que, dword timeout);
  85. extern void near tsk_kill (tcbptr task);
  86. extern void near tsk_kill_queue (queheadptr que);
  87. extern void near tsk_init_qhead (queheadptr head);
  88.  
  89. #if (TSK_NAMED)
  90. extern void near tsk_copy_name (nameptr elem, byteptr name);
  91. extern void near tsk_add_name (nameptr elem, byteptr name, byte kind,
  92.                               farptr strucp);
  93. extern void near tsk_del_name (nameptr elem);
  94. #endif
  95.  
  96. extern void far tsk_int8 (void);
  97. extern void far tsk_timer (void);
  98.  
  99. /* --------------------------------------------------------------------- */
  100.  
  101. /*
  102.                             The global variable block
  103.  
  104.     The task queues:
  105.  
  106.         timer_queue            All tasks using a timeout, either through "t_delay" 
  107.                                 or an event wait, are enqueued into "timer_queue",
  108.                                 using the "timerq" link.
  109.  
  110.         eligible_queue        All tasks eligible for running are enqueued 
  111.                                 in "eligible_queue".
  112.  
  113.         current_task        Points to the current running task's tcb.
  114.  
  115.    System flags:
  116.  
  117.       preempt             is zero if preemption is allowed.
  118.                           Bit 0 is set if preemption has been disabled globally.
  119.                           Bit 1 is set for temporary disabling preemption.
  120.                           Temporary preemption is automatically removed by the
  121.                           scheduler.
  122.  
  123.       pretick             is nonzero if a schedule request from an 
  124.                                 interrupt handler was rejected due to 
  125.                                 tsk_preempt nonzero. This allows an immediate 
  126.                                 scheduling whenever tsk_preempt is set to 0.
  127.  
  128.       var_prior           Can be set nonzero to enable variable priority.
  129.                           Variable priority will increase the priority of
  130.                           eligible tasks on each scheduler call while they
  131.                           are waiting to be executed, so that low priority 
  132.                           tasks will slowly get to the head of the eligible
  133.                           queue, getting a chance to be run. With variable
  134.                           priority off, lower priority tasks will never be
  135.                           executed while higher priority tasks are eligible.
  136.                     
  137.     System variables:
  138.  
  139.       in_sched            is used in the scheduler only. It is nonzero while
  140.                           the scheduler is active.
  141.  
  142.       tick_factor         is undefined if CLOCK_MSEC is 0, otherwise it 
  143.                                 contains the clock tick factor in milliseconds.
  144.  
  145.       ticks_per_sec      is the approximate number of ticks per second
  146.                                 expressed as an unsigned integer.
  147.  
  148.         l_swap                is set by tskdos and used by the scheduler.
  149.                                 It contains the length of the DOS swap area.
  150.                         (DOS only)
  151.  
  152.         dos_vars                contains the address of the DOS swap area.
  153.                         (DOS only)
  154.  
  155.         curr_group            is the current running task's group
  156.  
  157.       groups              is the group list head. It points to the most 
  158.                                 recently created group.
  159.  
  160.         name_list            is only present if TSK_NAMED is nonzero, and
  161.                         if there are no groups.
  162.                                 It is the head of the name queue.
  163.  
  164. */
  165.  
  166. #define VERSTRING "CTask12"   /* 7 Chars + zero */
  167.  
  168. typedef struct {
  169.                char     id [8];        /* contains 'VERSTRING' */
  170.  
  171.                tcbptr       current_task;
  172.                queue_head    eligible_queue;
  173.  
  174.                queue_head     timer_queue;
  175.                queue_head     watch_queue;
  176.  
  177.                byte     preempt;
  178.                byte     pretick;
  179.                byte     var_prior;
  180.  
  181.                byte     in_sched;
  182.  
  183.                double   tick_factor;
  184.                word     ticks_per_sec;
  185.                     tick_ptr    ticker_chain;
  186. #if (DOS)
  187.                     word        l_swap;
  188.                     dword        dos_vars;
  189. #endif
  190. #if (GROUPS)
  191.                gcbptr   curr_group;
  192.                gcb      group;
  193. #else
  194. #if (TSK_NAMED)
  195.                namerec  name_list;
  196. #endif
  197. #endif
  198.                } ctask_globvars;
  199.  
  200. typedef ctask_globvars far *globvarptr;
  201.  
  202.  
  203. extern counter _Near tsk_timer_counter;
  204. #if (DOS)
  205. extern counter _Near tsk_int8_counter;
  206. #endif
  207.  
  208. typedef void (cdecl far *funcptr_void)(void);
  209. typedef void (cdecl far *funcptr_void_fp)(farptr);
  210.  
  211. #if (SINGLE_DATA)
  212. extern ctask_globvars _Near tsk_glob_rec;
  213. #else
  214. extern globvarptr _Near tsk_global;
  215. extern globvarptr near tsk_resident (void);
  216. #endif
  217.  
  218. #if (SINGLE_DATA)
  219. #define  GLOBDATA        tsk_glob_rec.
  220. #else
  221. #define  GLOBDATA        tsk_global->
  222. #endif
  223.  
  224.