예제 #1
0
 /// <summary>
 /// 结束运行 依次唤醒等待get结果的节点
 /// </summary>
 private void finishCompletion()
 {
     // assert state > COMPLETING;
     for (WaitNode q; (q = waiters) != null;)
     {
         if (Interlocked.CompareExchange <WaitNode>(ref waiters, null, q) == q)
         {
             for (; ;)
             {
                 Thread t = q.thread;
                 if (t != null)
                 {
                     q.thread = null;
                     LockSupport.unpark(t);
                 }
                 WaitNode next = q.next;
                 if (next == null)
                 {
                     break;
                 }
                 q.next = null; // unlink to help gc
                 q      = next;
             }
             break;
         }
     }
     done();
     callable = null;        // to reduce footprint
 }
예제 #2
0
        private int Poke()
        {
            int result = this._targetTicket.incrementAndGet();

            LockSupport.unpark(_updatePullingThread);
            return(result);
        }
예제 #3
0
 public override void Run()
 {
     while (!_closed)
     {
         if (_hasReadAhead || _eof)
         {                         // We have already read ahead, sleep a little
             ParkAWhile();
         }
         else
         {                         // We haven't read ahead, or the data we read ahead have been consumed
             try
             {
                 if (!ReadAhead())
                 {
                     _eof = true;
                 }
                 _hasReadAhead = true;
                 LockSupport.unpark(_owner);
             }
             catch (IOException e)
             {
                 _ioException = e;
                 _closed      = true;
             }
             catch (Exception e)
             {
                 _ioException = new IOException(e);
                 _closed      = true;
             }
         }
     }
 }
예제 #4
0
        /// <summary>
        /// 唤醒下一个等待线程
        /// </summary>
        /// <param name="node"></param>
        private void UnparkSuccessor(Node node)
        {
            int ws = node.WaitStatus;

            if (ws < 0)
            {
                CompareAndSetWaitStatus(node, ws, 0);
            }
            Node s = node.Next;

            //节点为null或者已经取消 则寻找下一个节点
            if (s == null || s.WaitStatus > 0)
            {
                s = null;
                //从后向前找最前面可以被唤醒的节点 不知道为什么不从前往后找
                for (Node t = Tail; t != null && t != node; t = t.Prev)
                {
                    if (t.WaitStatus <= 0)
                    {
                        s = t;
                    }
                }
            }
            //唤醒该节点线程
            if (s != null)
            {
                LockSupport.unpark(s.Thread);
            }
        }
예제 #5
0
 private void UnparkEvictor()
 {
     if (_evictorParked)
     {
         _evictorParked = false;
         LockSupport.unpark(_evictionThread);
     }
 }
예제 #6
0
 private void UnparkSuccessor(Node waiters)
 {
     if (waiters.GetType() == typeof(Waiter))
     {
         Waiter waiter = ( Waiter )waiters;
         waiter.State = WAITER_STATE_SUCCESSOR;
         LockSupport.unpark(waiter.WaitingThread);
     }
 }
예제 #7
0
        public override void Stop()          // for removing throw declaration
        {
            if (_shutdownLatch == null)
            {
                return;                         // This SlaveUpdatePuller has already been shut down
            }

            Thread thread = _updatePullingThread;

            _halted = true;
            LockSupport.unpark(thread);
            _shutdownLatch.await();
            _shutdownLatch = null;
        }
예제 #8
0
        public override void Send(T @event)
        {
            AsyncEvent prev = _stackUpdater.getAndSet(this, @event);

            Debug.Assert(prev != null);
            @event.Next = prev;
            if (prev == _endSentinel)
            {
                LockSupport.unpark(_backgroundThread);
            }
            else if (prev == _shutdownSentinel)
            {
                AsyncEvent events = _stackUpdater.getAndSet(this, _shutdownSentinel);
                Process(events);
            }
        }
예제 #9
0
 private void UnparkAll(Node waiters)
 {
     // If we find a node that is not a waiter, then it is either 'end' or 'released'. Looking at the type pointer
     // is the cheapest way to make this check.
     while (waiters.GetType() == typeof(Waiter))
     {
         Waiter waiter = ( Waiter )waiters;
         waiter.State = WAITER_STATE_RELEASED;
         LockSupport.unpark(waiter.WaitingThread);
         Node next;
         do
         {
             // Just like in isReleased, loop if the next pointer is null.
             next = waiters.Next;
         } while (next == null);
         waiters = next;
     }
 }
        public void shutdown()
        {
            _isRunnable = false;

            LockSupport.unpark(_timerThread);

            try {
                long sleepTime = 200;

                if (CurrentTime.isTest())
                {
                    sleepTime = 1;
                }

                Thread.sleep(sleepTime);
            } catch (Exception e) {
            }
        }
예제 #11
0
 /// <summary>
 /// Initiate the shut down process of this {@code AsyncEvents} instance.
 /// <para>
 /// This call does not block or otherwise wait for the background thread to terminate.
 /// </para>
 /// </summary>
 public virtual void Shutdown()
 {
     Debug.Assert(!_shutdown, "Already shut down");
     _shutdown = true;
     LockSupport.unpark(_backgroundThread);
 }
예제 #12
0
 internal void EnqueueTask(ScheduledJobHandle newTasks)
 {
     _delayedTasks.offer(newTasks);
     LockSupport.unpark(_timeKeeper);
 }
예제 #13
0
 public void Stop()
 {
     _stopped = true;
     LockSupport.unpark(_timeKeeper);
 }
예제 #14
0
 internal virtual void Unpark()
 {
     LockSupport.unpark(Owner);
 }
예제 #15
0
 public virtual void signal()
 {
     LockSupport.unpark(consumer);
 }
예제 #16
0
 public override void Unpark(Thread thread)
 {
     LockSupport.unpark(thread);
 }
예제 #17
0
 public virtual void Unpark()
 {
     LockSupport.unpark(Thread);
 }
예제 #18
0
 protected internal virtual void PokeReader()
 {
     // wake up the reader... there's stuff to do, data to read
     _hasReadAhead = false;
     LockSupport.unpark(this);
 }