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

  1. DEFINITION MODULE Semaphores;
  2.  
  3.         (********************************************************)
  4.         (*                                                      *)
  5.         (*      Defines the semaphore data type, and the two    *)
  6.         (*      basic operations on a semaphore.                *)
  7.         (*                                                      *)
  8.         (*      Programmer:     P. Moylan                       *)
  9.         (*      Last edited:    11 May 1997                     *)
  10.         (*      Status:         OK                              *)
  11.         (*                                                      *)
  12.         (********************************************************)
  13.  
  14. FROM TaskControl IMPORT TaskID;
  15.  
  16. TYPE Semaphore;         (* is private *)
  17.  
  18. (*
  19. PROCEDURE DumpSemaphoreState (s: Semaphore);
  20.  
  21.     (* Writes information about s to the dump file. *)
  22. *)
  23.  
  24. PROCEDURE CreateSemaphore (VAR (*OUT*) s: Semaphore; InitialValue: CARDINAL);
  25.  
  26.     (* Creates semaphore s, with the given initial value and an empty   *)
  27.     (* queue.                                                           *)
  28.  
  29. PROCEDURE DestroySemaphore (VAR (*INOUT*) s: Semaphore);
  30.  
  31.     (* Reclaims any space used by semaphore s.  Remark:  It is not at   *)
  32.     (* all obvious what should be done with any tasks which happen to   *)
  33.     (* be blocked on this semaphore (should they be unblocked, or       *)
  34.     (* killed?).  At present we take the easy way out and assume that   *)
  35.     (* there are no pending operations on s at the time that it is      *)
  36.     (* destroyed.                                                       *)
  37.  
  38. PROCEDURE Wait (s: Semaphore);
  39.  
  40.     (* Decrements the semaphore value.  If the value goes negative,     *)
  41.     (* the calling task is blocked and there is a task switch.          *)
  42.  
  43. PROCEDURE TimedWaitT (s: Semaphore;
  44.                         TimeLimit: INTEGER;  VAR (*OUT*) TimedOut: BOOLEAN);
  45.  
  46.     (* Like procedure Wait, except that it returns with TimedOut TRUE   *)
  47.     (* if the corresponding Signal does not occur within TimeLimit      *)
  48.     (* clock ticks.  Note that this procedure is not recommended for    *)
  49.     (* general use, because "clock ticks" is not a convenient unit of   *)
  50.     (* time for most callers.  For a more useful version, see procedure *)
  51.     (* TimedWait in module Timer.                                       *)
  52.  
  53. PROCEDURE Signal (s: Semaphore);
  54.  
  55.     (* Increments the semaphore value.  Unblocks one waiting task,      *)
  56.     (* if there was one.                                                *)
  57.  
  58. PROCEDURE SemaphoreHolder (s: Semaphore): TaskID;
  59.  
  60.     (* Returns the Task ID of the current holder of s.  The result is   *)
  61.     (* 0 if there is no current holder.  For the purposes of this       *)
  62.     (* procedure, the holder of s is defined to be the last task to     *)
  63.     (* have passed a wait on s.  The Signal(s) operation sets the       *)
  64.     (* state back to "no current holder".                               *)
  65.  
  66. END Semaphores.
  67.  
  68.