Changeset 146
- Timestamp:
- Jan 26, 2011, 7:28:29 AM (14 years ago)
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/UCommon.pas
r129 r146 42 42 function AddLeadingZeroes(const aNumber, Length : integer) : string; 43 43 function LastPos(const SubStr: String; const S: String): Integer; 44 function GenerateNewName(OldName: string): string; 44 45 45 46 implementation 47 48 function GenerateNewName(OldName: string): string; 49 var 50 I: Integer; 51 Number: Integer; 52 begin 53 Number := 1; 54 // Find number on end 55 if Length(OldName) > 0 then begin 56 I := Length(OldName); 57 while (I > 1) and ((OldName[I] >= '0') and (OldName[I] <= '9')) do Dec(I); 58 TryStrToInt(Copy(OldName, I + 1, Length(OldName) - I), Number); 59 Inc(Number) 60 end; 61 Result := Copy(OldName, 1, I) + IntToStr(Number); 62 end; 46 63 47 64 (*function DelTree(DirName : string): Boolean; -
MicroThreading/Demo/Demo.lpi
r145 r146 50 50 <TopLine Value="1"/> 51 51 <CursorPos X="1" Y="15"/> 52 <UsageCount Value="4 7"/>52 <UsageCount Value="48"/> 53 53 </Unit0> 54 54 <Unit1> … … 58 58 <ResourceBaseClass Value="Form"/> 59 59 <UnitName Value="UMainForm"/> 60 <IsVisibleTab Value="True"/>61 60 <EditorIndex Value="0"/> 62 61 <WindowIndex Value="0"/> 63 <TopLine Value=" 84"/>64 <CursorPos X=" 3" Y="88"/>65 <UsageCount Value="4 7"/>62 <TopLine Value="218"/> 63 <CursorPos X="17" Y="230"/> 64 <UsageCount Value="48"/> 66 65 <Loaded Value="True"/> 67 66 <LoadedDesigner Value="True"/> … … 70 69 <Filename Value="../UMicroThreading.pas"/> 71 70 <UnitName Value="UMicroThreading"/> 71 <IsVisibleTab Value="True"/> 72 72 <EditorIndex Value="1"/> 73 73 <WindowIndex Value="0"/> 74 <TopLine Value=" 383"/>75 <CursorPos X=" 9" Y="384"/>76 <UsageCount Value="2 6"/>74 <TopLine Value="259"/> 75 <CursorPos X="11" Y="278"/> 76 <UsageCount Value="27"/> 77 77 <Loaded Value="True"/> 78 78 </Unit2> … … 159 159 <Unit13> 160 160 <Filename Value="../../../../lazarus/lcl/include/buttons.inc"/> 161 <EditorIndex Value="4"/>162 161 <WindowIndex Value="0"/> 163 162 <TopLine Value="317"/> 164 163 <CursorPos X="1" Y="341"/> 165 164 <UsageCount Value="10"/> 166 <Loaded Value="True"/>167 165 </Unit13> 168 166 <Unit14> 169 167 <Filename Value="../../../../lazarus/lcl/include/buttoncontrol.inc"/> 170 <EditorIndex Value="3"/>171 168 <WindowIndex Value="0"/> 172 169 <TopLine Value="45"/> 173 170 <CursorPos X="1" Y="62"/> 174 171 <UsageCount Value="10"/> 175 <Loaded Value="True"/>176 172 </Unit14> 177 173 <Unit15> 178 174 <Filename Value="../../../../lazarus/lcl/include/control.inc"/> 179 <EditorIndex Value="2"/>180 175 <WindowIndex Value="0"/> 181 176 <TopLine Value="2271"/> 182 177 <CursorPos X="19" Y="2274"/> 183 178 <UsageCount Value="11"/> 184 <Loaded Value="True"/>185 179 </Unit15> 186 180 <Unit16> … … 385 379 </Unit43> 386 380 </Units> 387 <JumpHistory Count="30" HistoryIndex=" 29">381 <JumpHistory Count="30" HistoryIndex="19"> 388 382 <Position1> 389 383 <Filename Value="../UMicroThreading.pas"/> 390 <Caret Line="2 33" Column="1" TopLine="209"/>384 <Caret Line="272" Column="1" TopLine="250"/> 391 385 </Position1> 392 386 <Position2> 393 387 <Filename Value="../UMicroThreading.pas"/> 394 <Caret Line="2 34" Column="1" TopLine="210"/>388 <Caret Line="273" Column="1" TopLine="251"/> 395 389 </Position2> 396 390 <Position3> 397 391 <Filename Value="../UMicroThreading.pas"/> 398 <Caret Line="2 35" Column="1" TopLine="211"/>392 <Caret Line="274" Column="1" TopLine="252"/> 399 393 </Position3> 400 394 <Position4> 401 395 <Filename Value="../UMicroThreading.pas"/> 402 <Caret Line=" 236" Column="1" TopLine="212"/>396 <Caret Line="397" Column="1" TopLine="384"/> 403 397 </Position4> 404 398 <Position5> 405 399 <Filename Value="../UMicroThreading.pas"/> 406 <Caret Line=" 237" Column="1" TopLine="213"/>400 <Caret Line="398" Column="1" TopLine="384"/> 407 401 </Position5> 408 402 <Position6> 409 <Filename Value=" ../UMicroThreading.pas"/>410 <Caret Line="23 9" Column="1" TopLine="215"/>403 <Filename Value="UMainForm.pas"/> 404 <Caret Line="230" Column="17" TopLine="218"/> 411 405 </Position6> 412 406 <Position7> 413 407 <Filename Value="../UMicroThreading.pas"/> 414 <Caret Line="2 40" Column="1" TopLine="216"/>408 <Caret Line="256" Column="1" TopLine="243"/> 415 409 </Position7> 416 410 <Position8> 417 411 <Filename Value="../UMicroThreading.pas"/> 418 <Caret Line="2 41" Column="1" TopLine="217"/>412 <Caret Line="259" Column="1" TopLine="243"/> 419 413 </Position8> 420 414 <Position9> 421 415 <Filename Value="../UMicroThreading.pas"/> 422 <Caret Line="2 42" Column="1" TopLine="218"/>416 <Caret Line="262" Column="1" TopLine="243"/> 423 417 </Position9> 424 418 <Position10> 425 419 <Filename Value="../UMicroThreading.pas"/> 426 <Caret Line="2 43" Column="1" TopLine="219"/>420 <Caret Line="263" Column="1" TopLine="243"/> 427 421 </Position10> 428 422 <Position11> 429 423 <Filename Value="../UMicroThreading.pas"/> 430 <Caret Line="2 46" Column="1" TopLine="222"/>424 <Caret Line="264" Column="1" TopLine="249"/> 431 425 </Position11> 432 426 <Position12> 433 427 <Filename Value="../UMicroThreading.pas"/> 434 <Caret Line="2 47" Column="1" TopLine="223"/>428 <Caret Line="265" Column="1" TopLine="249"/> 435 429 </Position12> 436 430 <Position13> 437 431 <Filename Value="../UMicroThreading.pas"/> 438 <Caret Line="2 48" Column="1" TopLine="224"/>432 <Caret Line="266" Column="1" TopLine="249"/> 439 433 </Position13> 440 434 <Position14> 441 435 <Filename Value="../UMicroThreading.pas"/> 442 <Caret Line="2 49" Column="1" TopLine="225"/>436 <Caret Line="268" Column="1" TopLine="249"/> 443 437 </Position14> 444 438 <Position15> 445 439 <Filename Value="../UMicroThreading.pas"/> 446 <Caret Line="2 50" Column="1" TopLine="226"/>440 <Caret Line="269" Column="1" TopLine="249"/> 447 441 </Position15> 448 442 <Position16> 449 443 <Filename Value="../UMicroThreading.pas"/> 450 <Caret Line="2 52" Column="1" TopLine="228"/>444 <Caret Line="270" Column="1" TopLine="249"/> 451 445 </Position16> 452 446 <Position17> 453 447 <Filename Value="../UMicroThreading.pas"/> 454 <Caret Line="2 04" Column="1" TopLine="189"/>448 <Caret Line="271" Column="1" TopLine="249"/> 455 449 </Position17> 456 450 <Position18> 457 451 <Filename Value="../UMicroThreading.pas"/> 458 <Caret Line="2 17" Column="1" TopLine="193"/>452 <Caret Line="272" Column="1" TopLine="250"/> 459 453 </Position18> 460 454 <Position19> 461 455 <Filename Value="../UMicroThreading.pas"/> 462 <Caret Line=" 188" Column="1" TopLine="173"/>456 <Caret Line="273" Column="1" TopLine="251"/> 463 457 </Position19> 464 458 <Position20> 465 459 <Filename Value="../UMicroThreading.pas"/> 466 <Caret Line="2 17" Column="1" TopLine="192"/>460 <Caret Line="274" Column="1" TopLine="252"/> 467 461 </Position20> 468 462 <Position21> 469 463 <Filename Value="../UMicroThreading.pas"/> 470 <Caret Line=" 188" Column="1" TopLine="173"/>464 <Caret Line="397" Column="1" TopLine="384"/> 471 465 </Position21> 472 466 <Position22> 473 467 <Filename Value="../UMicroThreading.pas"/> 474 <Caret Line=" 268" Column="7" TopLine="242"/>468 <Caret Line="400" Column="44" TopLine="384"/> 475 469 </Position22> 476 470 <Position23> 477 471 <Filename Value="../UMicroThreading.pas"/> 478 <Caret Line=" 217" Column="1" TopLine="202"/>472 <Caret Line="397" Column="1" TopLine="384"/> 479 473 </Position23> 480 474 <Position24> 481 475 <Filename Value="../UMicroThreading.pas"/> 482 <Caret Line=" 188" Column="1" TopLine="173"/>476 <Caret Line="398" Column="1" TopLine="384"/> 483 477 </Position24> 484 478 <Position25> 485 479 <Filename Value="../UMicroThreading.pas"/> 486 <Caret Line=" 480" Column="1" TopLine="465"/>480 <Caret Line="399" Column="1" TopLine="384"/> 487 481 </Position25> 488 482 <Position26> 489 483 <Filename Value="../UMicroThreading.pas"/> 490 <Caret Line=" 188" Column="1" TopLine="173"/>484 <Caret Line="400" Column="18" TopLine="384"/> 491 485 </Position26> 492 486 <Position27> 493 487 <Filename Value="../UMicroThreading.pas"/> 494 <Caret Line=" 292" Column="1" TopLine="254"/>488 <Caret Line="398" Column="1" TopLine="384"/> 495 489 </Position27> 496 490 <Position28> 497 491 <Filename Value="../UMicroThreading.pas"/> 498 <Caret Line="3 89" Column="3" TopLine="387"/>492 <Caret Line="399" Column="1" TopLine="384"/> 499 493 </Position28> 500 494 <Position29> 501 495 <Filename Value="../UMicroThreading.pas"/> 502 <Caret Line=" 384" Column="9" TopLine="383"/>496 <Caret Line="400" Column="1" TopLine="384"/> 503 497 </Position29> 504 498 <Position30> 505 <Filename Value=" UMainForm.pas"/>506 <Caret Line="2 35" Column="1" TopLine="142"/>499 <Filename Value="../UMicroThreading.pas"/> 500 <Caret Line="274" Column="15" TopLine="261"/> 507 501 </Position30> 508 502 </JumpHistory> … … 529 523 </CompilerOptions> 530 524 <Debugging> 531 <BreakPoints Count=" 7">525 <BreakPoints Count="5"> 532 526 <Item1> 533 527 <Source Value="../Coroutine.pas"/> … … 550 544 <Line Value="145"/> 551 545 </Item5> 552 <Item6>553 <Source Value="../UMicroThreading.pas"/>554 <Line Value="389"/>555 </Item6>556 <Item7>557 <Source Value="UMainForm.pas"/>558 <Line Value="88"/>559 </Item7>560 546 </BreakPoints> 561 547 <Exceptions Count="3"> -
MicroThreading/Demo/UMainForm.lfm
r145 r146 1 1 object Form1: TForm1 2 Left = 3002 Left = 231 3 3 Height = 510 4 Top = 1375 Width = 7 034 Top = 48 5 Width = 798 6 6 Caption = 'MicroThreading demo' 7 7 ClientHeight = 510 8 ClientWidth = 7 038 ClientWidth = 798 9 9 OnClose = FormClose 10 10 OnCreate = FormCreate … … 24 24 Height = 483 25 25 Top = 24 26 Width = 38626 Width = 481 27 27 Anchors = [akTop, akLeft, akRight, akBottom] 28 28 Columns = < 29 29 item 30 30 Caption = 'Id' 31 Width = 40 31 32 end 32 33 item … … 45 46 item 46 47 Caption = 'Execution time' 47 Width = 105 48 Width = 70 49 end 50 item 51 Caption = 'Completion' 48 52 end> 49 53 OwnerData = True … … 58 62 Height = 14 59 63 Top = 8 60 Width = 8564 Width = 74 61 65 Caption = 'Microthread list' 62 66 ParentColor = False … … 93 97 Height = 14 94 98 Top = 80 95 Width = 3 899 Width = 32 96 100 Caption = 'Label2' 97 101 ParentColor = False -
MicroThreading/Demo/UMainForm.pas
r145 r146 208 208 Item.SubItems.Add(MicroThreadStateText[State]); 209 209 Item.SubItems.Add(FloatToStr(ExecutionTime)); 210 Item.SubItems.Add(IntToStr(Trunc(Completion * 100)) + '%'); 210 211 end; 211 212 finally … … 226 227 var 227 228 I: Integer; 229 const 230 TotalSteps = 100; 228 231 begin 229 232 with MicroThread do begin 230 233 Memo1.Lines.Add('Worker ' + IntToStr(Id)); 231 for I := 0 to 1000do begin234 for I := 0 to TotalSteps - 1 do begin 232 235 Memo1.Lines.Add(IntToStr(Id) + ': ' + IntToStr(I) + ' ' + 233 236 FloatToStr(ExecutionTime)); 237 Completion := I / TotalSteps; 234 238 //Sleep(1 * Id * OneMillisecond); 235 239 Yield; -
MicroThreading/UMicroThreading.pas
r145 r146 45 45 Manager: TMicroThreadManager; 46 46 Scheduler: TMicroThreadScheduler; 47 Completion: Single; // Can be used for progress information in range <0, 1> 47 48 procedure Execute; virtual; 48 49 … … 247 248 mov edx, [eax].TMicroThread.FStackPointer 248 249 mov esp, edx 250 push ebp 249 251 mov edx, [eax].TMicroThread.FBasePointer 250 252 mov ebp, edx 251 253 end; 252 254 StaticMicroThread.Execute; 255 asm 256 pop ebp 257 end; 253 258 //FSelected.Method(FSelected); 254 StaticManager := StaticMicroThread.Manager;259 StaticManager := CurrentMicroThread.Manager; 255 260 asm 256 261 // Restore scheduler stack … … 267 272 CurrentMicroThread.FFinished := True; 268 273 if CurrentMicroThread.FFreeOnTerminate then begin 269 CurrentMicroThread.Free; 274 // Microthread is finished, remove it from queue 275 with Scheduler do 276 try 277 Lock.Acquire; 278 MicroThreads.Delete(MicroThreads.IndexOf(CurrentMicroThread)); 279 finally 280 Lock.Release; 281 end; 270 282 end; 271 283 CurrentMicroThread := nil; … … 387 399 destructor TMicroThread.Destroy; 388 400 begin 389 Terminate; 390 WaitFor; 391 // Microthread is finished, remove it from queue 392 try 393 Manager.Scheduler.Lock.Acquire; 394 Manager.Scheduler.MicroThreads.Delete(Manager.Scheduler.MicroThreads.IndexOf(Self)); 395 finally 396 Manager.Scheduler.Lock.Release; 397 end; 401 //Terminate; 402 //WaitFor; 398 403 FreeMem(FStack); 399 404 inherited Destroy;
Note:
See TracChangeset
for help on using the changeset viewer.