コード例 #1
0
        public MyUpdateData()
        {
            m_frameDataPool   = new MyConcurrentPool <MyUpdateFrame>(5, true);
            m_updateDataQueue = new MyConcurrentQueue <MyUpdateFrame>(5);

            CurrentUpdateFrame = m_frameDataPool.Get();
        }
コード例 #2
0
        public MyReceiveQueue(int channel, Action <ulong> disconnectPeerOnError, Mode readMode = Mode.Synchronized, int defaultMessageCount = 1,
                              Func <MyTimeSpan> timestampProvider = null)
        {
#if !XB1
            Trace.Assert(readMode != Mode.Spin, "Spin mode should be used only for testing purposes, it keeps CPU under heavy load!");
#else // XB1
            System.Diagnostics.Debug.Assert(readMode != Mode.Spin, "Spin mode should be used only for testing purposes, it keeps CPU under heavy load!");
#endif // XB1

            Disposed = false;
            Channel  = channel;
            ReadMode = readMode;

            m_messagePool           = new MyConcurrentPool <Message>(defaultMessageCount, true);
            m_receiveQueue          = new MyConcurrentQueue <Message>(defaultMessageCount);
            m_timestampProvider     = timestampProvider;
            m_disconnectPeerOnError = disconnectPeerOnError;

            if (readMode == Mode.Spin)
            {
                m_readThread = new Thread(ReceiveThread);
                m_readThread.CurrentCulture   = CultureInfo.InvariantCulture;
                m_readThread.CurrentUICulture = CultureInfo.InvariantCulture;
                m_readThread.Start();
            }
            else if (readMode == Mode.Timer)
            {
                m_timerAction = new Action(ReceiveTimer);
                m_timer       = new MyTimer(1, m_timerAction);
                m_timer.Start();
            }
        }
コード例 #3
0
        public MyReceiveQueue(int channel, Mode readMode = Mode.Synchronized, int defaultMessageCount = 1, Func<TimeSpan> timestampProvider = null)
        {
#if !XB1
            Trace.Assert(readMode != Mode.Spin, "Spin mode should be used only for testing purposes, it keeps CPU under heavy load!");
#else // XB1
            System.Diagnostics.Debug.Assert(readMode != Mode.Spin, "Spin mode should be used only for testing purposes, it keeps CPU under heavy load!");
#endif // XB1

            Disposed = false;
            Channel = channel;
            ReadMode = readMode;

            m_messagePool = new MyConcurrentPool<Message>(defaultMessageCount, true);
            m_receiveQueue = new MyConcurrentQueue<Message>(defaultMessageCount);
            m_timestampProvider = timestampProvider;

            if (readMode == Mode.Spin)
            {
                m_readThread = new Thread(ReceiveThread);
                m_readThread.CurrentCulture = CultureInfo.InvariantCulture;
                m_readThread.CurrentUICulture = CultureInfo.InvariantCulture;
                m_readThread.Start();
            }
            else if (readMode == Mode.Timer)
            {
                m_timerAction = new Action(ReceiveTimer);
                m_timer = new MyTimer(1, m_timerAction);
                m_timer.Start();
            }
        }
コード例 #4
0
        public void InitWriteCache(int prealloc = 128)
        {
            //Debug.Assert(m_cachedChunks == null, "Error: Cache already initialized"); disabled due to shared storages

            if (m_cachedChunks != null)
            {
                return;
            }

            if (OperationsComponent != null)
            {
                CachedWrites = true;
            }
            else
            {
                return;
            }

            m_cachedChunks         = new MyConcurrentDictionary <Vector3I, VoxelChunk>(prealloc, Vector3I.Comparer);
            m_pendingChunksToWrite = new MyConcurrentQueue <Vector3I>(prealloc / 10);
            m_chunksbyAge          = new MyQueue <Vector3I>(prealloc);

            m_cacheMap = new MyDynamicAABBTree(Vector3.Zero);

            m_cacheLock = new FastResourceLock();

            OperationsComponent.Add(this);
        }
