home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pmos2002.zip / DEF / taskcont.def < prev    next >
Text File  |  1997-11-04  |  6KB  |  129 lines

  1. DEFINITION MODULE TaskControl;
  2.  
  3.         (****************************************************************)
  4.         (*                                                              *)
  5.         (*   Data structures internal to the kernel of the operating    *)
  6.         (*     system; the dispatcher of the operating system; and      *)
  7.         (*                  related procedures.                         *)
  8.         (*                                                              *)
  9.         (*      Programmer:     P. Moylan                               *)
  10.         (*      Last edited:    4 November 1997                         *)
  11.         (*      Status:         Seems to be working                     *)
  12.         (*                                                              *)
  13.         (****************************************************************)
  14.  
  15. IMPORT OS2;
  16. FROM SYSTEM IMPORT ADDRESS;
  17.  
  18. (************************************************************************)
  19. (*                                                                      *)
  20. (*                         END-USER PROCEDURES                          *)
  21. (*                                                                      *)
  22. (************************************************************************)
  23.  
  24. CONST MaxPriority = 15;
  25.  
  26. TYPE
  27.     PriorityLevel = [0..MaxPriority];
  28.     NameString = ARRAY [0..15] OF CHAR;
  29.     PROC1 = PROCEDURE (ADDRESS);
  30.  
  31. PROCEDURE CreateTask (StartAddress: PROC;  taskpriority: PriorityLevel;
  32.                                                 taskname: NameString);
  33.  
  34.     (* Must be called to introduce a task to the system. The first      *)
  35.     (* parameter, which should be the name of a procedure containing    *)
  36.     (* the task code, gives the starting address.  The second parameter *)
  37.     (* is the task's base priority.  If this task has a higher priority *)
  38.     (* than its creator, it will run immediately.  Otherwise, it        *)
  39.     (* becomes ready.                                                   *)
  40.  
  41.     (* A task terminates itself either by an explicit call to TaskExit, *)
  42.     (* or simply by falling out of the bottom of its code.              *)
  43.     (* There is no provision for tasks to kill other tasks.  Suicide    *)
  44.     (* is legal, but murder is not.                                     *)
  45.  
  46. PROCEDURE CreateTask1 (StartAddress: PROC1;  taskpriority: PriorityLevel;
  47.                                    taskname: NameString;  param: ADDRESS);
  48.  
  49.     (* Like CreateTask, but allows the passing of a single parameter    *)
  50.     (* "param" to the task.                                             *)
  51.  
  52. PROCEDURE TaskExit;
  53.  
  54.     (* Removes the currently running task from the system, and performs *)
  55.     (* a task switch to the next ready task.                            *)
  56.  
  57.     (* There is normally no need for a task to call this procedure,     *)
  58.     (* because it is automatically called when the task code "falls out *)
  59.     (* the bottom" by executing its final procedure return.             *)
  60.  
  61. (************************************************************************)
  62. (*                                                                      *)
  63. (*                LOCKS FOR CRITICAL SECTION PROTECTION                 *)
  64. (*                                                                      *)
  65. (*  Note that we distinguish between a Lock and a Semaphore.            *)
  66. (*  A Semaphore is a general semaphore - whose operations are defined   *)
  67. (*  in module Semaphores - which can be used for general inter-task     *)
  68. (*  interlocking.  A Lock is similar to a binary semaphore (with a      *)
  69. (*  more efficient implementation than a Semaphore), but may be used    *)
  70. (*  only in a strictly nested fashion and is therefore useful only      *)
  71. (*  for critical section protection.                                    *)
  72. (*                                                                      *)
  73. (************************************************************************)
  74.  
  75. TYPE Lock;      (* is private *)
  76.  
  77. PROCEDURE CreateLock (VAR (*OUT*) L: Lock);
  78.  
  79.     (* Creates a new lock. *)
  80.  
  81. PROCEDURE DestroyLock (VAR (*INOUT*) L: Lock);
  82.  
  83.     (* Disposes of a lock. *)
  84.  
  85. PROCEDURE Obtain (L: Lock);
  86.  
  87.     (* Obtains lock L, waiting if necessary. *)
  88.  
  89. PROCEDURE Release (L: Lock);
  90.  
  91.     (* Releases lock L - which might unblock some other task. *)
  92.  
  93. PROCEDURE ReleaseAllLocks;
  94.  
  95.     (* Releases all locks held by the current task.  Application-level  *)
  96.     (* tasks normally won't need to call this procedure; it is          *)
  97.     (* provided to support the system shutdown function and for things  *)
  98.     (* like "emergency abort" operations.                               *)
  99.  
  100. (*
  101. PROCEDURE DumpLockState (L: Lock);
  102.  
  103.     (* Writes information about L to the dump file. *)
  104. *)
  105.  
  106. (************************************************************************)
  107. (*                  PROCEDURES PRIVATE TO THE KERNEL                    *)
  108. (************************************************************************)
  109.  
  110. TYPE TaskID = OS2.TID;
  111.  
  112. PROCEDURE CurrentTaskID(): TaskID;
  113.  
  114.     (* Returns the TaskID of the calling task. *)
  115.  
  116. PROCEDURE SuspendMe (id: TaskID;  TimeLimit: CARDINAL): BOOLEAN;
  117.  
  118.     (* Suspends the caller.  A TRUE result indicates that the time      *)
  119.     (* limit expired.                                                   *)
  120.  
  121. PROCEDURE ResumeTask (id: TaskID): BOOLEAN;
  122.  
  123.     (* Resumes a task specified by its thread ID.  The function result  *)
  124.     (* is normally TRUE, but is FALSE if the task couldn't be resumed   *)
  125.     (* (usually because that task no longer exists).                    *)
  126.  
  127. END TaskControl.
  128.  
  129.