/*
 * 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.
 * 
 */

Function GetState(Var i: INFO):STATE;
Begin
	return i.State;
End;

Procedure SetState(Var i: INFO; st: STATE);
Begin
	i.State := st;
End;

Procedure IncSharer(Var i: INFO; n : NODE);
Begin
	Assert(i.NumSharers = i.Bitvec.Cnt) "In IncSharers numsharers != count";
	i.IsOwned := false;
	Undefine i.Owner;
	BV_Include(i.Bitvec, n);
	i.NumSharers := i.NumSharers + 1;
	Assert(i.NumSharers = i.Bitvec.Cnt) "Out IncSharers numsharers != count";
End;

Function InSharers(Var i: INFO; n : NODE): BOOLEAN;
Begin
	Assert(i.NumSharers = i.Bitvec.Cnt) "In InSharers numsharers != count";
	return BV_IsMember(i.Bitvec, n);
End;

Function NotInSharers(Var i: INFO; n : NODE): BOOLEAN;
Begin
	Assert(i.NumSharers = i.Bitvec.Cnt) "In NotInSharers numsharers != count";
	return (!BV_IsMember(i.Bitvec, n));
End;

Procedure DelSharer(Var i: INFO; n : NODE);
Begin
	Assert(i.NumSharers = i.Bitvec.Cnt) "In DelSharer numsharers != count";
	Assert(InSharers(i, n)) "DelSharer: Cant delete non-sharer";
	BV_Delete(i.Bitvec, n);
	i.NumSharers := i.NumSharers - 1;
	Assert(i.NumSharers = i.Bitvec.Cnt) "Out DelSharer numsharers != count";
End;

Function NumSharers(Var i:INFO):INTEGER;
Begin
	Assert(i.NumSharers = i.Bitvec.Cnt) "In NumSharers numsharers != count";
	return i.NumSharers;
End;

Function GetSharers(Var i:INFO):SHARER_LIST;
Begin
	Assert(i.NumSharers = i.Bitvec.Cnt) "In GetSharers numsharers != count";
	return i.Bitvec;
End;

Function GetOwner(Var i:INFO): NODE;
Begin
	return i.Owner;
End;

Function GetSS(id: ID): NODE;
Begin
	return SSMap[id];
End;

Function GetSS2 (id: ID; xreq: XpotReqP_t): NODE;
Begin
	return SSMap[id];
End;

Procedure DelOwner(Var i:INFO);
Begin
	Assert(i.IsOwned = true);
	Undefine i.Owner;
	i.IsOwned := false;
End;

Procedure SetOwner(Var i:INFO; n:NODE);
Begin
	Assert(i.IsOwned = false);
	Assert(Isundefined(i.Owner)) "SetOwner: Already have an owner";
	Assert(i.NumSharers = 0) "SetOwner: there are sharers";
	i.Owner := n;
	i.IsOwned := true;
End;

/*
 *------------------------------------------------------------------
 *
 * PickCachingNode --
 *
 *          Return any NODE that is caching the 
 *          block tracked by this info.
 *          The node can be from either the
 *          sharers list or the owner (if any).
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      None.
 *
 *------------------------------------------------------------------
 */
Function PickCachingNode(i:INFO): NODE;
Begin
	if (i.IsOwned)
	Then
		return i.Owner;
        Else
		return BV_PickMember(i.Bitvec);
	Endif
End;

Function SameNode(n1: NODE; n2: NODE): BOOLEAN;
Begin
	return (n1 = n2);
End;








-- stuff related to itor

Procedure ShItorInit(Var itor: SHARER_LIST_ITOR; sh: SHARER_LIST; num: INTEGER);
Begin
	itor.Num := 0;
	While (itor.Num < num) Do
		Assert(!Isundefined(sh.Sh[itor.Num])) "Itor Init copies undefined element";
		itor.Sh[itor.Num] := sh.Sh[itor.Num];
		itor.Num := itor.Num + 1;
	End;
	itor.Cur := 0;
End;

Function ShItorNext(Var itor: SHARER_LIST_ITOR; Var j : NODE): BOOLEAN;
Begin
	If (itor.Cur < itor.Num)
	Then
		j := itor.Sh[itor.Cur];
		Undefine itor.Sh[itor.Cur];
		itor.Cur := itor.Cur + 1;
		Assert(!Isundefined(j)) "Itor Next returns undefined node";
		return true;
	Else	
		return false;
	Endif
End;

Procedure IncHomeRdMiss();
Begin
End;
Procedure IncHomeWrMiss();
Begin
End;
Procedure IncHomeWrRoMiss();
Begin
End;
Procedure IncCacheRdMiss();
Begin
End;
Procedure IncCacheWrMiss();
Begin
End;
Procedure IncCacheWrRoMiss();
Begin
End;
Procedure InterruptsOn();
Begin
End;
Procedure InterruptsOff();
Begin
End;