コード例 #5
0
 public void StartFromTo(MyConcurrentQueue <HashFunctionResult> stash,
                         ConnectionWith wrCon)
 {
     this.stash      = stash;
     this.connection = wrCon;
     thread          = new Thread(new ThreadStart(() =>
     {
         try
         {
             while (stash.Count > 0 || stash.IsProducering)
             {
                 AddingDataFromStash();
             }
         }
         catch (Exception e) { HandleException(e); }
         finally
         {
             if (verbose)
             {
                 Console.WriteLine($"Thrd<{Thread.CurrentThread.ManagedThreadId}>-Writer: FINISHED his work.");
             }
         }
     }));
     thread.Start();
 }
コード例 #6
0
ファイル: MyUpdateData.cs プロジェクト: fluxit/SpaceEngineers
        public MyUpdateData()
        {
            m_frameDataPool = new MyConcurrentPool<MyUpdateFrame>(5, true);
            m_updateDataQueue = new MyConcurrentQueue<MyUpdateFrame>(5);

            CurrentUpdateFrame = m_frameDataPool.Get();
        }
コード例 #7
0
        public MyReceiveQueue(int channel, Mode readMode = Mode.Synchronized, int defaultMessageCount = 1, Func <TimeSpan> timestampProvider = null)
        {
            Trace.Assert(readMode != Mode.Spin, "Spin mode should be used only for testing purposes, it keeps CPU under heavy load!");

            Disposed = false;
            Channel  = channel;
            ReadMode = readMode;

            m_messagePool       = new MyConcurrentPool <Message>(defaultMessageCount, true);
            m_receiveQueue      = new MyConcurrentQueue <Message>(defaultMessageCount);
            m_timestampProvider = timestampProvider;

            if (readMode == Mode.Spin)
            {
                m_readThread = new Thread(ReceiveThread);
                m_readThread.CurrentCulture   = CultureInfo.InvariantCulture;
                m_readThread.CurrentUICulture = CultureInfo.InvariantCulture;
                m_readThread.Start();
            }
            else if (readMode == Mode.Timer)
            {
                m_timerAction = new Action(ReceiveTimer);
                m_timer       = new MyTimer(1, m_timerAction);
                m_timer.Start();
            }
        }
コード例 #8
0
        public void Return(IMyRenderMessage message)
        {
            MyConcurrentQueue <IMyRenderMessage> queue = base[(int)message.MessageType];

            if (queue.Count < 2048)
            {
                queue.Enqueue(message);
            }
        }
コード例 #9
0
 public MySourceVoicePool(XAudio2 audioEngine, WaveFormat waveformat, MyCueBank owner)
 {
     m_audioEngine     = audioEngine;
     m_waveFormat      = waveformat;
     m_owner           = owner;
     m_availableVoices = new MyConcurrentQueue <MySourceVoice>(MAX_COUNT);
     m_fadingOutVoices = new List <MySourceVoice>();
     m_currentCount    = 0;
 }
コード例 #10
0
 public MySourceVoicePool(XAudio2 audioEngine, WaveFormat waveformat, MyCueBank owner)
 {
     m_audioEngine = audioEngine;
     m_waveFormat = waveformat;
     m_owner = owner;
     m_availableVoices = new MyConcurrentQueue<MySourceVoice>(32);
     m_fadingOutVoices = new List<MySourceVoice>();
     m_currentCount = 0;
 }
コード例 #11
0
        public void Return(MyRenderMessageBase message)
        {
            MyConcurrentQueue <MyRenderMessageBase> queue = base[(int)message.MessageType];

            message.Close();
            if (queue.Count < 2048)
            {
                queue.Enqueue(message);
            }
        }
コード例 #12
0
 public ObjectsPool(int baseCapacity, Func <T> activator = null)
 {
     _activator    = activator ?? new Func <T>(() => new T());
     _baseCapacity = baseCapacity;
     _unused       = new MyConcurrentQueue <T>(_baseCapacity);
     _active       = new HashSet <T>();
     _marked       = new HashSet <T>();
     for (int index = 0; index < _baseCapacity; ++index)
     {
         _unused.Enqueue(_activator());
     }
 }
