チェンジセット 572
- コミット日時:
- 2008/06/05 20:53:09 (6 ヶ月前)
- ファイル:
凡例:
- 変更無し
- 追加
- 削除
- 更新
- コピー
- 移動
as3/Thread/branches/soumen/Thread.as3proj
r550 r572 67 67 <!-- Class files to compile (other referenced classes will automatically be included) --> 68 68 <compileTargets> 69 <compile path=" samples\tweener\Sample.as" />69 <compile path="tests\RunTests.as" /> 70 70 </compileTargets> 71 71 <!-- Paths to exclude from the Project Explorer tree --> as3/Thread/branches/soumen/src/org/libspark/thread/Thread.as
r547 r572 613 613 } 614 614 615 // 待機状態でなければなにもしない616 if ((_state != ThreadState.WAITING && _state != ThreadState.TIMED_WAITING) || _waitMonitor == null) {617 return;618 }619 620 615 // イベントを保存 621 616 _event = e; … … 627 622 resetEventHandlers(); 628 623 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 } 634 631 635 632 // state を実行状態に切り替える … … 827 824 eventHandler.register(); 828 825 } 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 } 837 837 } 838 838 } as3/Thread/branches/soumen/tests/org/libspark/thread/EventTest.as
r538 r572 34 34 /** 35 35 * イベントハンドラが正しく動作するか。 36 * イベントハンドラが設定された場合 、next の呼び出しは無視され、自動的に待機状態になる。36 * イベントハンドラが設定された場合かつ next が設定されていない場合は、自動的に待機状態になる。 37 37 * イベントが来るとスレッドは起床し、指定されたイベントハンドラを次の実行関数に設定する。 38 38 * 複数のイベントハンドラが設定されていた場合、最初に起きたイベントのみ有効となる。 … … 72 72 t.start(); 73 73 } 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 } 74 91 } 75 92 } … … 99 116 event(dispatcher, 'hoge', hogeEvent); 100 117 event(dispatcher, 'fuga', fugaEvent); 101 next(run2);102 118 103 119 setTimeout(dispatch, 100); 104 }105 106 private function run2():void107 {108 Static.log += 'run2 ';109 120 } 110 121 … … 144 155 145 156 event(_dispatcher, 'myEvent', myEventHandler); 146 next(run2);147 157 wait(); 148 158 … … 150 160 } 151 161 152 private function run2():void153 {154 Static.log += 'run2 ';155 }156 157 162 private function myEventHandler(e:Event):void 158 163 { … … 172 177 } 173 178 } 179 180 class 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 208 class 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 }
