Exemplo n.º 1
0
            public void Dispose()
            {
                lock (Semaphores)
                {
                    --RefCount;

                    if (RefCount == 0)
                    {
                        Semaphores.Remove(Key);
                    }
                }

                Semaphore.Release();
            }
Exemplo n.º 2
0
            public void Dispose()
            {
                RefCounted <SemaphoreSlim> item;

                lock (Semaphores)
                {
                    item = Semaphores[Key];
                    --item.RefCount;
                    if (item.RefCount == 0)
                    {
                        Semaphores.Remove(Key);
                    }
                }
                item.Value.Release();
            }
Exemplo n.º 3
0
            public void Dispose()
            {
                Holder holder = null;

                lock (Semaphores)
                {
                    holder = Semaphores[Key];
                    --holder.References;

                    if (holder.References == 0)
                    {
                        Semaphores.Remove(Key);
                    }
                }

                holder.Semaphore.Release();
            }
Exemplo n.º 4
0
        /// <summary>
        /// Removes all elements in scope from the instance.
        /// </summary>
        /// <param name="theTier">The tier to remove the elements from.</param>
        /// <param name="xMin">The min x-value of the scope.</param>
        /// <param name="xMax">The max x-value of the scope.</param>
        /// <param name="yMin">The min y-value of the scope.</param>
        /// <param name="yMax">The max y-value of the scope.</param>
        public void ModRemoveWaypoints(ITierInfo theTier, double xMin, double yMin, double xMax, double yMax)
        {
            Tier tier = theTier as Tier;
            // Remove waypoints
            List <Waypoint> remWaypoints = Waypoints.Where(w => w.Tier == tier && xMin <= w.X && w.X <= xMax && yMin <= w.Y && w.Y <= yMax).ToList();

            // Remove all of them
            foreach (var waypoint in remWaypoints)
            {
                // Remove the waypoint - the waypoint graph handles all cascading path removals
                waypoint.Tier.RemoveWaypoint(waypoint);
                // Remove all elements that were connected to the waypoint
                foreach (var guard in Semaphores.SelectMany(s => s.Guards).Where(guard => guard.From == waypoint || guard.To == waypoint).ToArray())
                {
                    guard.Semaphore.UnregisterGuard(guard);
                    if (guard.Semaphore.Guards.Count() == 0)
                    {
                        Semaphores.Remove(guard.Semaphore);
                    }
                }
                foreach (var station in InputStations.Where(s => s.Waypoint == waypoint).ToArray())
                {
                    station.Tier.RemoveInputStation(station);
                    InputStations.Remove(station);
                }
                foreach (var station in OutputStations.Where(s => s.Waypoint == waypoint).ToArray())
                {
                    station.Tier.RemoveOutputStation(station);
                    OutputStations.Remove(station);
                }
                foreach (var pod in Pods.Where(p => p.Waypoint == waypoint).ToArray())
                {
                    pod.Tier.RemovePod(pod);
                    Pods.Remove(pod);
                }
                foreach (var elevator in Elevators.Where(e => e.ConnectedPoints.Contains(waypoint)))
                {
                    elevator.UnregisterPoint(waypoint);
                    if (elevator.ConnectedPoints.Count == 0)
                    {
                        Elevators.Remove(elevator);
                    }
                }
                // Make sure it is not on the list of storage locations anymore
                if (waypoint.PodStorageLocation)
                {
                    ResourceManager.RemovePodStorageLocation(waypoint);
                }
                // Finally remove from the overall waypoint list
                Waypoints.Remove(waypoint);
            }
            // Also remove movables in scope
            List <Bot> remBots = Bots.Where(b => b.Tier == tier && xMin <= b.X && b.X <= xMax && yMin <= b.Y && b.Y <= yMax).ToList();

            foreach (var bot in remBots)
            {
                Bots.Remove(bot);
                bot.Tier.RemoveBot(bot);
            }
            List <Pod> remPods = Pods.Where(p => p.Tier == tier && xMin <= p.X && p.X <= xMax && yMin <= p.Y && p.Y <= yMax).ToList();

            foreach (var pod in remPods)
            {
                Pods.Remove(pod);
                pod.Tier.RemovePod(pod);
            }
        }
Exemplo n.º 5
0
 public void Dispose()
 {
     this._semaphore.Release();
     Semaphores.Remove(this._value, out _);
 }