Changeset 158 for MicroThreading
- Timestamp:
- Jan 28, 2011, 9:10:16 PM (14 years ago)
- Location:
- MicroThreading
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
MicroThreading/Demo/Demo.lpi
r157 r158 39 39 </Item2> 40 40 </RequiredPackages> 41 <Units Count="6 5">41 <Units Count="67"> 42 42 <Unit0> 43 43 <Filename Value="Demo.lpr"/> … … 47 47 <TopLine Value="1"/> 48 48 <CursorPos X="34" Y="16"/> 49 <UsageCount Value="8 6"/>49 <UsageCount Value="89"/> 50 50 </Unit0> 51 51 <Unit1> … … 55 55 <ResourceBaseClass Value="Form"/> 56 56 <UnitName Value="UMainForm"/> 57 <EditorIndex Value=" 4"/>58 <WindowIndex Value="0"/> 59 <TopLine Value=" 247"/>60 <CursorPos X=" 1" Y="261"/>61 <UsageCount Value="8 6"/>57 <EditorIndex Value="5"/> 58 <WindowIndex Value="0"/> 59 <TopLine Value="351"/> 60 <CursorPos X="54" Y="366"/> 61 <UsageCount Value="89"/> 62 62 <Loaded Value="True"/> 63 63 <LoadedDesigner Value="True"/> … … 69 69 <EditorIndex Value="0"/> 70 70 <WindowIndex Value="0"/> 71 <TopLine Value=" 175"/>72 <CursorPos X=" 1" Y="190"/>73 <UsageCount Value="4 5"/>71 <TopLine Value="319"/> 72 <CursorPos X="9" Y="330"/> 73 <UsageCount Value="46"/> 74 74 <Loaded Value="True"/> 75 75 </Unit2> … … 144 144 <EditorIndex Value="1"/> 145 145 <WindowIndex Value="0"/> 146 <TopLine Value=" 896"/>147 <CursorPos X=" 10" Y="911"/>148 <UsageCount Value="1 0"/>146 <TopLine Value="469"/> 147 <CursorPos X="3" Y="484"/> 148 <UsageCount Value="12"/> 149 149 <Loaded Value="True"/> 150 150 </Unit11> … … 194 194 <Unit18> 195 195 <Filename Value="/usr/share/fpcsrc/2.4.0/rtl/objpas/classes/classesh.inc"/> 196 <EditorIndex Value=" 2"/>196 <EditorIndex Value="3"/> 197 197 <WindowIndex Value="0"/> 198 198 <TopLine Value="1"/> 199 199 <CursorPos X="50" Y="9"/> 200 <UsageCount Value="1 0"/>200 <UsageCount Value="12"/> 201 201 <Loaded Value="True"/> 202 202 </Unit18> … … 410 410 <Filename Value="../UPlatform.pas"/> 411 411 <UnitName Value="UPlatform"/> 412 <EditorIndex Value=" 3"/>412 <EditorIndex Value="4"/> 413 413 <WindowIndex Value="0"/> 414 414 <TopLine Value="23"/> 415 415 <CursorPos X="31" Y="38"/> 416 <UsageCount Value="2 5"/>416 <UsageCount Value="26"/> 417 417 <Loaded Value="True"/> 418 418 </Unit48> … … 536 536 <UsageCount Value="15"/> 537 537 </Unit64> 538 <Unit65> 539 <Filename Value="/usr/share/fpcsrc/2.4.0/rtl/inc/system.inc"/> 540 <EditorIndex Value="2"/> 541 <WindowIndex Value="0"/> 542 <TopLine Value="671"/> 543 <CursorPos X="1" Y="673"/> 544 <UsageCount Value="11"/> 545 <Loaded Value="True"/> 546 </Unit65> 547 <Unit66> 548 <Filename Value="/usr/share/fpcsrc/2.4.0/rtl/inc/objpash.inc"/> 549 <EditorIndex Value="6"/> 550 <WindowIndex Value="0"/> 551 <TopLine Value="160"/> 552 <CursorPos X="23" Y="175"/> 553 <UsageCount Value="11"/> 554 <Loaded Value="True"/> 555 </Unit66> 538 556 </Units> 539 557 <JumpHistory Count="30" HistoryIndex="29"> 540 558 <Position1> 541 559 <Filename Value="../UMicroThreading.pas"/> 542 <Caret Line=" 531" Column="1" TopLine="515"/>560 <Caret Line="615" Column="1" TopLine="599"/> 543 561 </Position1> 544 562 <Position2> 545 563 <Filename Value="../UMicroThreading.pas"/> 546 <Caret Line=" 532" Column="1" TopLine="515"/>564 <Caret Line="614" Column="1" TopLine="599"/> 547 565 </Position2> 548 566 <Position3> 549 567 <Filename Value="../UMicroThreading.pas"/> 550 <Caret Line=" 954" Column="1" TopLine="939"/>568 <Caret Line="615" Column="1" TopLine="599"/> 551 569 </Position3> 552 570 <Position4> 553 571 <Filename Value="../UMicroThreading.pas"/> 554 <Caret Line=" 822" Column="1" TopLine="807"/>572 <Caret Line="614" Column="1" TopLine="599"/> 555 573 </Position4> 556 574 <Position5> 557 575 <Filename Value="../UMicroThreading.pas"/> 558 <Caret Line=" 824" Column="1" TopLine="807"/>576 <Caret Line="615" Column="1" TopLine="599"/> 559 577 </Position5> 560 578 <Position6> 561 579 <Filename Value="../UMicroThreading.pas"/> 562 <Caret Line=" 955" Column="1" TopLine="940"/>580 <Caret Line="614" Column="1" TopLine="599"/> 563 581 </Position6> 564 582 <Position7> 565 <Filename Value=" UMainForm.pas"/>566 <Caret Line=" 262" Column="1" TopLine="247"/>583 <Filename Value="../UMicroThreading.pas"/> 584 <Caret Line="615" Column="1" TopLine="599"/> 567 585 </Position7> 568 586 <Position8> 569 <Filename Value=" UMainForm.pas"/>570 <Caret Line=" 261" Column="1" TopLine="247"/>587 <Filename Value="../UMicroThreading.pas"/> 588 <Caret Line="614" Column="1" TopLine="599"/> 571 589 </Position8> 572 590 <Position9> 573 591 <Filename Value="../UMicroThreading.pas"/> 574 <Caret Line=" 816" Column="1" TopLine="801"/>592 <Caret Line="615" Column="1" TopLine="599"/> 575 593 </Position9> 576 594 <Position10> 577 595 <Filename Value="../UMicroThreading.pas"/> 578 <Caret Line=" 777" Column="1" TopLine="756"/>596 <Caret Line="616" Column="1" TopLine="599"/> 579 597 </Position10> 580 598 <Position11> 581 599 <Filename Value="../UMicroThreading.pas"/> 582 <Caret Line=" 760" Column="1" TopLine="754"/>600 <Caret Line="618" Column="1" TopLine="599"/> 583 601 </Position11> 584 602 <Position12> 585 603 <Filename Value="../UMicroThreading.pas"/> 586 <Caret Line=" 762" Column="1" TopLine="754"/>604 <Caret Line="620" Column="1" TopLine="599"/> 587 605 </Position12> 588 606 <Position13> 589 607 <Filename Value="../UMicroThreading.pas"/> 590 <Caret Line=" 763" Column="1" TopLine="754"/>608 <Caret Line="325" Column="3" TopLine="321"/> 591 609 </Position13> 592 610 <Position14> 593 611 <Filename Value="../UMicroThreading.pas"/> 594 <Caret Line=" 764" Column="1" TopLine="754"/>612 <Caret Line="321" Column="69" TopLine="319"/> 595 613 </Position14> 596 614 <Position15> 597 615 <Filename Value="../UMicroThreading.pas"/> 598 <Caret Line=" 768" Column="2" TopLine="754"/>616 <Caret Line="326" Column="1" TopLine="319"/> 599 617 </Position15> 600 618 <Position16> 601 619 <Filename Value="../UMicroThreading.pas"/> 602 <Caret Line=" 767" Column="1" TopLine="754"/>620 <Caret Line="327" Column="1" TopLine="319"/> 603 621 </Position16> 604 622 <Position17> 605 623 <Filename Value="../UMicroThreading.pas"/> 606 <Caret Line=" 768" Column="1" TopLine="754"/>624 <Caret Line="411" Column="22" TopLine="403"/> 607 625 </Position17> 608 626 <Position18> 609 627 <Filename Value="../UMicroThreading.pas"/> 610 <Caret Line=" 769" Column="1" TopLine="754"/>628 <Caret Line="863" Column="10" TopLine="841"/> 611 629 </Position18> 612 630 <Position19> 613 631 <Filename Value="../UMicroThreading.pas"/> 614 <Caret Line=" 768" Column="1" TopLine="754"/>632 <Caret Line="861" Column="1" TopLine="841"/> 615 633 </Position19> 616 634 <Position20> 617 635 <Filename Value="../UMicroThreading.pas"/> 618 <Caret Line=" 770" Column="22" TopLine="754"/>636 <Caret Line="862" Column="1" TopLine="841"/> 619 637 </Position20> 620 638 <Position21> 621 639 <Filename Value="../UMicroThreading.pas"/> 622 <Caret Line=" 760" Column="1" TopLine="754"/>640 <Caret Line="863" Column="1" TopLine="841"/> 623 641 </Position21> 624 642 <Position22> 625 643 <Filename Value="../UMicroThreading.pas"/> 626 <Caret Line=" 762" Column="1" TopLine="754"/>644 <Caret Line="861" Column="1" TopLine="841"/> 627 645 </Position22> 628 646 <Position23> 629 647 <Filename Value="../UMicroThreading.pas"/> 630 <Caret Line=" 767" Column="1" TopLine="754"/>648 <Caret Line="843" Column="33" TopLine="841"/> 631 649 </Position23> 632 650 <Position24> 633 651 <Filename Value="../UMicroThreading.pas"/> 634 <Caret Line=" 768" Column="1" TopLine="754"/>652 <Caret Line="325" Column="5" TopLine="319"/> 635 653 </Position24> 636 654 <Position25> 637 655 <Filename Value="../UMicroThreading.pas"/> 638 <Caret Line=" 770" Column="1" TopLine="754"/>656 <Caret Line="326" Column="1" TopLine="319"/> 639 657 </Position25> 640 658 <Position26> 641 659 <Filename Value="../UMicroThreading.pas"/> 642 <Caret Line=" 772" Column="1" TopLine="754"/>660 <Caret Line="327" Column="1" TopLine="319"/> 643 661 </Position26> 644 662 <Position27> 645 663 <Filename Value="../UMicroThreading.pas"/> 646 <Caret Line=" 776" Column="1" TopLine="754"/>664 <Caret Line="328" Column="1" TopLine="319"/> 647 665 </Position27> 648 666 <Position28> 649 667 <Filename Value="../UMicroThreading.pas"/> 650 <Caret Line=" 777" Column="1" TopLine="754"/>668 <Caret Line="329" Column="1" TopLine="319"/> 651 669 </Position28> 652 670 <Position29> 653 671 <Filename Value="../UMicroThreading.pas"/> 654 <Caret Line=" 778" Column="1" TopLine="754"/>672 <Caret Line="328" Column="1" TopLine="319"/> 655 673 </Position29> 656 674 <Position30> 657 675 <Filename Value="../UMicroThreading.pas"/> 658 <Caret Line=" 782" Column="1" TopLine="782"/>676 <Caret Line="329" Column="1" TopLine="319"/> 659 677 </Position30> 660 678 </JumpHistory> … … 696 714 </CompilerOptions> 697 715 <Debugging> 716 <BreakPoints Count="2"> 717 <Item1> 718 <Source Value="../UMicroThreading.pas"/> 719 <Line Value="869"/> 720 </Item1> 721 <Item2> 722 <Source Value="../UMicroThreading.pas"/> 723 <Line Value="325"/> 724 </Item2> 725 </BreakPoints> 698 726 <Watches Count="2"> 699 727 <Item1> -
MicroThreading/Demo/UMainForm.lfm
r157 r158 16 16 Top = 8 17 17 Width = 802 18 ActivePage = TabSheet 218 ActivePage = TabSheet1 19 19 Anchors = [akTop, akLeft, akRight, akBottom] 20 TabIndex = 020 TabIndex = 1 21 21 TabOrder = 0 22 22 object TabSheet2: TTabSheet … … 133 133 Height = 14 134 134 Top = 36 135 Width = 13 136 Caption = ' ' 137 ParentColor = False 138 end 139 object Label15: TLabel 140 Left = 9 141 Height = 14 142 Top = 52 143 Width = 83 144 Caption = 'Main thread id:' 145 ParentColor = False 146 end 147 object Label16: TLabel 148 Left = 142 149 Height = 14 150 Top = 52 135 151 Width = 13 136 152 Caption = ' ' … … 226 242 Left = 10 227 243 Height = 25 228 Top = 74244 Top = 223 229 245 Width = 104 230 246 Caption = 'Clear jobs' … … 236 252 Height = 14 237 253 Top = 14 238 Width = 3 4254 Width = 37 239 255 Caption = 'Count:' 240 256 ParentColor = False … … 253 269 object Memo1: TMemo 254 270 Left = 316 255 Height = 24 4271 Height = 243 256 272 Top = 14 257 273 Width = 294 … … 261 277 end 262 278 object Button1: TButton 263 Left = 12264 Height = 25 265 Top = 138279 Left = 230 280 Height = 25 281 Top = 239 266 282 Width = 75 267 283 Caption = 'Clear memo' … … 273 289 Height = 14 274 290 Top = 38 275 Width = 5 2291 Width = 57 276 292 Caption = 'Iterations:' 277 293 ParentColor = False … … 287 303 Value = 10000000 288 304 end 305 object GroupBox3: TGroupBox 306 Left = 10 307 Height = 137 308 Top = 74 309 Width = 292 310 Caption = 'Do inside jobs' 311 ClientHeight = 122 312 ClientWidth = 288 313 TabOrder = 6 314 object CheckBox1: TCheckBox 315 Left = 4 316 Height = 20 317 Top = 9 318 Width = 76 319 Caption = 'Use sleep' 320 OnChange = CheckBox1Change 321 TabOrder = 0 322 end 323 object SpinEdit4: TSpinEdit 324 Left = 149 325 Height = 21 326 Top = 8 327 Width = 90 328 MaxValue = 100000 329 TabOrder = 1 330 Value = 100 331 end 332 object Label14: TLabel 333 Left = 242 334 Height = 14 335 Top = 15 336 Width = 17 337 Caption = 'ms' 338 ParentColor = False 339 end 340 object CheckBox2: TCheckBox 341 Left = 5 342 Height = 20 343 Top = 32 344 Width = 126 345 Caption = 'Write test to memo' 346 OnChange = CheckBox2Change 347 TabOrder = 2 348 end 349 object CheckBox3: TCheckBox 350 Left = 5 351 Height = 20 352 Top = 56 353 Width = 98 354 Caption = 'Wait for event' 355 OnChange = CheckBox3Change 356 TabOrder = 3 357 end 358 object Button3: TButton 359 Left = 226 360 Height = 25 361 Top = 51 362 Width = 51 363 Caption = 'Signal' 364 OnClick = Button3Click 365 TabOrder = 4 366 end 367 object SpinEdit5: TSpinEdit 368 Left = 130 369 Height = 21 370 Top = 51 371 Width = 70 372 MaxValue = 100000 373 OnChange = CheckBox3Change 374 TabOrder = 5 375 Value = 100 376 end 377 object Label17: TLabel 378 Left = 202 379 Height = 14 380 Top = 56 381 Width = 17 382 Caption = 'ms' 383 ParentColor = False 384 end 385 end 289 386 end 290 387 object TabSheet3: TTabSheet -
MicroThreading/Demo/UMainForm.pas
r157 r158 11 11 type 12 12 13 TMainForm = class; 14 15 { TWorker } 16 17 TWorker = class(TMicroThread) 18 procedure Execute; override; 19 private 20 MainForm: TMainForm; 21 procedure DoWriteToMemo; 22 end; 23 13 24 { TMainForm } 14 25 … … 16 27 Button1: TButton; 17 28 Button2: TButton; 29 Button3: TButton; 18 30 ButtonAddWorkers: TButton; 19 31 ButtonClearMicroThreads: TButton; … … 21 33 ButtonSchedulerStartStop: TButton; 22 34 ButtonShowThreadId: TButton; 35 CheckBox1: TCheckBox; 36 CheckBox2: TCheckBox; 37 CheckBox3: TCheckBox; 23 38 CheckBoxUseMainThread: TCheckBox; 24 39 GroupBox1: TGroupBox; 25 40 GroupBox2: TGroupBox; 41 GroupBox3: TGroupBox; 26 42 Label1: TLabel; 27 43 Label10: TLabel; … … 29 45 Label12: TLabel; 30 46 Label13: TLabel; 47 Label14: TLabel; 48 Label15: TLabel; 49 Label16: TLabel; 50 Label17: TLabel; 31 51 Label2: TLabel; 32 52 Label3: TLabel; … … 44 64 SpinEdit2: TSpinEdit; 45 65 SpinEdit3: TSpinEdit; 66 SpinEdit4: TSpinEdit; 67 SpinEdit5: TSpinEdit; 46 68 TabSheet1: TTabSheet; 47 69 TabSheet2: TTabSheet; … … 49 71 TimerRedraw: TTimer; 50 72 procedure Button1Click(Sender: TObject); 73 procedure Button3Click(Sender: TObject); 51 74 procedure ButtonSchedulerStartStopClick(Sender: TObject); 52 75 procedure Button2Click(Sender: TObject); … … 55 78 procedure ButtonShowThreadIdClick(Sender: TObject); 56 79 procedure ButtonClearMicroThreadsClick(Sender: TObject); 80 procedure CheckBox1Change(Sender: TObject); 81 procedure CheckBox2Change(Sender: TObject); 82 procedure CheckBox3Change(Sender: TObject); 57 83 procedure CheckBoxUseMainThreadChange(Sender: TObject); 58 84 procedure FormCreate(Sender: TObject); … … 63 89 procedure SpinEdit2Change(Sender: TObject); 64 90 procedure SpinEdit3Change(Sender: TObject); 91 procedure SpinEdit5Change(Sender: TObject); 65 92 procedure TimerRedrawTimer(Sender: TObject); 66 93 private 67 procedure Worker(MicroThread: TMicroThread);68 procedure WorkerDoWrite;69 94 procedure WorkerSubRoutine; 70 95 public 96 DoWriteToMemo: Boolean; 97 DoSleep: Boolean; 98 SleepDuration: Integer; 99 DoWaitForEvent: Boolean; 100 Event: TMicroThreadEvent; 101 WaitForEventDuration: Integer; 71 102 Iterations: Integer; 72 103 end; … … 88 119 ListView1.DoubleBuffered := True; 89 120 Label6.Caption := IntToStr(GetLogicalProcessorCount); 121 Event := TMicroThreadEvent.Create; 90 122 end; 91 123 … … 107 139 begin 108 140 Memo1.Clear; 141 end; 142 143 procedure TMainForm.Button3Click(Sender: TObject); 144 begin 145 Event.SetEvent; 109 146 end; 110 147 … … 165 202 var 166 203 I: Integer; 204 NewWorker: TWorker; 167 205 begin 168 206 //Scheduler.FMicroThreads.Clear; 169 for I := 0 to SpinEdit1.Value - 1 do 170 MainScheduler.AddMethod(Worker); 207 for I := 0 to SpinEdit1.Value - 1 do begin 208 NewWorker := TWorker.Create(True); 209 NewWorker.MainForm := Self; 210 NewWorker.Start; 211 end; 171 212 end; 172 213 … … 203 244 end; 204 245 246 procedure TMainForm.CheckBox1Change(Sender: TObject); 247 begin 248 SleepDuration := SpinEdit4.Value; 249 DoSleep := CheckBox1.Checked; 250 end; 251 252 procedure TMainForm.CheckBox2Change(Sender: TObject); 253 begin 254 DoWriteToMemo := CheckBox2.Checked; 255 end; 256 257 procedure TMainForm.CheckBox3Change(Sender: TObject); 258 begin 259 DoWaitForEvent := CheckBox3.Checked; 260 WaitForEventDuration := SpinEdit5.Value; 261 end; 262 205 263 procedure TMainForm.CheckBoxUseMainThreadChange(Sender: TObject); 206 264 begin … … 211 269 begin 212 270 MainScheduler.Active := False; 271 Event.Free; 213 272 end; 214 273 … … 216 275 begin 217 276 Iterations := SpinEdit3.Value; 218 SpinEdit2.Value := 20;277 SpinEdit2.Value := 6; 219 278 ButtonAddWorkers.Click; 220 279 ButtonSchedulerStartStop.Click; 280 Label16.Caption := IntToStr(MainThreadID); 221 281 end; 222 282 … … 267 327 end; 268 328 329 procedure TMainForm.SpinEdit5Change(Sender: TObject); 330 begin 331 332 end; 333 269 334 procedure TMainForm.TimerRedrawTimer(Sender: TObject); 270 335 begin … … 290 355 end; 291 356 292 procedure T MainForm.Worker(MicroThread: TMicroThread);357 procedure TWorker.Execute; 293 358 var 294 359 I: Integer; 295 360 Q: Integer; 296 361 begin 297 with MicroThread do begin 298 //Memo1.Lines.Add('Worker ' + IntToStr(Id)); 299 for I := 0 to Iterations - 1 do begin 300 Q := 0; 301 while Q < 100 do Inc(Q); 302 //Synchronize(WorkerDoWrite); 303 //Memo1.Lines.Add(IntToStr(Id) + ': ' + IntToStr(I) + ' ' + 304 // FloatToStr(ExecutionTime)); 305 Completion := I / Iterations; 306 //MTSleep(1000 * OneMillisecond); 307 Yield; 308 //WorkerSubRoutine; 309 end; 310 end; 311 end; 312 313 procedure TMainForm.WorkerDoWrite; 314 begin 315 //Memo1.Lines.Add('.'); 362 for I := 0 to MainForm.Iterations - 1 do begin 363 Q := 0; 364 while Q < 100 do Inc(Q); 365 if MainForm.DoWriteToMemo then Synchronize(DoWriteToMemo); 366 if MainForm.DoWaitForEvent then MainForm.Event.WaitFor(MainForm.WaitForEventDuration * OneMillisecond); 367 if MainForm.DoSleep then MTSleep(MainForm.SleepDuration * OneMillisecond); 368 //WorkerSubRoutine; 369 Completion := I / MainForm.Iterations; 370 Yield; 371 end; 372 end; 373 374 procedure TWorker.DoWriteToMemo; 375 begin 376 MainForm.Memo1.Lines.Add(IntToStr(Id) + ': ' + IntToStr(Trunc(Completion * 100)) + ' %'); 316 377 end; 317 378 -
MicroThreading/UMicroThreading.pas
r157 r158 178 178 FUseMainThread: Boolean; 179 179 FMainThreadStarter: TTimer; 180 FEvents: TObjectList; 180 181 function GetMicroThreadCount: Integer; 181 182 function GetThreadPoolCount: Integer; … … 322 323 I: Integer; 323 324 begin 324 for I := 0 to FMicroThreads.Count - 1 do 325 TMicroThread(FMicroThreads[I]).FStatePending := tsWaiting; 326 if not FAutoReset then FSignaled := True; 325 try 326 MainScheduler.FMicroThreadsLock.Acquire; 327 for I := 0 to FMicroThreads.Count - 1 do 328 with TMicroThread(FMicroThreads[I]) do begin 329 if (FState = tsBlocked) and (FBlockState = tbsWaitFor) then 330 FState := tsWaiting; 331 end; 332 if not FAutoReset then FSignaled := True; 333 finally 334 MainScheduler.FMicroThreadsLock.Release; 335 end; 327 336 end; 328 337 … … 342 351 constructor TMicroThreadEvent.Create; 343 352 begin 353 FAutoReset := True; 344 354 FMicroThreads := TObjectList.Create; 345 355 FMicroThreads.OwnsObjects := False; 346 356 FMicroThreadsLock := TCriticalSection.Create; 357 MainScheduler.FEvents.Add(Self); 347 358 end; 348 359 349 360 destructor TMicroThreadEvent.Destroy; 350 361 begin 362 MainScheduler.FEvents.Delete(MainScheduler.FEvents.IndexOf(Self)); 351 363 FMicroThreadsLock.Free; 352 364 FMicroThreads.Free; … … 399 411 end; 400 412 FCurrentMicroThread.CheckStack; 401 if FCurrentMicroThread = nil then402 raise Exception.Create('x');403 413 FScheduler.ReleaseMicroThread(FCurrentMicroThread); 404 414 end; … … 588 598 if not Assigned(FManager) then 589 599 raise Exception.Create('Manager reference lost'); 590 FStatePending := tsWaiting; 600 if FStatePending = tsNone then 601 FStatePending := tsWaiting; 591 602 FManager.Yield; 592 603 end; … … 613 624 Event.FMicroThreadsLock.Acquire; 614 625 Event.FMicroThreads.Add(Self); 626 FBlockTime := NowPrecise + Duration; 627 FBlockState := tbsWaitFor; 628 FStatePending := tsBlocked; 615 629 finally 616 630 Event.FMicroThreadsLock.Release; 617 631 end; 618 FBlockTime := NowPrecise + Duration;619 FBlockState := tbsWaitFor;620 FStatePending := tsBlocked;621 632 Yield; 622 633 try … … 642 653 end; 643 654 FFreeOnTerminate := True; 655 MainScheduler.Add(Self); 644 656 end; 645 657 … … 718 730 constructor TMicroThreadScheduler.Create; 719 731 begin 732 FEvents := TObjectList.Create; 720 733 FMainThreadStarter := TTimer.Create(nil); 721 734 FMainThreadStarter.Enabled := False; … … 742 755 FMicroThreads.Free; 743 756 FMicroThreadsLock.Free; 757 FEvents.Free; 744 758 inherited Destroy; 745 759 end; … … 878 892 begin 879 893 if not Assigned(MicroThread) then 880 raise Exception.Create('Can''t re alease nil thread.');894 raise Exception.Create('Can''t release nil thread.'); 881 895 try 882 896 FMicroThreadsLock.Acquire;
Note:
See TracChangeset
for help on using the changeset viewer.