Exemplo n.º 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
 }
Exemplo n.º 2
0
        private int Poke()
        {
            int result = this._targetTicket.incrementAndGet();

            LockSupport.unpark(_updatePullingThread);
            return(result);
        }
Exemplo n.º 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;
             }
         }
     }
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 5
0
 private void UnparkEvictor()
 {
     if (_evictorParked)
     {
         _evictorParked = false;
         LockSupport.unpark(_evictionThread);
     }
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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;
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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) {
            }
        }
Exemplo n.º 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);
 }
Exemplo n.º 12
0
 internal void EnqueueTask(ScheduledJobHandle newTasks)
 {
     _delayedTasks.offer(newTasks);
     LockSupport.unpark(_timeKeeper);
 }
Exemplo n.º 13
0
 public void Stop()
 {
     _stopped = true;
     LockSupport.unpark(_timeKeeper);
 }
Exemplo n.º 14
0
 internal virtual void Unpark()
 {
     LockSupport.unpark(Owner);
 }
Exemplo n.º 15
0
 public virtual void signal()
 {
     LockSupport.unpark(consumer);
 }
Exemplo n.º 16
0
 public override void Unpark(Thread thread)
 {
     LockSupport.unpark(thread);
 }
Exemplo n.º 17
0
 public virtual void Unpark()
 {
     LockSupport.unpark(Thread);
 }
Exemplo n.º 18
0
 protected internal virtual void PokeReader()
 {
     // wake up the reader... there's stuff to do, data to read
     _hasReadAhead = false;
     LockSupport.unpark(this);
 }