semaphor.def

来自「Welcome to PMOS. PMOS is a set of module」· DEF 代码 · 共 52 行

DEF
52
字号
DEFINITION MODULE Semaphores;

	(********************************************************)
	(*							*)
	(*	Defines the semaphore data type, and the two	*)
	(*	basic operations on a semaphore.		*)
	(*							*)
	(*	Programmer:	P. Moylan			*)
	(*	Last edited:	24 March 1991			*)
	(*							*)
	(*	Status:		OK.				*)
	(*							*)
	(********************************************************)

TYPE Semaphore;		(* is private *)

PROCEDURE CreateSemaphore (VAR (*OUT*) s: Semaphore; InitialValue: CARDINAL);

    (* Creates semaphore s, with the given initial value and an empty	*)
    (* queue.								*)

PROCEDURE DestroySemaphore (VAR (*INOUT*) s: Semaphore);

    (* Reclaims any space used by semaphore s.  Remark:  It is not at	*)
    (* all obvious what should be done with any tasks which happen to	*)
    (* be blocked on this semaphore (should they be unblocked, or	*)
    (* killed?).  At present we take the easy way out and assume that	*)
    (* there are no pending operations on s at the time that it is	*)
    (* destroyed.							*)

PROCEDURE Wait (VAR (*INOUT*) s: Semaphore);

    (* Decrements the semaphore value.  If the value goes negative,	*)
    (* the calling task is blocked and there is a task switch.		*)

PROCEDURE TimedWaitT (VAR (*INOUT*) s: Semaphore;
			TimeLimit: INTEGER;  VAR (*OUT*) TimedOut: BOOLEAN);

    (* Like procedure Wait, except that it returns with TimedOut TRUE	*)
    (* if the corresponding Signal does not occur within TimeLimit	*)
    (* clock ticks.  Note that this procedure is not recommended for	*)
    (* general use, because "clock ticks" is not a convenient unit of	*)
    (* time for most callers.  For a more useful version, see procedure	*)
    (* TimedWait in module Timer.					*)

PROCEDURE Signal (VAR (*INOUT*) s: Semaphore);

    (* Increments the semaphore value.  Unblocks one waiting task,	*)
    (* if there was one.						*)

END Semaphores.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?