示例#1
0
 public void EnterNextHolder <TKey>(TKey localkey, Func <ulong, TKey, QueuedMessage, Stopwatch, MessageType, ulong, bool> entering)
 {
     // move head forward past all entries that immediately leave the lock after entering
     while (head != null && !entering(head.Request.Opid, localkey, head.Request, head.Stopwatch, head.Request.MessageType, head.Request.Parent))
     {
         if (head.Request.MessageType.IsFork())
         {
             Process.FinishStates[head.Request.Parent].RemovePending(head.Request.Opid);
         }
         head = head.Next;
         continue;
     }
 }
示例#2
0
        public void Enqueue(QueuedMessage request, Stopwatch stopwatch)
        {
            Process.LockTracer?.Invoke($"p{Process.ProcessId:D3} {request.GetPartitionKey(Process)} Enqueue {request.Opid}");
            var rinfo = new RInfo()
            {
                Request   = request,
                Stopwatch = stopwatch,
            };

            if (head == null)
            {
                head = tail = rinfo;
            }
            else
            {
                tail.Next = rinfo;
                tail      = rinfo;
            }
        }
示例#3
0
        public JObject Get()
        {
            var lines = System.IO.File.ReadAllLines("RestInfoTable.txt");

            RInfo[] restaurants = new RInfo[lines.Length];

            for (int i = 0; i < lines.Length; i++)
            {
                string[] restaurantInfo = lines[i].Split("||");
                string   address        = restaurantInfo[0];
                string   name           = restaurantInfo[1];
                string[] timeSlotsUgly  = restaurantInfo[2].Split(" ");
                int[]    timeSlots      = new int[timeSlotsUgly.Length];
                for (int j = 0; j < timeSlotsUgly.Length; j++)
                {
                    Console.WriteLine(name + " " + timeSlotsUgly[j]);
                    timeSlots[j] = int.Parse(timeSlotsUgly[j]);
                }
                int    capacity  = int.Parse(restaurantInfo[3]);
                Food[] foodItems = new Food[(restaurantInfo.Length - 4) / 4];
                for (int j = 4; j < restaurantInfo.Length; j += 4)
                {
                    string[] itemsUgly = restaurantInfo[j].Split(" ");
                    int[]    items     = new int[itemsUgly.Length];
                    for (int k = 0; k < items.Length; k++)
                    {
                        items[k] = int.Parse(itemsUgly[k]);
                    }
                    string description = restaurantInfo[j + 1];
                    string foodName    = restaurantInfo[j + 2];
                    float  price       = float.Parse(restaurantInfo[j + 3]);

                    Console.WriteLine(description + " " + foodName + " " + price + " " + items.ToString());
                    foodItems[(j - 1) / 4] = new Food(description, foodName, price, items);
                }
                restaurants[i] = new RInfo(address, name, capacity, timeSlots, foodItems);
            }
            string json = "{ restaurants: " + JsonConvert.SerializeObject(restaurants) + " }";

            return(JObject.Parse(json));
        }
示例#4
0
        public void Update <TKey>(TKey localkey, ProtocolMessage protocolMessage)
        {
            if (head == null)
            {
                throw new Exception("internal error: received update for request not holding lock");
            }

            head.Request.Update(Process, localkey, protocolMessage, head.Stopwatch, out var exiting);

            while (exiting)
            {
                head.Request.OnExit(Process);
                head = head.Next;

                if (head == null)
                {
                    return;
                }

                head.Request.OnEnter(Process);
                head.Request.Enter(Process, localkey, head.Stopwatch, out exiting);
            }
        }
示例#5
0
 public void Remove(ulong opid, out QueuedMessage msg)
 {
     if (head.Request.Opid == opid)
     {
         msg  = head.Request;
         head = head.Next;
     }
     else
     {
         var pos = head;
         while (pos.Next.Request.Opid != opid)
         {
             pos = pos.Next;
         }
         msg = pos.Next.Request;
         if (tail == pos.Next)
         {
             tail = pos;
         }
         pos.Next = pos.Next.Next;
     }
     Process.LockTracer?.Invoke($"p{Process.ProcessId:D3} {msg.GetPartitionKey(Process)} Removed {opid}");
 }