/*
 * Copyright (c) 1996 by Satish Chandra, Brad Richards, Mark D. Hill, 
 * James R. Larus, and David A. Wood.
 *
 * Teapot is distributed under the following conditions:
 * 
 *     You may make copies of Teapot for your own use and modify those copies.
 * 
 *     All copies of Teapot must retain our names and copyright notice.
 * 
 *     You may not sell Teapot or distributed Teapot in conjunction with a
 *     commercial product or service without the expressed written consent of
 *     the copyright holders.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 * 
 */
Procedure Barrier(n : NODE);
Var
    	AllArrived : BOOLEAN;
Begin
	Nodes[n].AtBarrier := true;	

	AllArrived := true;
	For j : NODE Do
	    If (!Nodes[j].AtBarrier) Then
		AllArrived := false;
	    Endif;
	End; -- For

	If (AllArrived) Then			-- everybody is at barrier
	    For j : NODE Do		
	        Nodes[j].AtBarrier := false;	-- start all procs
	        Nodes[j].Blocked := false;

	        -- Do a RESET on the linked cache blocks on each node.
	        -- Also clear the Murfi access history as appropriate.

	        cur_node := j;
	        cur_msg.MType := RESET; 	-- should it need to enqueue
	        For a : ID Do
	    	    cur_id := a;
		    DispatchState(Nodes[j].Dram[a].State, RESET, a, 
				  Nodes[j].Dram[a], HomeMap[a]);
	            History[a].readers[j] := False;
	            History[a].writers[j] := False;
		    Undefine History[a].writer;		
	        End;
	    End; 
	Else
	    Nodes[n].Blocked := true; 	-- wait for everybody else
	Endif;
End;
