コード例 #1
0
        /// <summary>
        /// Look up the Monitor for the specified object in the SyncBlock
        /// tables. If no Monitor exists for the object then one is created.
        /// </summary>
        private static Monitor GetMonitorFromSyncBlock(Object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException();
            }
            SyncBlock[] table;
            int         index = SyncBlock.GetSyncBlockIndex(obj, out table);

            if (index < 0 || table[index].Monitor == null)
            {
                if (index < 0)
                {
                    index = SyncBlock.LazyCreateSyncBlock(obj, out table);
                }
                Monitor monitor = table[index].Monitor;
                if (monitor == null)
                {
                    Interlocked.CompareExchange(ref table[index].Monitor, new Monitor(), null);
                    monitor = table[index].Monitor;
                }
                return(monitor);
            }
            else
            {
                return(table[index].Monitor);
            }
        }
コード例 #2
0
 bool TryGetSyncChannel(UInt32 channel, out SyncBlock syncBlock)
 {
     lock (_SyncMessageLock)
     {
         return(_SyncMessageDict.TryGetValue(channel, out syncBlock));
     }
 }
コード例 #3
0
 public void TryToWakeUp(SyncBlock syncBlock)
 {
     if (!syncBlock.IsWorking)
     {
         syncBlock.IsWorking = true;
         syncBlock.Event.Set();
     }
 }
コード例 #4
0
 public void StartLazyThread(SyncBlock syncBlock, int elementsCount)
 {
     if (elementsCount >= startPoint)
     {
         TryToWakeUp(syncBlock);
         LazyStartWasFired = true;
     }
 }
コード例 #5
0
        private void InitQueueManagers(QueueManager <BytesBlock>[] queuesManager)
        {
            var syncs = new SyncBlock[coresCount];

            InitDefaultQueues(syncs);

            for (int i = 0; i < queuesManager.Length; i++)
            {
                queuesManager[i] = new QueueManager <BytesBlock>(_threadManager, syncs[i]);
            }
        }
コード例 #6
0
        UInt32 GetChannelForSync(out SyncBlock syncBlock)
        {
            lock (_SyncMessageLock)
            {
                UInt32 channel = IncCurChannel();

                while (_SyncMessageDict.ContainsKey(channel))
                {
                    channel = IncCurChannel();
                }

                syncBlock = new SyncBlock();

                _SyncMessageDict.Add(channel, syncBlock);

                return(channel);
            }
        }
コード例 #7
0
        public bool GetLastSyncBlock(out ulong height, out byte[] hash)
        {
            lock (_sync)
            {
                SyncBlock syncBlock = _dataContext.SyncBlocks.OrderBy(b => b.SyncBlockId).FirstOrDefault();

                if (syncBlock != null)
                {
                    height = syncBlock.SyncBlockId;
                    hash   = syncBlock.Hash;
                    return(true);
                }

                height = 0;
                hash   = null;
                return(false);
            }
        }
コード例 #8
0
        void ClearChannelForSync()
        {
            lock (_SyncMessageLock)
            {
                foreach (SyncBlock syncBlock in _SyncMessageDict.Values)
                {
                    try
                    {
                        syncBlock.Close();
                    }
                    catch
                    {
                    }
                }

                _SyncMessageDict.Clear();
            }

            SyncBlock.ClearAutoEvents();
        }
コード例 #9
0
 public SerialTaskQueue(ILogger logger)
 {
     _logger   = logger;
     _lockData = new SyncBlock(_logger);
 }
コード例 #10
0
 public QueueManager(ThreadManager threadManager, SyncBlock syncBlock) : base()
 {
     _threadManager = threadManager;
     _syncBlock     = syncBlock;
 }