コード例 #13
0
        //private RakNetStatistics m_stats;

        //private RakNetStatistics GetStats(RakNet.SystemAddress systemAddress = null)
        //{
        //    systemAddress = systemAddress ?? RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS;
        //    if (m_stats == null)
        //    {
        //        m_stats = m_peer.GetStatistics(systemAddress);
        //    }
        //    else
        //    {
        //        m_stats = m_peer.GetStatistics(systemAddress, m_stats);
        //    }
        //    return m_stats;
        //}

        //public string GetStatsToString()
        //{
        //    string tmp;
        //    RakNet.RakNet.StatisticsToString(GetStats(), out tmp, 3);
        //    return tmp;
        //}

        //public ulong GetOutgoingBufferedBytes()
        //{
        //    var stats = GetStats();
        //    ulong bytes = stats.bytesInResendBuffer;

        //    foreach (var val in stats.bytesInSendBuffer)
        //    {
        //        bytes += (ulong)val;
        //    }

        //    return bytes;
        //}

        //[Conditional("DEBUG")]
        //private void ApplyNetworkSimulator(uint maxOutgoingBitsBandwidthPerConnection, float packetLoss, ushort minExtraPing, ushort extraPingVariance)
        //{
        //    m_peer.SetPerConnectionOutgoingBandwidthLimit(maxOutgoingBitsBandwidthPerConnection);
        //    m_peer.ApplyNetworkSimulator(packetLoss, minExtraPing, extraPingVariance);
        //}

        protected MyRakNetPeer(ulong steamID)
        {
            MySteamID      = steamID;
            m_receiveQueue = new MyConcurrentQueue <Packet>();
            m_peer         = new RakPeer(null);

            RegisterHandlers();

            if (APPLY_NETWORK_SIMULATOR)
            {
                //ApplyNetworkSimulator(MAX_OUTGOING_BITS_BANDWIDTH_PER_CONNECTION, PACKET_LOSS, MIN_EXTRA_PING, EXTRA_PING_VARIANCE);
            }
        }
コード例 #14
0
 /// <summary>
 /// Constructor of the worker array.
 /// </summary>
 /// <param name="prioritizedScheduler">Scheduler, owner of this group.</param>
 public WorkerArray(PrioritizedScheduler prioritizedScheduler, int workerArrayIndex, int threadCount, ThreadPriority systemThreadPriority)
 {
     for (int i = 0; i < m_taskQueuesByPriority.Length; i++)
     {
         m_taskQueuesByPriority[i] = new MyConcurrentQueue <Task>(DEFAULT_QUEUE_CAPACITY);
     }
     m_workerArrayIndex     = workerArrayIndex;
     m_prioritizedScheduler = prioritizedScheduler;
     m_workers = new Worker[threadCount];
     for (int workerIndex = 0; workerIndex < threadCount; workerIndex++) // initialize workers inside the array
     {
         m_workers[workerIndex] = new Worker(this, "Parallel " + systemThreadPriority + "_" + workerIndex, systemThreadPriority);
     }
 }
コード例 #15
0
        public FixedPriorityScheduler(int threadCount, ThreadPriority priority)
        {
            m_taskQueuesByPriority = new MyConcurrentQueue<Task>[typeof(WorkPriority).GetEnumValues().Length];
            for (int i = 0; i < m_taskQueuesByPriority.Length; ++i)
                m_taskQueuesByPriority[i] = new MyConcurrentQueue<Task>();

            m_hasNoWork = new ManualResetEvent[threadCount];
            m_workers = new Worker[threadCount];
            for (int i = 0; i < threadCount; i++)
            {
                m_workers[i] = new Worker(this, "Parallel " + i, priority);
                m_hasNoWork[i] = m_workers[i].HasNoWork;
            }
        }
