home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / p / pcrte224.zip / SOURCE.ZIP / TASKS.INC < prev    next >
Text File  |  1992-06-09  |  3KB  |  107 lines

  1. ;;**************************************************************************
  2. ;;                          tasks.inc    tasks.inc
  3. ;;**************************************************************************
  4. ;; 
  5. ;;*************************************************************************
  6. ;;
  7. ;;  Copyright (C) 1989 Northwestern University, Vance Morrison
  8. ;;
  9. ;;
  10. ;; Permission to view, compile, and modify for LOCAL (intra-organization) 
  11. ;; USE ONLY is hereby granted, provided that this copyright and permission 
  12. ;; notice appear on all copies.  Any other use by permission only.
  13. ;;
  14. ;; Northwestern University makes no representations about the suitability 
  15. ;; of this software for any purpose.  It is provided "as is" without expressed 
  16. ;; or implied warranty.  See the copywrite notice file for complete details.
  17. ;;
  18. ;;**************************************************************************
  19. ;;
  20. ;; tasks.inc is the module that provides the multitasking capability for
  21. ;; programs.  These really aren't even tasks anymore, they are simply 
  22. ;; a nice way of breaking up the program.
  23. ;;
  24. ;; This module assumes that there will be only one scheduler.  
  25. ;;
  26. ;; The routines declared here dealing with the task scheduler
  27. ;;
  28. ;;   SCHED_DECLARE num_tasks
  29. ;;   TASK_DEFINE task, code
  30. ;;   TASK_RETURN task
  31. ;;   SCHED_RUN 
  32. ;;
  33. ;;**************************************************************************
  34.  
  35.  
  36. ;;****************************************************************************
  37. ;; SCHED_DECLARE num_tasks
  38. ;;
  39. ;;  SCHED_DECLARE declares a task scheduler that has 'num_tasks' in its
  40. ;;  run queue.  This scheduler is VERY light and VERY primitive.  The
  41. ;;  tasks are aways run bound and the run queue never changes.  Even so
  42. ;;  this is sufficient for the PCrouter.
  43.  
  44. SCHED_DECLARE   MACRO num_tasks
  45.     .errb <num_tasks>
  46.  
  47. sched_num_tasks = num_tasks
  48.  
  49.     IRP idx, <1,2,3,4,5,6,7,8,9>
  50.     if idx le num_tasks
  51.         SCHED_HELPER idx
  52.     endif
  53.     endm
  54. ENDM
  55.  
  56. SCHED_HELPER MACRO task
  57.     .CODE
  58.     global sched_task_&task:near
  59. ENDM
  60.  
  61. ;;****************************************************************************
  62. ;; SCHED_RUN 
  63. ;;
  64. ;;  SCHED_RUN runs the tasks in the run queue.  This routine is meant to
  65. ;;  be called after all the tasks have been defined with TASK_DEFINE
  66. ;;  and you wish to begin scheduling.  The macro NEVER returns.
  67. ;;
  68. SCHED_RUN   MACRO 
  69.     jmp sched_task_1
  70. ENDM
  71.  
  72.  
  73. ;;****************************************************************************
  74. ;; TASK_DEFINE task, code
  75. ;;
  76. ;; TASK_DEFINE defines the task 'task' (which must be a number from 
  77. ;; 1..num_tasks) to start at the label 'code'.   This code will be 
  78. ;; run when 'SCHED_RUN is called
  79. ;;
  80. TASK_DEFINE MACRO task, code
  81.     .errb <code>
  82.  
  83. sched_task_&task = code
  84. ENDM
  85.  
  86. ;;****************************************************************************
  87. ;; TASK_RETURN task
  88. ;;
  89. ;; TASK_RETURN is to be called when the task wants to reliquish control
  90. ;; of the CPU.  NOTE THAT CONTROL WILL BE GIVEN BACK AT THE STARTING
  91. ;; POINT NOT AT THE POINT OF THE TASK_RETURN CALL
  92. ;;
  93. TASK_RETURN MACRO task
  94.     .errb <task>
  95.  
  96.     new_task = task + 1
  97.     if new_task gt sched_num_tasks
  98.         new_task = 1
  99.     endif
  100.     TASK_HELPER task, %new_task
  101. ENDM
  102.  
  103. TASK_HELPER MACRO task, new_task
  104.     jmp sched_task_&new_task
  105. ENDM
  106.  
  107.