チェンジセット 538
- コミット日時:
- 2008/05/28 15:48:06 (4 年前)
- ファイル:
凡例:
- 変更無し
- 追加
- 削除
- 更新
- コピー
- 移動
as3/Thread/branches/soumen/Thread.as3proj
r536 r538 66 66 <!-- Class files to compile (other referenced classes will automatically be included) --> 67 67 <compileTargets> 68 <compile path=" samples\tweener\Sample.as" />68 <compile path="tests\RunTests.as" /> 69 69 </compileTargets> 70 70 <!-- Paths to exclude from the Project Explorer tree --> as3/Thread/branches/soumen/src/org/libspark/thread/Thread.as
r535 r538 603 603 } 604 604 605 // 待機状態でなければなにもしない 606 if ((_state != ThreadState.WAITING && _state != ThreadState.TIMED_WAITING) || _waitMonitor == null) { 607 return; 608 } 609 605 610 // イベントを保存 606 611 _event = e.clone(); … … 612 617 resetEventHandlers(); 613 618 614 // スレッドを起こす 615 _eventMonitor.notifyAll(); 619 // モニタに対して待機セットから抜けることを伝える 620 _waitMonitor.leave(this); 621 622 // 保存されていたモニタを破棄 623 _waitMonitor = null; 624 625 // state を実行状態に切り替える 626 _state = _runningState; 616 627 } 617 628 … … 789 800 eventHandler.register(); 790 801 } 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 } 798 811 } 799 812 } as3/Thread/branches/soumen/tests/org/libspark/thread/EventTest.as
r524 r538 51 51 assertNotNull(e.e); 52 52 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); 53 70 }, 1000)); 54 71 … … 117 134 } 118 135 } 136 137 class 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 }