コード例 #16
0
        public MyObjectsPool(int baseCapacity)
        {
            //  Pool should contain at least one preallocated item!
            Debug.Assert(baseCapacity > 0);

            m_baseCapacity = baseCapacity;
            m_unused       = new MyConcurrentQueue <T>(m_baseCapacity);
            m_active       = new HashSet <T>();
            m_marked       = new HashSet <T>();

            for (int i = 0; i < m_baseCapacity; i++)
            {
                m_unused.Enqueue(new T());
            }
        }
コード例 #17
0
        public FixedPriorityScheduler(int threadCount, ThreadPriority priority)
        {
            m_taskQueuesByPriority = new MyConcurrentQueue <Task> [typeof(WorkPriority).GetEnumValues().Length];
            for (int i = 0; i < m_taskQueuesByPriority.Length; ++i)
            {
                m_taskQueuesByPriority[i] = new MyConcurrentQueue <Task>();
            }

            m_hasNoWork = new ManualResetEvent[threadCount];
            m_workers   = new Worker[threadCount];
            for (int i = 0; i < threadCount; i++)
            {
                m_workers[i]   = new Worker(this, "Parallel " + i, priority);
                m_hasNoWork[i] = m_workers[i].HasNoWork;
            }
        }
コード例 #18
0
        public override void LoadData()
        {
            base.LoadData();

            if (MyPerGameSettings.EnableAi)
            {
                Sync.Players.NewPlayerRequestSucceeded += PlayerCreated;
                Sync.Players.LocalPlayerLoaded += LocalPlayerLoaded;
                Sync.Players.NewPlayerRequestFailed += Players_NewPlayerRequestFailed;
                if (Sync.IsServer)
                {
                    Sync.Players.PlayerRemoved += Players_PlayerRemoved;
                    Sync.Players.PlayerRequesting += Players_PlayerRequesting;
                }

                if (MyPerGameSettings.PathfindingType != null)
                {
                    m_pathfinding = Activator.CreateInstance(MyPerGameSettings.PathfindingType) as IMyPathfinding;
                }
                m_behaviorTreeCollection = new MyBehaviorTreeCollection();
                m_botCollection = new MyBotCollection(m_behaviorTreeCollection);
                m_loadedLocalPlayers = new List<int>();
                m_loadedBotObjectBuildersByHandle = new Dictionary<int, MyObjectBuilder_Bot>();
                m_agentsToSpawn = new Dictionary<int, AgentSpawnData>();
                m_removeQueue = new MyConcurrentQueue<BotRemovalRequest>();
                m_maxBotNotification = new MyHudNotification(MyCommonTexts.NotificationMaximumNumberBots, 2000, MyFontEnum.Red);
                m_processQueue = new MyConcurrentQueue<AgentSpawnData>();
                m_lock = new FastResourceLock();

#if !XB1
                if (MyFakes.ENABLE_BEHAVIOR_TREE_TOOL_COMMUNICATION)
                {
                    MyMessageLoop.AddMessageHandler(MyWMCodes.BEHAVIOR_GAME_UPLOAD_TREE, OnUploadNewTree);
                    MyMessageLoop.AddMessageHandler(MyWMCodes.BEHAVIOR_GAME_STOP_SENDING, OnBreakDebugging);
                    MyMessageLoop.AddMessageHandler(MyWMCodes.BEHAVIOR_GAME_RESUME_SENDING, OnResumeDebugging);
                }
#endif

                MyToolbarComponent.CurrentToolbar.SelectedSlotChanged += CurrentToolbar_SelectedSlotChanged;
                MyToolbarComponent.CurrentToolbar.SlotActivated += CurrentToolbar_SlotActivated;
                MyToolbarComponent.CurrentToolbar.Unselected += CurrentToolbar_Unselected;
            }
        }
コード例 #19
0
ファイル: Pool.cs プロジェクト: whztt07/SpaceEngineers
        /// <summary>
        /// Gets an instance from the pool.
        /// </summary>
        /// <returns>An instance of <typeparamref name="T"/>.</returns>
        public T Get(Thread thread)
        {
            MyConcurrentQueue <T> queue;

            if (!m_instances.TryGetValue(thread, out queue))
            {
                queue = new MyConcurrentQueue <T>();
                m_instances.Add(thread, queue);
            }

            T instance;

            if (!queue.TryDequeue(out instance))
            {
                instance = new T();
            }

            return(instance);
        }
