Exemplo n.º 1
0
		public static AtomicBoolean FromValue(bool value)
		{
			AtomicBoolean temp = new AtomicBoolean();
			temp.Value = value;
			
			return temp;
		}
Exemplo n.º 2
0
		protected virtual void Dispose (bool disposing)
		{
			if (disposing){
				if (cntd != null){
					cntd.Dispose ();
					cntd = null;
				}
				cleaned = null;
				postPhaseAction = null;
			}
		}
		public bool Equals (AtomicBoolean rhs)
		{
			return this.flag == rhs.flag;
		}
Exemplo n.º 4
0
		void InitCountdownEvent ()
		{
			cleaned = new AtomicBoolean ();
			cntd = new CountdownEvent (participants);
		}
Exemplo n.º 5
0
		void PostPhaseAction (AtomicBoolean cl)
		{
			if (postPhaseAction != null)
				postPhaseAction (this);
			
			InitCountdownEvent ();
			
			cl.Value = true;
			phase++;
		}
Exemplo n.º 6
0
		bool Wait (Func<CountdownEvent, bool> associate, CountdownEvent temp, AtomicBoolean cl)
		{
			if (!associate (temp))
				return false;
			
			SpinWait sw = new SpinWait ();
			while (!cl.Value)
				sw.SpinOnce ();
			
			return true;
		}
Exemplo n.º 7
0
        public void shouldPreventPublishersOvertakingEventProcessorWrapPoint()
        {
            int ringBufferSize = 4;
            CountDownLatch latch = new CountDownLatch(ringBufferSize);
            AtomicBoolean publisherComplete = new AtomicBoolean(false);
            RingBuffer<StubEvent> ringBuffer = new RingBuffer<StubEvent>(StubEvent.EVENT_FACTORY, ringBufferSize);
            TestEventProcessor processor = new TestEventProcessor(ringBuffer.newBarrier());
            ringBuffer.setGatingSequences(processor.getSequence());

            Thread thread = new Thread(() =>
            {
                {
                    for (int i = 0; i <= ringBufferSize; i++)
                    {
                        long sequence = ringBuffer.next();
                        StubEvent @event = ringBuffer.get(sequence);
                        @event.setValue(i);
                        ringBuffer.publish(sequence);
                        latch.countDown();
                    }

                    publisherComplete.set(true);
                }
            });

            thread.Start();

            latch.await();
            assertEquals(ringBuffer.getCursor(), ringBufferSize - 1);
            Assert.IsFalse(publisherComplete.get());

            processor.run();
            thread.Join();

            Assert.IsTrue(publisherComplete.get());
        }
Exemplo n.º 8
0
		bool Wait (Func<CountdownEvent, bool> associate, CountdownEvent temp, AtomicBoolean cl)
		{
			if (!associate (temp))
				return false;
			
			SpinWait sw = new SpinWait ();
			while (!cl.Value) {
				//Console.WriteLine (cleaned);
				sw.SpinOnce ();
			}
			
			return true;
		}