示例#1
0
 /// <summary>
 /// do commit on the object itself
 /// </summary>
 /// <param name="TID"></param>
 /// <returns></returns>
 public bool Commit(long TID)
 {
     lock (this)
     {
         bool isCommited = false;
         Console.WriteLine("\n---------------Commit (START, TID=" + TID + " ,UID=" + this.Uid + ")-------------------");
         while (true)
         {
             if (TentativeList.Exists(x => x.WriteTS == TID))
             {
                 if (TentativeList.Exists(x => x.WriteTS < TID))
                 {
                     Console.WriteLine("Wait TID = " + TID);
                     Monitor.Wait(this);
                 }
                 else
                 {
                     TentativePadInt temp = TentativeList.Find(x => x.WriteTS == TID);
                     this.Value      = temp.Value;
                     this.WriteTS    = temp.WriteTS;
                     this.IsCommited = true;
                     tentativeList.Remove(temp);
                     Monitor.PulseAll(this);
                     isCommited = true;
                     Console.WriteLine("commited TID : " + TID + ", Value = " + Value);
                     break;
                 }
             }
             else
             {
                 Console.WriteLine("TID is not in this object to commit");
                 isCommited = true;
                 break;
             }
         }
         Console.WriteLine("---------------Commited (End, TID=" + TID + ")-------------------\n");
         return(isCommited);
     }
 }
示例#2
0
 /// <summary>
 /// Do write on the object itself
 /// </summary>
 /// <param name="TID"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public bool Write(long TID, int value)
 {
     lock (this)
     {
         bool isWriteSuccessful = false;
         Console.WriteLine("\n---------------Write (START, TID=" + TID + ")-------------------");
         Console.WriteLine("ReadTSList count = " + ReadTSList.Count());
         Console.WriteLine("WriteTS = " + WriteTS);
         Console.WriteLine("TID = " + TID);
         Console.WriteLine("UID = " + this.Uid);
         Console.WriteLine("Committed Version Value = " + this.Value);
         if ((ReadTSList.Count() == 0 || TID >= ReadTSList.Max()) && TID > WriteTS)
         {
             if (TentativeList.Exists(x => x.WriteTS == TID))
             {
                 TentativeList.First(x => x.WriteTS == TID).Value = value;
                 Console.WriteLine("Already in tentativelist, value updated TID = " + TID + ", Value = " + value);
             }
             else
             {
                 TentativePadInt tentative = new TentativePadInt(TID, value);
                 TentativeList.Add(tentative);
                 Console.WriteLine("Added to tentativelist TID = " + TID + ", Value = " + value);
             }
             isWriteSuccessful = true;
         }
         else
         {
             TxAbort(TID);
             Console.WriteLine("Transaction aborts. TID = " + TID);
             Common.Logger().LogInfo("Write aborted TID=" + TID, string.Empty, string.Empty);
         }
         Console.WriteLine("---------------Write (END, TID=" + TID + ")-------------------\n");
         return(isWriteSuccessful);
     }
 }