コード例 #20
0
 public override void LoadData()
 {
     base.LoadData();
     if (MyPerGameSettings.EnableAi)
     {
         Sync.Players.NewPlayerRequestSucceeded += new Action <MyPlayer.PlayerId>(this.PlayerCreated);
         Sync.Players.LocalPlayerLoaded         += new Action <int>(this.LocalPlayerLoaded);
         Sync.Players.NewPlayerRequestFailed    += new Action <int>(this.Players_NewPlayerRequestFailed);
         if (Sync.IsServer)
         {
             Sync.Players.PlayerRemoved    += new Action <MyPlayer.PlayerId>(this.Players_PlayerRemoved);
             Sync.Players.PlayerRequesting += new PlayerRequestDelegate(this.Players_PlayerRequesting);
         }
         if (MyPerGameSettings.PathfindingType != null)
         {
             this.m_pathfinding = Activator.CreateInstance(MyPerGameSettings.PathfindingType) as IMyPathfinding;
         }
         this.m_behaviorTreeCollection          = new MyBehaviorTreeCollection();
         this.m_botCollection                   = new MyBotCollection(this.m_behaviorTreeCollection);
         this.m_loadedLocalPlayers              = new List <int>();
         this.m_loadedBotObjectBuildersByHandle = new Dictionary <int, MyObjectBuilder_Bot>();
         this.m_agentsToSpawn                   = new Dictionary <int, AgentSpawnData>();
         this.m_removeQueue        = new MyConcurrentQueue <BotRemovalRequest>();
         this.m_maxBotNotification = new MyHudNotification(MyCommonTexts.NotificationMaximumNumberBots, 0x7d0, "Red", MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, 0, MyNotificationLevel.Normal);
         this.m_processQueue       = new MyConcurrentQueue <AgentSpawnData>();
         this.m_lock = new FastResourceLock();
         if (MyFakes.ENABLE_BEHAVIOR_TREE_TOOL_COMMUNICATION)
         {
             MyMessageLoop.AddMessageHandler((uint)0x40a, new ActionRef <System.Windows.Forms.Message>(this.OnUploadNewTree));
             MyMessageLoop.AddMessageHandler((uint)0x40c, new ActionRef <System.Windows.Forms.Message>(this.OnBreakDebugging));
             MyMessageLoop.AddMessageHandler((uint)0x40b, new ActionRef <System.Windows.Forms.Message>(this.OnResumeDebugging));
         }
         MyToolbarComponent.CurrentToolbar.SelectedSlotChanged += new Action <MyToolbar, MyToolbar.SlotArgs>(this.CurrentToolbar_SelectedSlotChanged);
         MyToolbarComponent.CurrentToolbar.SlotActivated       += new Action <MyToolbar, MyToolbar.SlotArgs, bool>(this.CurrentToolbar_SlotActivated);
         MyToolbarComponent.CurrentToolbar.Unselected          += new Action <MyToolbar>(this.CurrentToolbar_Unselected);
     }
 }
コード例 #21
0
 /// <summary>
 /// Constructor of the worker array.
 /// </summary>
 /// <param name="prioritizedScheduler">Scheduler, owner of this group.</param>
 public WorkerArray(PrioritizedScheduler prioritizedScheduler, int workerArrayIndex, int threadCount, ThreadPriority systemThreadPriority)
 {
     for (int i = 0; i < m_taskQueuesByPriority.Length; i++)
     {
         m_taskQueuesByPriority[i] = new MyConcurrentQueue<Task>(DEFAULT_QUEUE_CAPACITY);
     }
     m_workerArrayIndex = workerArrayIndex;
     m_prioritizedScheduler = prioritizedScheduler;
     m_workers = new Worker[threadCount];
     for (int workerIndex = 0; workerIndex < threadCount; workerIndex++) // initialize workers inside the array
     {
         m_workers[workerIndex] = new Worker(this, "Parallel " + systemThreadPriority + "_" + workerIndex, systemThreadPriority);
     }
 }
