Changeset 150 for MicroThreading


Ignore:
Timestamp:
Jan 26, 2011, 7:58:27 PM (13 years ago)
Author:
george
Message:
  • Fixed: Micro threads freeing.
Location:
MicroThreading
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • MicroThreading/Demo/Demo.lpi

    r149 r150  
    3939      </Item2>
    4040    </RequiredPackages>
    41     <Units Count="51">
     41    <Units Count="57">
    4242      <Unit0>
    4343        <Filename Value="Demo.lpr"/>
    4444        <IsPartOfProject Value="True"/>
    4545        <UnitName Value="Demo"/>
    46         <IsVisibleTab Value="True"/>
    47         <EditorIndex Value="1"/>
    4846        <WindowIndex Value="0"/>
    4947        <TopLine Value="1"/>
    50         <CursorPos X="10" Y="7"/>
    51         <UsageCount Value="58"/>
    52         <Loaded Value="True"/>
     48        <CursorPos X="5" Y="9"/>
     49        <UsageCount Value="59"/>
    5350      </Unit0>
    5451      <Unit1>
     
    5855        <ResourceBaseClass Value="Form"/>
    5956        <UnitName Value="UMainForm"/>
     57        <IsVisibleTab Value="True"/>
    6058        <EditorIndex Value="0"/>
    6159        <WindowIndex Value="0"/>
    62         <TopLine Value="1"/>
    63         <CursorPos X="20" Y="226"/>
    64         <UsageCount Value="58"/>
     60        <TopLine Value="249"/>
     61        <CursorPos X="22" Y="267"/>
     62        <UsageCount Value="59"/>
    6563        <Loaded Value="True"/>
    6664        <LoadedDesigner Value="True"/>
     
    6967        <Filename Value="../UMicroThreading.pas"/>
    7068        <UnitName Value="UMicroThreading"/>
    71         <EditorIndex Value="3"/>
    72         <WindowIndex Value="0"/>
    73         <TopLine Value="352"/>
    74         <CursorPos X="1" Y="367"/>
    75         <UsageCount Value="32"/>
     69        <EditorIndex Value="1"/>
     70        <WindowIndex Value="0"/>
     71        <TopLine Value="271"/>
     72        <CursorPos X="1" Y="286"/>
     73        <UsageCount Value="33"/>
    7674        <Loaded Value="True"/>
    7775      </Unit2>
     
    8078        <UnitName Value="Forms"/>
    8179        <WindowIndex Value="0"/>
    82         <TopLine Value="1310"/>
    83         <CursorPos X="15" Y="1327"/>
    84         <UsageCount Value="8"/>
     80        <TopLine Value="55"/>
     81        <CursorPos X="3" Y="70"/>
     82        <UsageCount Value="10"/>
    8583      </Unit3>
    8684      <Unit4>
     
    110108        <Filename Value="../../ExceptionLogger/UExceptionLogger.pas"/>
    111109        <UnitName Value="UExceptionLogger"/>
    112         <EditorIndex Value="4"/>
    113110        <WindowIndex Value="0"/>
    114111        <TopLine Value="1"/>
    115112        <CursorPos X="1" Y="8"/>
    116113        <UsageCount Value="10"/>
    117         <Loaded Value="True"/>
    118114        <DefaultSyntaxHighlighter Value="Delphi"/>
    119115      </Unit7>
     
    146142      <Unit11>
    147143        <Filename Value="/usr/share/fpcsrc/2.4.0/rtl/inc/systemh.inc"/>
    148         <EditorIndex Value="2"/>
    149144        <WindowIndex Value="0"/>
    150145        <TopLine Value="479"/>
    151146        <CursorPos X="3" Y="494"/>
    152147        <UsageCount Value="11"/>
    153         <Loaded Value="True"/>
    154148      </Unit11>
    155149      <Unit12>
     
    177171        <Filename Value="../../../../lazarus/lcl/include/control.inc"/>
    178172        <WindowIndex Value="0"/>
    179         <TopLine Value="2271"/>
    180         <CursorPos X="19" Y="2274"/>
     173        <TopLine Value="1670"/>
     174        <CursorPos X="1" Y="1685"/>
    181175        <UsageCount Value="11"/>
    182176      </Unit15>
     
    198192      <Unit18>
    199193        <Filename Value="/usr/share/fpcsrc/2.4.0/rtl/objpas/classes/classesh.inc"/>
    200         <EditorIndex Value="6"/>
    201         <WindowIndex Value="0"/>
    202         <TopLine Value="1425"/>
    203         <CursorPos X="25" Y="1443"/>
     194        <WindowIndex Value="0"/>
     195        <TopLine Value="1823"/>
     196        <CursorPos X="3" Y="1838"/>
    204197        <UsageCount Value="12"/>
    205         <Loaded Value="True"/>
    206198      </Unit18>
    207199      <Unit19>
    208200        <Filename Value="../../../../lazarus/lcl/include/customform.inc"/>
    209201        <WindowIndex Value="0"/>
    210         <TopLine Value="861"/>
    211         <CursorPos X="1" Y="878"/>
    212         <UsageCount Value="9"/>
     202        <TopLine Value="1348"/>
     203        <CursorPos X="1" Y="1363"/>
     204        <UsageCount Value="10"/>
    213205      </Unit19>
    214206      <Unit20>
     
    414406        <Filename Value="../UPlatform.pas"/>
    415407        <UnitName Value="UPlatform"/>
    416         <EditorIndex Value="7"/>
     408        <EditorIndex Value="3"/>
    417409        <WindowIndex Value="0"/>
    418410        <TopLine Value="1"/>
    419411        <CursorPos X="24" Y="9"/>
    420         <UsageCount Value="12"/>
     412        <UsageCount Value="13"/>
    421413        <Loaded Value="True"/>
    422414      </Unit48>
     
    431423        <Filename Value="/usr/share/fpcsrc/2.4.0/rtl/unix/sysutils.pp"/>
    432424        <UnitName Value="sysutils"/>
    433         <EditorIndex Value="5"/>
    434425        <WindowIndex Value="0"/>
    435426        <TopLine Value="1"/>
    436427        <CursorPos X="1" Y="1"/>
    437428        <UsageCount Value="10"/>
     429      </Unit50>
     430      <Unit51>
     431        <Filename Value="../../../../lazarus/lcl/interfaces/gtk2/gtk2widgetset.inc"/>
     432        <EditorIndex Value="2"/>
     433        <WindowIndex Value="0"/>
     434        <TopLine Value="2380"/>
     435        <CursorPos X="30" Y="2390"/>
     436        <UsageCount Value="10"/>
    438437        <Loaded Value="True"/>
    439       </Unit50>
     438      </Unit51>
     439      <Unit52>
     440        <Filename Value="/usr/share/fpcsrc/2.4.0/rtl/objpas/classes/classes.inc"/>
     441        <WindowIndex Value="0"/>
     442        <TopLine Value="150"/>
     443        <CursorPos X="55" Y="162"/>
     444        <UsageCount Value="10"/>
     445      </Unit52>
     446      <Unit53>
     447        <Filename Value="../../../../lazarus/lcl/include/wincontrol.inc"/>
     448        <WindowIndex Value="0"/>
     449        <TopLine Value="5227"/>
     450        <CursorPos X="1" Y="5242"/>
     451        <UsageCount Value="10"/>
     452      </Unit53>
     453      <Unit54>
     454        <Filename Value="../../../../lazarus/lcl/lclmessageglue.pas"/>
     455        <UnitName Value="LCLMessageGlue"/>
     456        <WindowIndex Value="0"/>
     457        <TopLine Value="102"/>
     458        <CursorPos X="1" Y="121"/>
     459        <UsageCount Value="10"/>
     460      </Unit54>
     461      <Unit55>
     462        <Filename Value="../../../../lazarus/lcl/interfaces/gtk2/gtk2proc.inc"/>
     463        <WindowIndex Value="0"/>
     464        <TopLine Value="3515"/>
     465        <CursorPos X="1" Y="3531"/>
     466        <UsageCount Value="10"/>
     467      </Unit55>
     468      <Unit56>
     469        <Filename Value="../../../../lazarus/lcl/interfaces/gtk2/gtk2callback.inc"/>
     470        <WindowIndex Value="0"/>
     471        <TopLine Value="1159"/>
     472        <CursorPos X="1" Y="1174"/>
     473        <UsageCount Value="10"/>
     474      </Unit56>
    440475    </Units>
    441476    <JumpHistory Count="30" HistoryIndex="29">
    442477      <Position1>
    443478        <Filename Value="../UMicroThreading.pas"/>
    444         <Caret Line="524" Column="1" TopLine="509"/>
     479        <Caret Line="308" Column="1" TopLine="284"/>
    445480      </Position1>
    446481      <Position2>
    447482        <Filename Value="../UMicroThreading.pas"/>
    448         <Caret Line="530" Column="28" TopLine="515"/>
     483        <Caret Line="309" Column="1" TopLine="285"/>
    449484      </Position2>
    450485      <Position3>
    451486        <Filename Value="../UMicroThreading.pas"/>
    452         <Caret Line="547" Column="1" TopLine="532"/>
     487        <Caret Line="310" Column="1" TopLine="286"/>
    453488      </Position3>
    454489      <Position4>
    455490        <Filename Value="../UMicroThreading.pas"/>
    456         <Caret Line="570" Column="1" TopLine="555"/>
     491        <Caret Line="312" Column="1" TopLine="288"/>
    457492      </Position4>
    458493      <Position5>
    459494        <Filename Value="../UMicroThreading.pas"/>
    460         <Caret Line="661" Column="1" TopLine="646"/>
     495        <Caret Line="315" Column="1" TopLine="291"/>
    461496      </Position5>
    462497      <Position6>
    463498        <Filename Value="../UMicroThreading.pas"/>
    464         <Caret Line="662" Column="1" TopLine="646"/>
     499        <Caret Line="338" Column="1" TopLine="323"/>
    465500      </Position6>
    466501      <Position7>
    467502        <Filename Value="../UMicroThreading.pas"/>
    468         <Caret Line="663" Column="1" TopLine="646"/>
     503        <Caret Line="218" Column="1" TopLine="203"/>
    469504      </Position7>
    470505      <Position8>
    471506        <Filename Value="../UMicroThreading.pas"/>
    472         <Caret Line="570" Column="1" TopLine="555"/>
     507        <Caret Line="219" Column="1" TopLine="203"/>
    473508      </Position8>
    474509      <Position9>
    475510        <Filename Value="../UMicroThreading.pas"/>
    476         <Caret Line="571" Column="1" TopLine="555"/>
     511        <Caret Line="360" Column="1" TopLine="345"/>
    477512      </Position9>
    478513      <Position10>
    479514        <Filename Value="../UMicroThreading.pas"/>
    480         <Caret Line="572" Column="1" TopLine="555"/>
     515        <Caret Line="290" Column="25" TopLine="275"/>
    481516      </Position10>
    482517      <Position11>
    483518        <Filename Value="../UMicroThreading.pas"/>
    484         <Caret Line="573" Column="1" TopLine="555"/>
     519        <Caret Line="291" Column="28" TopLine="276"/>
    485520      </Position11>
    486521      <Position12>
    487522        <Filename Value="../UMicroThreading.pas"/>
    488         <Caret Line="574" Column="1" TopLine="555"/>
     523        <Caret Line="286" Column="1" TopLine="276"/>
    489524      </Position12>
    490525      <Position13>
    491526        <Filename Value="../UMicroThreading.pas"/>
    492         <Caret Line="575" Column="1" TopLine="555"/>
     527        <Caret Line="301" Column="1" TopLine="277"/>
    493528      </Position13>
    494529      <Position14>
    495530        <Filename Value="../UMicroThreading.pas"/>
    496         <Caret Line="20" Column="3" TopLine="1"/>
     531        <Caret Line="286" Column="1" TopLine="277"/>
    497532      </Position14>
    498533      <Position15>
    499534        <Filename Value="../UMicroThreading.pas"/>
    500         <Caret Line="573" Column="1" TopLine="558"/>
     535        <Caret Line="287" Column="1" TopLine="277"/>
    501536      </Position15>
    502537      <Position16>
    503538        <Filename Value="../UMicroThreading.pas"/>
    504         <Caret Line="664" Column="1" TopLine="649"/>
     539        <Caret Line="288" Column="1" TopLine="277"/>
    505540      </Position16>
    506541      <Position17>
    507542        <Filename Value="../UMicroThreading.pas"/>
    508         <Caret Line="665" Column="1" TopLine="649"/>
     543        <Caret Line="301" Column="1" TopLine="277"/>
    509544      </Position17>
    510545      <Position18>
    511546        <Filename Value="../UMicroThreading.pas"/>
    512         <Caret Line="666" Column="1" TopLine="649"/>
     547        <Caret Line="302" Column="1" TopLine="278"/>
    513548      </Position18>
    514549      <Position19>
    515550        <Filename Value="../UMicroThreading.pas"/>
    516         <Caret Line="573" Column="1" TopLine="558"/>
     551        <Caret Line="303" Column="1" TopLine="279"/>
    517552      </Position19>
    518553      <Position20>
    519554        <Filename Value="../UMicroThreading.pas"/>
    520         <Caret Line="574" Column="1" TopLine="558"/>
     555        <Caret Line="304" Column="1" TopLine="280"/>
    521556      </Position20>
    522557      <Position21>
    523558        <Filename Value="../UMicroThreading.pas"/>
    524         <Caret Line="575" Column="1" TopLine="558"/>
     559        <Caret Line="305" Column="1" TopLine="281"/>
    525560      </Position21>
    526561      <Position22>
    527562        <Filename Value="../UMicroThreading.pas"/>
    528         <Caret Line="576" Column="1" TopLine="558"/>
     563        <Caret Line="306" Column="1" TopLine="282"/>
    529564      </Position22>
    530565      <Position23>
    531566        <Filename Value="../UMicroThreading.pas"/>
    532         <Caret Line="577" Column="1" TopLine="558"/>
     567        <Caret Line="308" Column="1" TopLine="284"/>
    533568      </Position23>
    534569      <Position24>
    535570        <Filename Value="../UMicroThreading.pas"/>
    536         <Caret Line="578" Column="1" TopLine="558"/>
     571        <Caret Line="309" Column="1" TopLine="285"/>
    537572      </Position24>
    538573      <Position25>
    539574        <Filename Value="../UMicroThreading.pas"/>
    540         <Caret Line="20" Column="16" TopLine="1"/>
     575        <Caret Line="310" Column="1" TopLine="286"/>
    541576      </Position25>
    542577      <Position26>
    543         <Filename Value="../../ExceptionLogger/UExceptionLogger.pas"/>
    544         <Caret Line="15" Column="8" TopLine="1"/>
     578        <Filename Value="../UMicroThreading.pas"/>
     579        <Caret Line="311" Column="1" TopLine="287"/>
    545580      </Position26>
    546581      <Position27>
    547582        <Filename Value="../UMicroThreading.pas"/>
    548         <Caret Line="14" Column="15" TopLine="1"/>
     583        <Caret Line="313" Column="1" TopLine="289"/>
    549584      </Position27>
    550585      <Position28>
    551         <Filename Value="Demo.lpr"/>
    552         <Caret Line="8" Column="34" TopLine="1"/>
     586        <Filename Value="../UMicroThreading.pas"/>
     587        <Caret Line="316" Column="1" TopLine="292"/>
    553588      </Position28>
    554589      <Position29>
    555590        <Filename Value="../UMicroThreading.pas"/>
    556         <Caret Line="573" Column="1" TopLine="558"/>
     591        <Caret Line="339" Column="1" TopLine="324"/>
    557592      </Position29>
    558593      <Position30>
    559594        <Filename Value="../UMicroThreading.pas"/>
    560         <Caret Line="649" Column="11" TopLine="649"/>
     595        <Caret Line="286" Column="1" TopLine="271"/>
    561596      </Position30>
    562597    </JumpHistory>
     
    596631  </CompilerOptions>
    597632  <Debugging>
    598     <BreakPoints Count="6">
     633    <BreakPoints Count="1">
    599634      <Item1>
    600         <Source Value="../Coroutine.pas"/>
    601         <Line Value="110"/>
     635        <Source Value="../UMicroThreading.pas"/>
     636        <Line Value="285"/>
    602637      </Item1>
    603       <Item2>
    604         <Source Value="../Coroutine.pas"/>
    605         <Line Value="222"/>
    606       </Item2>
    607       <Item3>
    608         <Source Value="../Coroutine.pas"/>
    609         <Line Value="257"/>
    610       </Item3>
    611       <Item4>
    612         <Source Value="../Coroutine.pas"/>
    613         <Line Value="145"/>
    614       </Item4>
    615       <Item5>
    616         <Source Value="../UMicroThreading.pas"/>
    617         <Line Value="560"/>
    618       </Item5>
    619       <Item6>
    620         <Source Value="../UMicroThreading.pas"/>
    621         <Line Value="540"/>
    622       </Item6>
    623638    </BreakPoints>
    624639    <Exceptions Count="3">
  • MicroThreading/Demo/Demo.lpr

    r149 r150  
    44
    55uses
    6   {$IFDEF UNIX}{$IFDEF UseCThreads}
     6  {$IFDEF UNIX}
     7  //{$IFDEF UseCThreads}
    78  cthreads,
    8   {$ENDIF}{$ENDIF}
     9  //{$ENDIF}
     10  {$ENDIF}
    911  Interfaces, // this includes the LCL widgetset
    1012  Forms, UMainForm, MicroThreading;
  • MicroThreading/Demo/UMainForm.lfm

    r149 r150  
    3939        Top = 37
    4040        Width = 140
    41         Caption = 'Clear microthreads'
     41        Caption = 'Clear jobs'
    4242        OnClick = ButtonClearMicroThreadsClick
    4343        TabOrder = 1
     
    6969        ScrollBars = ssAutoBoth
    7070        TabOrder = 3
     71      end
     72      object Button1: TButton
     73        Left = 14
     74        Height = 25
     75        Top = 94
     76        Width = 75
     77        Caption = 'Clear memo'
     78        OnClick = Button1Click
     79        TabOrder = 4
    7180      end
    7281    end
     
    242251      end
    243252      object Label2: TLabel
    244         Left = 78
     253        Left = 102
    245254        Height = 14
    246255        Top = 135
    247         Width = 38
    248         Caption = 'Label2'
     256        Width = 13
     257        Caption = '    '
    249258        ParentColor = False
    250259      end
     
    257266        OnClick = Button2Click
    258267        TabOrder = 2
     268      end
     269      object Label11: TLabel
     270        Left = 15
     271        Height = 14
     272        Top = 135
     273        Width = 81
     274        Caption = 'Precision time:'
     275        ParentColor = False
    259276      end
    260277    end
  • MicroThreading/Demo/UMainForm.pas

    r149 r150  
    1414
    1515  TMainForm = class(TForm)
     16    Button1: TButton;
    1617    Button2: TButton;
    1718    ButtonAddWorkers: TButton;
     
    2425    Label1: TLabel;
    2526    Label10: TLabel;
     27    Label11: TLabel;
    2628    Label2: TLabel;
    2729    Label3: TLabel;
     
    4244    TimerRedraw: TTimer;
    4345    TimerSchedulerStart: TTimer;
     46    procedure Button1Click(Sender: TObject);
    4447    procedure ButtonSchedulerStartStopClick(Sender: TObject);
    4548    procedure Button2Click(Sender: TObject);
     
    8790  if ButtonSchedulerStartStop.Caption = 'Start scheduler' then begin
    8891    ButtonSchedulerStartStop.Caption := 'Stop scheduler';
    89     Memo1.Clear;
     92    Scheduler.ThreadPoolSize := SpinEdit2.Value;
    9093    Scheduler.Active := True;
    9194  end else begin
     
    9396    Scheduler.Active := False;
    9497  end;
     98end;
     99
     100procedure TMainForm.Button1Click(Sender: TObject);
     101begin
     102  Memo1.Clear;
    95103end;
    96104
     
    191199procedure TMainForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
    192200begin
     201  Scheduler.Active := False;
    193202end;
    194203
  • MicroThreading/UMicroThreading.pas

    r149 r150  
    275275        mov eax, StaticMicroThread
    276276        mov edx, [eax].TMicroThread.FStackPointer
     277        mov ecx, esp
    277278        mov esp, edx
    278279        push ebp // remember bp on micro thread stack for read back
     280        push ecx
    279281        mov edx, [eax].TMicroThread.FBasePointer
    280282        mov ebp, edx
     
    282284      StaticMicroThread.Execute;
    283285      asm
     286        pop edx
    284287        pop ebp
     288        mov esp, edx
    285289      end;
    286290      //FSelected.Method(FSelected);
    287       StaticManager := FCurrentMicroThread.FManager;
     291  (*    StaticManager := FCurrentMicroThread.FManager;
    288292      asm
    289293        // Restore FScheduler stack
     
    294298        mov ebp, edx
    295299      end;
     300*)
    296301      FCurrentMicroThread.FManager := nil;
    297302      FCurrentMicroThread.FExecutionEndTime := CurrentTime;
     
    561566  try
    562567    FThreadPoolLock.Acquire;
     568    FThreadPool.OwnsObjects := False;
    563569    FThreadPool.Delete(FThreadPool.IndexOf(Sender));
     570    FThreadPool.OwnsObjects := True;
    564571  finally
    565572    FThreadPoolLock.Release;
Note: See TracChangeset for help on using the changeset viewer.