Changeset 1699
- Timestamp:
- 06/30/10 18:32:04 (14 years ago)
- Files:
-
- trunk/phobos/std/concurrency.d (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/phobos/std/concurrency.d
r1696 r1699 583 583 } 584 584 } 585 585 586 586 587 587 /* 588 588 * Matches ops against each message in turn until a match is found. 589 589 * 590 590 * Params: 591 591 * ops = The operations to match. Each may return a bool to indicate 592 592 * whether a message with a matching type is truly a match. 593 * 594 * Returns: 595 * true if a message was retrieved and false if not (such as if a 596 * timeout occurred). 593 597 * 594 598 * Throws: 595 599 * LinkTerminated if a linked thread terminated, or OwnerTerminated 596 600 * if the owner thread terminates and no existing messages match the 597 601 * supplied ops. 598 602 */ 599 final voidget(T...)( T vals )603 final bool get(T...)( T vals ) 600 604 { 601 605 static assert( T.length ); 602 606 603 607 static if( isImplicitlyConvertible!(T[0], long) ) 604 608 { 605 609 alias TypeTuple!(T[1 .. $]) Ops; 606 610 alias vals[1 .. $] ops; 607 611 assert( vals[0] >= 0 ); 608 612 enum timedWait = true; 609 613 long period = vals[0]; … … 761 765 return false; 762 766 } 763 767 764 768 while( true ) 765 769 { 766 770 ListT arrived; 767 771 768 772 if( pty( m_localPty ) || 769 773 scan( m_localBox ) ) 770 774 { 771 return ;775 return true; 772 776 } 773 777 synchronized( m_lock ) 774 778 { 775 779 updateMsgCount(); 776 780 while( m_sharedPty.empty && m_sharedBox.empty ) 777 781 { 778 782 if( ownerDead ) 779 783 onOwnerDead(); 780 784 // NOTE: We're notifying all waiters here instead of just 781 785 // a few because the onCrowding behavior may have 782 786 // changed and we don't want to block sender threads 783 787 // unnecessarily if the new behavior is not to block. 784 788 // This will admittedly result in spurious wakeups 785 789 // in other situations, but what can you do? 786 790 if( m_putQueue && !mboxFull() ) 787 791 m_notFull.notifyAll(); 788 792 static if( timedWait ) 789 m_putMsg.wait( period ); 793 { 794 if( !m_putMsg.wait( period ) ) 795 return false; 796 } 790 797 else 798 { 791 799 m_putMsg.wait(); 800 } 792 801 } 793 802 m_localPty.put( m_sharedPty ); 794 803 arrived.put( m_sharedBox ); 795 804 } 796 805 if( m_localPty.empty ) 797 806 { 798 807 bool ok = scan( arrived ); 799 808 m_localBox.put( arrived ); 800 if( ok ) return ;809 if( ok ) return true; 801 810 else continue; 802 811 } 803 812 m_localBox.put( arrived ); 804 813 pty( m_localPty ); 805 return ;814 return true; 806 815 } 807 816 } 808 817 809 818 810 819 /* 811 820 * Called on thread termination. This routine processes any remaining 812 821 * control messages, clears out message queues, and sets a flag to 813 822 * reject any future messages. 814 823 */ 815 824 final void close()