コード例 #22
0
        public void InitWriteCache(int prealloc = 128)
        {
            //Debug.Assert(m_cachedChunks == null, "Error: Cache already initialized"); disabled due to shared storages

            if (m_cachedChunks != null) return;

            if (OperationsComponent != null)
                CachedWrites = true;
            else
                return;

            m_cachedChunks = new MyConcurrentDictionary<Vector3I, VoxelChunk>(prealloc, Vector3I.Comparer);
            m_pendingChunksToWrite = new MyConcurrentQueue<Vector3I>(prealloc / 10);
            m_chunksbyAge = new MyQueue<Vector3I>(prealloc);

            m_cacheMap = new MyDynamicAABBTree(Vector3.Zero);

            m_cacheLock = new FastResourceLock();

            OperationsComponent.Add(this);
        }
コード例 #23
0
        public override void LoadData()
        {
            base.LoadData();

            if (MyPerGameSettings.EnableAi)
            {
                Sync.Players.NewPlayerRequestSucceeded += PlayerCreated;
                Sync.Players.LocalPlayerLoaded += LocalPlayerLoaded;
                Sync.Players.NewPlayerRequestFailed += Players_NewPlayerRequestFailed;
                if (Sync.IsServer)
                {
                    Sync.Players.PlayerRemoved += Players_PlayerRemoved;
                    Sync.Players.PlayerRequesting += Players_PlayerRequesting;
                }

                m_pathfinding = new MyPathfinding();
                m_behaviorTreeCollection = new MyBehaviorTreeCollection();
                m_botCollection = new MyBotCollection(m_behaviorTreeCollection);
                m_loadedLocalPlayers = new List<int>();
                m_loadedBotObjectBuildersByHandle = new Dictionary<int, MyObjectBuilder_Bot>();
                m_agentsToSpawn = new Dictionary<int, AgentSpawnData>();
                m_removeQueue = new MyConcurrentQueue<BotRemovalRequest>();
                m_maxBotNotification = new MyHudNotification(MyCommonTexts.NotificationMaximumNumberBots, 2000, MyFontEnum.Red);
                m_processQueue = new MyConcurrentQueue<AgentSpawnData>();
                m_lock = new FastResourceLock();

#if !XB1
                if (MyFakes.ENABLE_BEHAVIOR_TREE_TOOL_COMMUNICATION)
                {
                    MyMessageLoop.AddMessageHandler(MyWMCodes.BEHAVIOR_GAME_UPLOAD_TREE, OnUploadNewTree);
                    MyMessageLoop.AddMessageHandler(MyWMCodes.BEHAVIOR_GAME_STOP_SENDING, OnBreakDebugging);
                    MyMessageLoop.AddMessageHandler(MyWMCodes.BEHAVIOR_GAME_RESUME_SENDING, OnResumeDebugging);
                }
#endif

                MyToolbarComponent.CurrentToolbar.SelectedSlotChanged += CurrentToolbar_SelectedSlotChanged;
                MyToolbarComponent.CurrentToolbar.SlotActivated += CurrentToolbar_SlotActivated;
                MyToolbarComponent.CurrentToolbar.Unselected += CurrentToolbar_Unselected;
            }
        }
