チェンジセット 538

差分発生行の前後
無視リスト:
コミット日時:
2008/05/28 15:48:06 (4 年前)
コミッタ:
yossy
ログメッセージ:

Thread(soumen): wait が入る場合でも event でイベントハンドラを設定できるように修正

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • as3/Thread/branches/soumen/Thread.as3proj

    r536 r538  
    6666  <!-- Class files to compile (other referenced classes will automatically be included) --> 
    6767  <compileTargets> 
    68     <compile path="samples\tweener\Sample.as" /> 
     68    <compile path="tests\RunTests.as" /> 
    6969  </compileTargets> 
    7070  <!-- Paths to exclude from the Project Explorer tree --> 
  • as3/Thread/branches/soumen/src/org/libspark/thread/Thread.as

    r535 r538  
    603603                        } 
    604604                         
     605                        // 待機状態でなければなにもしない 
     606                        if ((_state != ThreadState.WAITING && _state != ThreadState.TIMED_WAITING) || _waitMonitor == null) { 
     607                                return; 
     608                        } 
     609                         
    605610                        // イベントを保存 
    606611                        _event = e.clone(); 
     
    612617                        resetEventHandlers(); 
    613618                         
    614                         // スレッドを起こす 
    615                         _eventMonitor.notifyAll(); 
     619                        // モニタに対して待機セットから抜けることを伝える 
     620                        _waitMonitor.leave(this); 
     621                         
     622                        // 保存されていたモニタを破棄 
     623                        _waitMonitor = null; 
     624                         
     625                        // state を実行状態に切り替える 
     626                        _state = _runningState; 
    616627                } 
    617628                 
     
    789800                                        eventHandler.register(); 
    790801                                } 
    791                                 // イベントを待機する 
    792                                 try { 
    793                                         _currentThread = this; 
    794                                         getEventMonitor().wait(); 
    795                                 } 
    796                                 finally { 
    797                                         _currentThread = null; 
     802                                // まだ待機状態で無い場合、イベントを待機する 
     803                                if (_waitMonitor == null) { 
     804                                        try { 
     805                                                _currentThread = this; 
     806                                                getEventMonitor().wait(); 
     807                                        } 
     808                                        finally { 
     809                                                _currentThread = null; 
     810                                        } 
    798811                                } 
    799812                        } 
  • as3/Thread/branches/soumen/tests/org/libspark/thread/EventTest.as

    r524 r538  
    5151                                assertNotNull(e.e); 
    5252                                assertSame(e.ev.type, e.e.type); 
     53                        }, 1000)); 
     54                         
     55                        t.start(); 
     56                } 
     57                 
     58                /** 
     59                 * 既に wait している状態でもイベントハンドラを仕掛けることが出来るか 
     60                 */ 
     61                test function waitAndEvent():void 
     62                { 
     63                        Static.log = ''; 
     64                         
     65                        var t:TesterThread = new TesterThread(new WaitAndEventTestThread()); 
     66                         
     67                        t.addEventListener(Event.COMPLETE, async(function(ev:Event):void 
     68                        { 
     69                                assertEquals('run dispatch event finalize ', Static.log); 
    5370                        }, 1000)); 
    5471                         
     
    117134        } 
    118135} 
     136 
     137class WaitAndEventTestThread extends Thread 
     138{ 
     139        private var _dispatcher:IEventDispatcher = new EventDispatcher(); 
     140         
     141        override protected function run():void  
     142        { 
     143                Static.log += 'run '; 
     144                 
     145                event(_dispatcher, 'myEvent', myEventHandler); 
     146                next(run2); 
     147                wait(); 
     148                 
     149                setTimeout(dispatch, 100); 
     150        } 
     151         
     152        private function run2():void 
     153        { 
     154                Static.log += 'run2 '; 
     155        } 
     156         
     157        private function myEventHandler(e:Event):void 
     158        { 
     159                Static.log += 'event '; 
     160        } 
     161         
     162        override protected function finalize():void  
     163        { 
     164                Static.log += 'finalize '; 
     165        } 
     166         
     167        private function dispatch():void 
     168        { 
     169                Static.log += 'dispatch '; 
     170                 
     171                _dispatcher.dispatchEvent(new Event('myEvent')); 
     172        } 
     173}