Esempio n. 1
0
        /// -----------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="ParserScheduler"/> class.
        /// </summary>
        /// -----------------------------------------------------------------------------------
        public ParserScheduler(FdoCache cache, IdleQueue idleQueue)
        {
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }

            Trace.WriteLineIf(m_tracingSwitch.TraceInfo, "ParserScheduler(): CurrentThreadId = " + Win32.GetCurrentThreadId());

            m_cache = cache;

            switch (m_cache.LanguageProject.MorphologicalDataOA.ActiveParser)
            {
            case "XAmple":
                m_parserWorker = new XAmpleParserWorker(cache, HandleTaskUpdate, idleQueue);
                break;

            case "HC":
                m_parserWorker = new HCParserWorker(cache, HandleTaskUpdate, idleQueue);
                break;

            default:
                throw new InvalidOperationException("The language project is set to use an unrecognized parser.");
            }
            m_parserWorker.ParseFiler.WordformUpdated += ParseFiler_WordformUpdated;

            m_thread = new ConsumerThread <ParserPriority, ParserWork>(Work)
            {
                IsBackground = true
            };
            ReloadGrammarAndLexicon();
            m_thread.Start();
        }
Esempio n. 2
0
        public void SetUp()
        {
            var sut = new ConsumerThread<int>((item, disposing) => {
                return true;
            });

            Parallel.For(0, 100, sut.Enqueue);
        }