コード例 #24
0
ファイル: MyRakNetPeer.cs プロジェクト: caomw/SpaceEngineers
        //private RakNetStatistics m_stats;

        //private RakNetStatistics GetStats(RakNet.SystemAddress systemAddress = null)
        //{
        //    systemAddress = systemAddress ?? RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS;
        //    if (m_stats == null)
        //    {
        //        m_stats = m_peer.GetStatistics(systemAddress);
        //    }
        //    else
        //    {
        //        m_stats = m_peer.GetStatistics(systemAddress, m_stats);
        //    }
        //    return m_stats;
        //}

        //public string GetStatsToString()
        //{
        //    string tmp;
        //    RakNet.RakNet.StatisticsToString(GetStats(), out tmp, 3);
        //    return tmp;
        //}

        //public ulong GetOutgoingBufferedBytes()
        //{
        //    var stats = GetStats();
        //    ulong bytes = stats.bytesInResendBuffer;

        //    foreach (var val in stats.bytesInSendBuffer)
        //    {
        //        bytes += (ulong)val;
        //    }

        //    return bytes;
        //}

        //[Conditional("DEBUG")]
        //private void ApplyNetworkSimulator(uint maxOutgoingBitsBandwidthPerConnection, float packetLoss, ushort minExtraPing, ushort extraPingVariance)
        //{
        //    m_peer.SetPerConnectionOutgoingBandwidthLimit(maxOutgoingBitsBandwidthPerConnection);
        //    m_peer.ApplyNetworkSimulator(packetLoss, minExtraPing, extraPingVariance);
        //}

        protected MyRakNetPeer(ulong steamID)
        {
            MySteamID = steamID;
            m_receiveQueue = new MyConcurrentQueue<Packet>();
            m_peer = new RakPeer(null);

            RegisterHandlers();

            if (APPLY_NETWORK_SIMULATOR)
            {
                //ApplyNetworkSimulator(MAX_OUTGOING_BITS_BANDWIDTH_PER_CONNECTION, PACKET_LOSS, MIN_EXTRA_PING, EXTRA_PING_VARIANCE);
            }
        }
コード例 #25
0
 public OreDeposit(MyVoxelBase voxelMap)
 {
     m_voxelMap  = voxelMap;
     m_taskQueue = new MyConcurrentQueue <Vector3I>();
     Materials   = new OreDepositMaterials(voxelMap);
 }
コード例 #26
0
ファイル: Pool.cs プロジェクト: whztt07/SpaceEngineers
        /// <summary>
        /// Returns an instance to the pool, so it is available for re-use.
        /// It is advised that the item is reset to a default state before being returned.
        /// </summary>
        /// <param name="instance">The instance to return to the pool.</param>
        public void Return(Thread thread, T instance)
        {
            MyConcurrentQueue <T> queue = m_instances[thread];

            queue.Enqueue(instance);
        }
コード例 #27
0
ファイル: Program.cs プロジェクト: Baptista/PC
        static void Main(string[] args)
        {
            MyConcurrentQueue<String> queue = new MyConcurrentQueue<String>();
            Thread[] threads = new Thread[THREADS];
            CountdownEvent syncStart = new CountdownEvent(THREADS);

            for (int i = 0; i < THREADS; i++)
            {
                int tid = i;
                threads[i] = new Thread(() =>
                    {
                        syncStart.Signal();
                        Boolean interrupted = false;
                        do
                        {
                            try
                            {
                                syncStart.Wait();
                                break;
                            }
                            catch (ThreadInterruptedException)
                            {
                                interrupted = true;
                            }
                        } while (true);

                        if (interrupted)
                        {
                            Thread.CurrentThread.Interrupt();
                        }

                        for (int j = 0; j < PUSHS_PER_THREAD; ++j)
                        {
                            queue.put("# " + tid + " thread");
                        }

                    });
                threads[i].Start();
            }

            for (int i = 0; i < THREADS; ++i)
            {
                Boolean interrupted = false;
                do
                {
                    try
                    {
                        threads[i].Join();
                        break;
                    }
                    catch (ThreadInterruptedException)
                    {
                        interrupted = true;
                    }
                } while (true);
                if (interrupted)
                {
                    Thread.CurrentThread.Interrupt();
                }
            }

            for (int i = 0; i <= THREADS * PUSHS_PER_THREAD; i++)
            {
                String it = queue.tryTake().item;
                if (it != null)
                {
                    Console.WriteLine("--popped: " + it);
                }
                else
                {
                    Console.WriteLine("***pop failed!");
                }
            }
        }
コード例 #28
0
 public NearestNodeQuery(MyConcurrentQueue <NearestNodeQuery> cache)
 {
     _cache = cache;
 }