チェンジセット 572

差分発生行の前後
無視リスト:
コミット日時:
2008/06/05 20:53:09 (6 ヶ月前)
コミッタ:
yossy
ログメッセージ:

Thread(soumen): event と next 両方設定された場合、 next を無視しないように変更

ファイル:

凡例:

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

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

    r547 r572  
    613613                        } 
    614614                         
    615                         // 待機状態でなければなにもしない 
    616                         if ((_state != ThreadState.WAITING && _state != ThreadState.TIMED_WAITING) || _waitMonitor == null) { 
    617                                 return; 
    618                         } 
    619                          
    620615                        // イベントを保存 
    621616                        _event = e; 
     
    627622                        resetEventHandlers(); 
    628623                         
    629                         // モニタに対して待機セットから抜けることを伝える 
    630                         _waitMonitor.leave(this); 
    631                          
    632                         // 保存されていたモニタを破棄 
    633                         _waitMonitor = null; 
     624                        // 待機状態である場合 
     625                        if (_waitMonitor != null) { 
     626                                // モニタに対して待機セットから抜けることを伝える 
     627                                _waitMonitor.leave(this); 
     628                                // 保存されていたモニタを破棄 
     629                                _waitMonitor = null; 
     630                        } 
    634631                         
    635632                        // state を実行状態に切り替える 
     
    827824                                        eventHandler.register(); 
    828825                                } 
    829                                 // まだ待機状態で無い場合、イベントを待機する 
    830                                 if (_waitMonitor == null) { 
    831                                         try { 
    832                                                 _currentThread = this; 
    833                                                 getEventMonitor().wait(); 
    834                                         } 
    835                                         finally { 
    836                                                 _currentThread = null; 
     826                                // 次に実行する実行関数が設定されていない場合で 
     827                                if (_runHandler == null) { 
     828                                        // まだ待機状態で無い場合、自動で待機状態に移行する 
     829                                        if (_waitMonitor == null) { 
     830                                                try { 
     831                                                        _currentThread = this; 
     832                                                        getEventMonitor().wait(); 
     833                                                } 
     834                                                finally { 
     835                                                        _currentThread = null; 
     836                                                } 
    837837                                        } 
    838838                                } 
  • as3/Thread/branches/soumen/tests/org/libspark/thread/EventTest.as

    r538 r572  
    3434                /** 
    3535                 * イベントハンドラが正しく動作するか。 
    36                  * イベントハンドラが設定された場合、next の呼び出しは無視され、自動的に待機状態になる。 
     36                 * イベントハンドラが設定された場合かつ next が設定されていない場合は、自動的に待機状態になる。 
    3737                 * イベントが来るとスレッドは起床し、指定されたイベントハンドラを次の実行関数に設定する。 
    3838                 * 複数のイベントハンドラが設定されていた場合、最初に起きたイベントのみ有効となる。 
     
    7272                        t.start(); 
    7373                } 
     74                 
     75                /** 
     76                 * イベントハンドラが設定されている場合でも、 next が設定された場合は待機状態にならずに動作することができるか 
     77                 */ 
     78                test function nextAndEvent():void 
     79                { 
     80                        Static.log = ''; 
     81                         
     82                        var t:TesterThread = new TesterThread(new NextAndEventTestThread()); 
     83                         
     84                        t.addEventListener(Event.COMPLETE, async(function(e:Event):void 
     85                        { 
     86                                assertEquals('run run run dispatch event finalize ', Static.log); 
     87                        }, 1000)); 
     88                         
     89                        t.start(); 
     90                } 
    7491        } 
    7592} 
     
    99116                event(dispatcher, 'hoge', hogeEvent); 
    100117                event(dispatcher, 'fuga', fugaEvent); 
    101                 next(run2); 
    102118                 
    103119                setTimeout(dispatch, 100); 
    104         } 
    105          
    106         private function run2():void 
    107         { 
    108                 Static.log += 'run2 '; 
    109120        } 
    110121         
     
    144155                 
    145156                event(_dispatcher, 'myEvent', myEventHandler); 
    146                 next(run2); 
    147157                wait(); 
    148158                 
     
    150160        } 
    151161         
    152         private function run2():void 
    153         { 
    154                 Static.log += 'run2 '; 
    155         } 
    156          
    157162        private function myEventHandler(e:Event):void 
    158163        { 
     
    172177        } 
    173178} 
     179 
     180class NextAndEventTestThread extends Thread 
     181{ 
     182        private var _dispatcher:IEventDispatcher = new EventDispatcher(); 
     183        private var _count:uint = 0; 
     184         
     185        override protected function run():void  
     186        { 
     187                Static.log += 'run '; 
     188                 
     189                event(_dispatcher, 'myEvent', myEventHandler); 
     190                next(run); 
     191                 
     192                if (++_count == 3) { 
     193                        new EventFireThread(_dispatcher).start(); 
     194                } 
     195        } 
     196         
     197        private function myEventHandler(e:Event):void 
     198        { 
     199                Static.log += 'event '; 
     200        } 
     201         
     202        override protected function finalize():void  
     203        { 
     204                Static.log += 'finalize '; 
     205        } 
     206} 
     207 
     208class EventFireThread extends Thread 
     209{ 
     210        public function EventFireThread(dispatcher:IEventDispatcher) 
     211        { 
     212                _dispatcher = dispatcher; 
     213        } 
     214         
     215        private var _dispatcher:IEventDispatcher; 
     216         
     217        override protected function run():void 
     218        { 
     219                Static.log += 'dispatch '; 
     220                 
     221                _dispatcher.dispatchEvent(new Event('myEvent')); 
     222        } 
     223}