Library mcertikos.objects.BigLogThreadConfigFunction


Require Import Coqlib.
Require Import Maps.
Require Import AuxStateDataType.
Require Import FlatMemory.
Require Import Values.
Require Import Memory.
Require Import AuxLemma.
Require Import Constant.
Require Import GlobIdent.
Require Export GlobalOracle.
Require Import Integers.
Require Import BigStepGlobalOracle.
Require Import CalRealProcModule.

Fixpoint B_GetContainerUsed_aux (tid: Z) (cid : Z) (l: BigLog) : bool :=
  match l with
    | nilfalse
    | TBEVENT cpuid e ::
      match e with
      | TBSHARED (BTDSPAWN _ new_id _ _ _ _) ⇒
        if zeq cid cpuid then
          if zeq tid new_id then true else B_GetContainerUsed_aux tid cid
        else B_GetContainerUsed_aux tid cid
      | _B_GetContainerUsed_aux tid cid
      end
  end.

Definition B_GetContainerUsed (tid: Z) (cid : Z) (l: BigLog) : bool :=
  
  if zeq tid (cid + 1) then true
  else if zle_le 0 tid TOTAL_CPU then false
       else B_GetContainerUsed_aux tid cid l.

Definition B_GetContainerUsed_opt (tid : option Z) (cid : Z) (l : BigLog) : bool :=
  match tid with
    | Nonefalse
    | Some tid´B_GetContainerUsed tid´ cid l
  end.

Fixpoint B_GetlastPush_aux (cpuid : Z) (l: BigLog):=
  match l with
    | nilCalRealProcModule.real_syncchpool (ZMap.init SyncChanUndef)
    | TBEVENT tid e ::
      let res := B_GetlastPush_aux cpuid in
      match e with
        | TBLOCK _ (BREL_LOCK _ ) ⇒
          if zeq tid cpuid then else res
        | TBSHARED (BTDSLEEP _ _ ) ⇒
          if zeq tid cpuid then else res
        | _res
      end
  end.

Definition B_GetlastPush (cpuid: Z) (l : BigLogType) :=
  match l with
  | BigUndef ⇒ (ZMap.init SyncChanUndef)
  | BigDef B_GetlastPush_aux cpuid
  end.

Fixpoint B_inLock_aux (cpuid : Z) (l : BigLog) :=
  match l with
    | nilfalse
    | TBEVENT tid e ::
      match e with
       | TBLOCK _ (BWAIT_LOCK _ _) ⇒
         if zeq tid cpuid then true else B_inLock_aux cpuid
       | TBSHARED (BTDWAKE _ _) ⇒
         if zeq tid cpuid then true else B_inLock_aux cpuid
       | TBSHARED (BTDWAKE_DIFF _ _ _ _) ⇒
         if zeq tid cpuid then true else B_inLock_aux cpuid
       | TBSHARED (BBUFFERE _ _ _) ⇒
         if zeq tid cpuid then true else B_inLock_aux cpuid
       | _if zeq tid cpuid then false else B_inLock_aux cpuid
      end
  end.

Definition B_inLock (cpuid: Z) (l : BigLogType) :=
  match l with
  | BigUndeffalse
  | BigDef B_inLock_aux cpuid
  end.