Esempio n. 3
0
        /// -----------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="ParserScheduler"/> class.
        /// </summary>
        /// -----------------------------------------------------------------------------------
        public ParserScheduler(FdoCache cache, IdleQueue idleQueue, string dataDir)
        {
            m_parserWorker = new ParserWorker(cache, HandleTaskUpdate, idleQueue, dataDir);
            m_parserWorker.ParseFiler.WordformUpdated += ParseFiler_WordformUpdated;

            m_thread = new ConsumerThread <ParserPriority, ParserWork>(Work);
            ReloadGrammarAndLexicon();
            m_thread.Start();
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SearchEngine"/> class.
        /// </summary>
        protected SearchEngine(FdoCache cache, SearchType type)
        {
            m_cache    = cache;
            m_searcher = new StringSearcher <int>(type, m_cache.ServiceLocator.WritingSystemManager);
            m_thread   = new ConsumerThread <int, SearchField[]>(HandleWork);
            m_synchronizationContext = SynchronizationContext.Current;
            m_syncRoot    = new object();
            m_indexObjPos = new Dictionary <Tuple <int, int>, int>();

            m_cache.DomainDataByFlid.AddNotification(this);

            m_thread.Start();
        }
Esempio n. 5
0
		/// <summary>
		/// Initializes a new instance of the <see cref="SearchEngine"/> class.
		/// </summary>
		protected SearchEngine(FdoCache cache, SearchType type)
		{
			m_cache = cache;
			m_searcher = new StringSearcher<int>(type, m_cache.ServiceLocator.WritingSystemManager);
			m_thread = new ConsumerThread<int, SearchField[]>(HandleWork) { IsBackground = true };
			m_synchronizationContext = SynchronizationContext.Current;
			m_syncRoot = new object();
			m_indexObjPos = new Dictionary<Tuple<int, int>, int>();

			m_cache.DomainDataByFlid.AddNotification(this);

			m_thread.Start();
		}
    public void Execute()
    {
        SyncPoint      sync     = new SyncPoint();
        ProducerThread producer = new ProducerThread(sync);
        ConsumerThread consumer = new ConsumerThread(sync);


        Thread thrd1 = new Thread(new ThreadStart(consumer.Process));

        thrd1.Start();

        Thread thrd2 = new Thread(new ThreadStart(producer.Process));

        thrd2.Start();
    }
Esempio n. 7
0
 private void InitThreads()
 {
     if (SharedConfig.MutilThread)
     {
         _createSnapshopThreadsStat = new bool[SharedConfig.CreateSnapshotThreadCount];
         _createSnapshopThreads     =
             new ConsumerThread <CreateSnapshotTask, int> [SharedConfig.CreateSnapshotThreadCount];
         for (int i = 0; i < _createSnapshopThreads.Length; i++)
         {
             _createSnapshopThreads[i] =
                 new ConsumerThread <CreateSnapshotTask, int>(
                     string.Format("CreateSnapshotThread_{0}", i), CreateSendSnapshot, _queue);
             _createSnapshopThreads[i].Start();
         }
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Inherited class must call this initializer method first.
        /// </summary>
        /// <param name="name">The name of the <see cref="AsyncQueue"/></param>
        /// <param name="asyncQueue">The <see cref="IAsyncQueue"/> implementation</param>
        /// <param name="consumerCount">Number of consumers</param>
        /// <param name="priority">priority of consumer threads</param>
        protected void Initialize(
            string name,
            IAsyncQueue asyncQueue,
            int consumerCount,
            ThreadPriority priority)
        {
            Assert.IsTrue(consumerCount > 0);

            _name       = name;
            _asyncQueue = asyncQueue;

            for (var id = 0; id < consumerCount; id++)
            {
                var consumerThread = new ConsumerThread(this, id, priority);
                Consumers.Add(consumerThread.Thread);
            }
        }
Esempio n. 9
0
        private void Dequeue(ConsumerThread consumerThread)
        {
            var thread = consumerThread.Thread;

            WaitHandle[] waitHandles = { thread.StopRequest, _queueEvent };

            while (!thread.IsStopRequested)
            {
                var item = Dequeue();

                if (item != null)
                {
                    Consume(consumerThread, item);
                }
                else
                {
                    WaitHandle.WaitAny(waitHandles);
                }
            }
        }
Esempio n. 10
0
        private void Consume(ConsumerThread consumerThread, object item)
        {
            Assert.IsNotNull(consumerThread);

            var args         = new AsyncQueueConsumeEventArgs(item);
            var eventHandler = _asyncQueue.BeforeConsume;

            if (eventHandler != null)
            {
                eventHandler(this, args);
            }

            consumerThread.Consume(item);

            eventHandler = _asyncQueue.AfterConsume;

            if (eventHandler != null)
            {
                eventHandler(this, args);
            }
        }
Esempio n. 11
0
 public Form1()
 {
     InitializeComponent();
     ConsumerThread.Start();
 }
Esempio n. 12
0
		protected void PerformCommit(HashSet<ICmObjectOrSurrogate> newbies, HashSet<ICmObjectOrSurrogate> dirtballs, HashSet<ICmObjectId> goners,
			IEnumerable<CustomFieldInfo> customFields)
		{
			if (CommitThread == null || !CommitThread.WaitForNextRequest())
			{
				// If thread is already dead, then WaitForNextRequest will return false, but we still have to call Dispose() on it.
				if (CommitThread != null)
					CommitThread.Dispose();

				CommitThread = new ConsumerThread<int, CommitWork>(Work);
				CommitThread.Start();
			}

			CommitThread.EnqueueWork(new CommitWork(newbies, dirtballs, goners, customFields));
		}
Esempio n. 13
0
		/// <summary>
		/// Shutdown the BEP.
		/// </summary>
		protected override void ShutdownInternal()
		{
			CompleteAllCommits();
			// Make sure the commit thread is stopped. (FWR-3179)
			if (CommitThread != null)
			{
				CommitThread.StopOnIdle(); // CompleteAllCommits should wait until idle, but just in case...
				CommitThread.Dispose();
				CommitThread = null;
			}
			UnlockProject();
		}
Esempio n. 14
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="ParserScheduler"/> class.
		/// </summary>
		/// -----------------------------------------------------------------------------------
		public ParserScheduler(FdoCache cache, IdleQueue idleQueue, string dataDir)
		{
			m_parserWorker = new ParserWorker(cache, HandleTaskUpdate, idleQueue, dataDir);
			m_parserWorker.ParseFiler.WordformUpdated += ParseFiler_WordformUpdated;

			m_thread = new ConsumerThread<ParserPriority, ParserWork>(Work) {IsBackground = true};
			ReloadGrammarAndLexicon();
			m_thread.Start();
		}
Esempio n. 15
0
        public void Run()
        {
            // create sites, threads, and streams arrays
            sites   = new SiteConfiguration[NumberOfSites];
            threads = new ConsumerThread[NumberOfSites];
            streams = new StreamWriter[NumberOfSites];

            for (int i = 0; i < NumberOfSites; i++)
            {
                sites[i]   = new SiteConfiguration(resourceNames[i]); // create site configuration
                threads[i] = new ConsumerThread();                    // spawn consumer thread
                threads[i].Enqueue(InitializeSessions, sites[i]);     // queue instrument initialization

                // set configuration data in each site
                sites[i].commonConfig.CenterFrequency_Hz       = 5.18e9;
                sites[i].commonConfig.FrequencyReferenceSource = RFmxInstrMXConstants.OnboardClock;
                sites[i].commonConfig.LOSource            = RFmxInstrMXConstants.LOSourceOnboard;
                sites[i].commonConfig.DigitalEdgeSource   = "PXI_Trig" + i;
                sites[i].signalConfig.AutoDetectSignal    = false;
                sites[i].signalConfig.ChannelBandwidth_Hz = 80e6;
                sites[i].signalConfig.Standard            = RFmxWlanMXStandard.Standard802_11ac;

                streams[i] = new StreamWriter(File.Create(sites[i].resourceName + "_results.csv")); // create file for logging to disk
            }

            // spawn thread for logging to disk
            loggingThread = new ConsumerThread();

            // wait for sessions to initialize before continuing
            for (int i = 0; i < NumberOfSites; i++)
            {
                threads[i].Wait();
            }

            // queue work items into threads
            for (int i = 0; i < NumberOfSites; i++)
            {
                // RDL configurations
                threads[i].Enqueue(ConfigureCommon, sites[i].instr, sites[i].wlan, sites[i].commonConfig, sites[i].autoLevelConfig, "");
                threads[i].Enqueue(PowerEdgeTriggerOverride, sites[i]); // override digital edge trigger with power edge trigger
                threads[i].Enqueue(ConfigureSignal, sites[i].wlan, sites[i].signalConfig, "");
                threads[i].Enqueue(ConfigureOFDMModAcc, sites[i].wlan, sites[i].ofdmModAccConfig, "");

                // initate and measure
                threads[i].Enqueue((site) => site.wlan.Initiate("", ""), sites[i]);
                threads[i].Enqueue(Measure, sites[i], streams[i]);
            }

            // close instruments
            for (int i = 0; i < NumberOfSites; i++)
            {
                threads[i].Enqueue(sites[i].instr.Close);
            }

            // close threads
            foreach (var thread in threads)
            {
                thread.Finish();
            }

            // close file streams
            foreach (var fileStream in streams)
            {
                loggingThread.Enqueue(fileStream.Close);
            }

            // let logging thread finish working
            loggingThread.Finish();
        }