Changeset 144 for MicroThreading


Ignore:
Timestamp:
Jan 25, 2011, 2:16:25 PM (14 years ago)
Author:
george
Message:
  • Modified: Not finished implementation of multithreaded scheduler.
Location:
MicroThreading
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • MicroThreading/Demo/Demo.lpi

    r143 r144  
    4242      </Item3>
    4343    </RequiredPackages>
    44     <Units Count="39">
     44    <Units Count="44">
    4545      <Unit0>
    4646        <Filename Value="Demo.lpr"/>
     
    5050        <TopLine Value="1"/>
    5151        <CursorPos X="1" Y="15"/>
    52         <UsageCount Value="40"/>
     52        <UsageCount Value="46"/>
    5353      </Unit0>
    5454      <Unit1>
     
    6060        <EditorIndex Value="0"/>
    6161        <WindowIndex Value="0"/>
    62         <TopLine Value="147"/>
    63         <CursorPos X="29" Y="148"/>
    64         <UsageCount Value="40"/>
     62        <TopLine Value="182"/>
     63        <CursorPos X="28" Y="184"/>
     64        <UsageCount Value="46"/>
    6565        <Loaded Value="True"/>
    6666        <LoadedDesigner Value="True"/>
     
    7070        <UnitName Value="UMicroThreading"/>
    7171        <IsVisibleTab Value="True"/>
    72         <EditorIndex Value="3"/>
    73         <WindowIndex Value="0"/>
    74         <TopLine Value="128"/>
    75         <CursorPos X="36" Y="144"/>
    76         <UsageCount Value="21"/>
     72        <EditorIndex Value="6"/>
     73        <WindowIndex Value="0"/>
     74        <TopLine Value="337"/>
     75        <CursorPos X="17" Y="350"/>
     76        <UsageCount Value="25"/>
    7777        <Loaded Value="True"/>
    7878      </Unit2>
     
    8383        <TopLine Value="1310"/>
    8484        <CursorPos X="15" Y="1327"/>
    85         <UsageCount Value="9"/>
     85        <UsageCount Value="8"/>
    8686      </Unit3>
    8787      <Unit4>
     
    9090        <TopLine Value="346"/>
    9191        <CursorPos X="24" Y="351"/>
    92         <UsageCount Value="9"/>
     92        <UsageCount Value="8"/>
    9393      </Unit4>
    9494      <Unit5>
     
    9797        <TopLine Value="1"/>
    9898        <CursorPos X="1" Y="1"/>
    99         <UsageCount Value="9"/>
     99        <UsageCount Value="8"/>
    100100        <DefaultSyntaxHighlighter Value="XML"/>
    101101      </Unit5>
     
    106106        <TopLine Value="286"/>
    107107        <CursorPos X="1" Y="1"/>
    108         <UsageCount Value="9"/>
     108        <UsageCount Value="8"/>
    109109      </Unit6>
    110110      <Unit7>
     
    114114        <TopLine Value="8"/>
    115115        <CursorPos X="1" Y="1"/>
    116         <UsageCount Value="9"/>
     116        <UsageCount Value="8"/>
    117117        <DefaultSyntaxHighlighter Value="Delphi"/>
    118118      </Unit7>
     
    123123        <TopLine Value="56"/>
    124124        <CursorPos X="24" Y="77"/>
    125         <UsageCount Value="20"/>
     125        <UsageCount Value="19"/>
    126126        <DefaultSyntaxHighlighter Value="Delphi"/>
    127127      </Unit8>
     
    132132        <TopLine Value="264"/>
    133133        <CursorPos X="37" Y="141"/>
    134         <UsageCount Value="20"/>
     134        <UsageCount Value="19"/>
    135135        <DefaultSyntaxHighlighter Value="Delphi"/>
    136136      </Unit9>
     
    141141        <TopLine Value="302"/>
    142142        <CursorPos X="5" Y="33"/>
    143         <UsageCount Value="9"/>
     143        <UsageCount Value="8"/>
    144144      </Unit10>
    145145      <Unit11>
     
    148148        <TopLine Value="886"/>
    149149        <CursorPos X="20" Y="900"/>
    150         <UsageCount Value="9"/>
     150        <UsageCount Value="8"/>
    151151      </Unit11>
    152152      <Unit12>
     
    155155        <TopLine Value="1046"/>
    156156        <CursorPos X="34" Y="1053"/>
    157         <UsageCount Value="18"/>
     157        <UsageCount Value="17"/>
    158158      </Unit12>
    159159      <Unit13>
     
    162162        <TopLine Value="156"/>
    163163        <CursorPos X="21" Y="175"/>
    164         <UsageCount Value="9"/>
     164        <UsageCount Value="8"/>
    165165      </Unit13>
    166166      <Unit14>
     
    169169        <TopLine Value="45"/>
    170170        <CursorPos X="17" Y="62"/>
    171         <UsageCount Value="9"/>
     171        <UsageCount Value="8"/>
    172172      </Unit14>
    173173      <Unit15>
     
    176176        <TopLine Value="2271"/>
    177177        <CursorPos X="4" Y="2274"/>
    178         <UsageCount Value="12"/>
     178        <UsageCount Value="11"/>
    179179      </Unit15>
    180180      <Unit16>
     
    184184        <TopLine Value="290"/>
    185185        <CursorPos X="36" Y="306"/>
    186         <UsageCount Value="21"/>
     186        <UsageCount Value="20"/>
    187187      </Unit16>
    188188      <Unit17>
     
    191191        <TopLine Value="67"/>
    192192        <CursorPos X="10" Y="91"/>
    193         <UsageCount Value="9"/>
     193        <UsageCount Value="8"/>
    194194      </Unit17>
    195195      <Unit18>
     
    198198        <TopLine Value="1368"/>
    199199        <CursorPos X="3" Y="1385"/>
    200         <UsageCount Value="11"/>
     200        <UsageCount Value="10"/>
    201201      </Unit18>
    202202      <Unit19>
     
    205205        <TopLine Value="861"/>
    206206        <CursorPos X="1" Y="878"/>
    207         <UsageCount Value="10"/>
     207        <UsageCount Value="9"/>
    208208      </Unit19>
    209209      <Unit20>
     
    212212        <TopLine Value="32"/>
    213213        <CursorPos X="48" Y="50"/>
    214         <UsageCount Value="10"/>
     214        <UsageCount Value="9"/>
    215215      </Unit20>
    216216      <Unit21>
     
    219219        <TopLine Value="8"/>
    220220        <CursorPos X="11" Y="25"/>
    221         <UsageCount Value="12"/>
     221        <UsageCount Value="11"/>
    222222      </Unit21>
    223223      <Unit22>
     
    227227        <TopLine Value="1"/>
    228228        <CursorPos X="25" Y="9"/>
    229         <UsageCount Value="13"/>
     229        <UsageCount Value="12"/>
    230230      </Unit22>
    231231      <Unit23>
    232232        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/objpas/dateutil.inc"/>
    233         <EditorIndex Value="1"/>
    234233        <WindowIndex Value="0"/>
    235234        <TopLine Value="38"/>
    236235        <CursorPos X="29" Y="50"/>
    237         <UsageCount Value="13"/>
    238         <Loaded Value="True"/>
     236        <UsageCount Value="16"/>
    239237      </Unit23>
    240238      <Unit24>
    241239        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/objpas/sysutils/datih.inc"/>
    242         <EditorIndex Value="2"/>
    243240        <WindowIndex Value="0"/>
    244241        <TopLine Value="161"/>
    245242        <CursorPos X="11" Y="184"/>
    246         <UsageCount Value="13"/>
    247         <Loaded Value="True"/>
     243        <UsageCount Value="16"/>
    248244      </Unit24>
    249245      <Unit25>
     
    252248        <TopLine Value="254"/>
    253249        <CursorPos X="12" Y="258"/>
    254         <UsageCount Value="13"/>
     250        <UsageCount Value="12"/>
    255251      </Unit25>
    256252      <Unit26>
     
    260256        <TopLine Value="581"/>
    261257        <CursorPos X="11" Y="585"/>
    262         <UsageCount Value="13"/>
     258        <UsageCount Value="12"/>
    263259      </Unit26>
    264260      <Unit27>
     
    267263        <TopLine Value="525"/>
    268264        <CursorPos X="11" Y="538"/>
    269         <UsageCount Value="13"/>
     265        <UsageCount Value="12"/>
    270266      </Unit27>
    271267      <Unit28>
    272268        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/packages/fcl-base/src/syncobjs.pp"/>
    273269        <UnitName Value="syncobjs"/>
    274         <EditorIndex Value="11"/>
    275270        <WindowIndex Value="0"/>
    276271        <TopLine Value="57"/>
    277272        <CursorPos X="16" Y="70"/>
    278         <UsageCount Value="10"/>
    279         <Loaded Value="True"/>
     273        <UsageCount Value="13"/>
    280274      </Unit28>
    281275      <Unit29>
    282276        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/inc/threadh.inc"/>
    283         <EditorIndex Value="12"/>
    284277        <WindowIndex Value="0"/>
    285278        <TopLine Value="18"/>
    286279        <CursorPos X="50" Y="31"/>
    287         <UsageCount Value="10"/>
    288         <Loaded Value="True"/>
     280        <UsageCount Value="13"/>
    289281      </Unit29>
    290282      <Unit30>
    291283        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/inc/thread.inc"/>
    292         <EditorIndex Value="14"/>
    293284        <WindowIndex Value="0"/>
    294285        <TopLine Value="109"/>
    295286        <CursorPos X="3" Y="112"/>
    296         <UsageCount Value="10"/>
    297         <Loaded Value="True"/>
     287        <UsageCount Value="13"/>
    298288      </Unit30>
    299289      <Unit31>
    300290        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/win/sysosh.inc"/>
    301         <EditorIndex Value="13"/>
     291        <EditorIndex Value="3"/>
    302292        <WindowIndex Value="0"/>
    303293        <TopLine Value="12"/>
    304294        <CursorPos X="3" Y="25"/>
    305         <UsageCount Value="10"/>
     295        <UsageCount Value="13"/>
    306296        <Loaded Value="True"/>
    307297      </Unit31>
    308298      <Unit32>
    309299        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/objpas/classes/classesh.inc"/>
    310         <EditorIndex Value="6"/>
    311300        <WindowIndex Value="0"/>
    312301        <TopLine Value="1507"/>
    313302        <CursorPos X="3" Y="1469"/>
    314         <UsageCount Value="10"/>
    315         <Loaded Value="True"/>
     303        <UsageCount Value="13"/>
    316304      </Unit32>
    317305      <Unit33>
    318306        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/win/tthread.inc"/>
    319         <EditorIndex Value="8"/>
    320307        <WindowIndex Value="0"/>
    321308        <TopLine Value="96"/>
    322309        <CursorPos X="15" Y="98"/>
    323         <UsageCount Value="10"/>
    324         <Loaded Value="True"/>
     310        <UsageCount Value="13"/>
    325311      </Unit33>
    326312      <Unit34>
    327313        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/win/wininc/func.inc"/>
    328         <EditorIndex Value="10"/>
    329314        <WindowIndex Value="0"/>
    330315        <TopLine Value="130"/>
    331316        <CursorPos X="10" Y="143"/>
    332         <UsageCount Value="10"/>
    333         <Loaded Value="True"/>
     317        <UsageCount Value="13"/>
    334318      </Unit34>
    335319      <Unit35>
    336320        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/win/wininc/defines.inc"/>
    337         <EditorIndex Value="9"/>
    338321        <WindowIndex Value="0"/>
    339322        <TopLine Value="1923"/>
    340323        <CursorPos X="6" Y="1936"/>
    341         <UsageCount Value="10"/>
    342         <Loaded Value="True"/>
     324        <UsageCount Value="13"/>
    343325      </Unit35>
    344326      <Unit36>
    345327        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/objpas/classes/classes.inc"/>
    346         <EditorIndex Value="7"/>
    347328        <WindowIndex Value="0"/>
    348329        <TopLine Value="109"/>
    349330        <CursorPos X="6" Y="115"/>
    350         <UsageCount Value="10"/>
    351         <Loaded Value="True"/>
     331        <UsageCount Value="13"/>
    352332      </Unit36>
    353333      <Unit37>
    354334        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/inc/objpash.inc"/>
    355         <EditorIndex Value="5"/>
    356335        <WindowIndex Value="0"/>
    357336        <TopLine Value="181"/>
    358337        <CursorPos X="21" Y="194"/>
    359         <UsageCount Value="10"/>
    360         <Loaded Value="True"/>
     338        <UsageCount Value="13"/>
    361339      </Unit37>
    362340      <Unit38>
    363341        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/objpas/sysutils/osutilsh.inc"/>
    364         <EditorIndex Value="4"/>
    365342        <WindowIndex Value="0"/>
    366343        <TopLine Value="14"/>
    367344        <CursorPos X="11" Y="27"/>
     345        <UsageCount Value="13"/>
     346      </Unit38>
     347      <Unit39>
     348        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/lcl/include/control.inc"/>
     349        <WindowIndex Value="0"/>
     350        <TopLine Value="2275"/>
     351        <CursorPos X="39" Y="2285"/>
     352        <UsageCount Value="12"/>
     353      </Unit39>
     354      <Unit40>
     355        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/inc/systemh.inc"/>
     356        <EditorIndex Value="1"/>
     357        <WindowIndex Value="0"/>
     358        <TopLine Value="492"/>
     359        <CursorPos X="3" Y="504"/>
    368360        <UsageCount Value="10"/>
    369361        <Loaded Value="True"/>
    370       </Unit38>
     362      </Unit40>
     363      <Unit41>
     364        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/win/syswin.inc"/>
     365        <EditorIndex Value="5"/>
     366        <WindowIndex Value="0"/>
     367        <TopLine Value="197"/>
     368        <CursorPos X="30" Y="208"/>
     369        <UsageCount Value="10"/>
     370        <Loaded Value="True"/>
     371      </Unit41>
     372      <Unit42>
     373        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/inc/system.inc"/>
     374        <EditorIndex Value="4"/>
     375        <WindowIndex Value="0"/>
     376        <TopLine Value="737"/>
     377        <CursorPos X="21" Y="747"/>
     378        <UsageCount Value="10"/>
     379        <Loaded Value="True"/>
     380      </Unit42>
     381      <Unit43>
     382        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/inc/innr.inc"/>
     383        <EditorIndex Value="2"/>
     384        <WindowIndex Value="0"/>
     385        <TopLine Value="96"/>
     386        <CursorPos X="1" Y="1"/>
     387        <UsageCount Value="10"/>
     388        <Loaded Value="True"/>
     389      </Unit43>
    371390    </Units>
    372     <JumpHistory Count="30" HistoryIndex="28">
     391    <JumpHistory Count="30" HistoryIndex="29">
    373392      <Position1>
    374393        <Filename Value="../UMicroThreading.pas"/>
    375         <Caret Line="189" Column="1" TopLine="180"/>
     394        <Caret Line="322" Column="1" TopLine="315"/>
    376395      </Position1>
    377396      <Position2>
    378397        <Filename Value="../UMicroThreading.pas"/>
    379         <Caret Line="190" Column="1" TopLine="180"/>
     398        <Caret Line="328" Column="1" TopLine="315"/>
    380399      </Position2>
    381400      <Position3>
    382401        <Filename Value="../UMicroThreading.pas"/>
    383         <Caret Line="185" Column="1" TopLine="180"/>
     402        <Caret Line="363" Column="3" TopLine="350"/>
    384403      </Position3>
    385404      <Position4>
    386405        <Filename Value="../UMicroThreading.pas"/>
    387         <Caret Line="186" Column="1" TopLine="180"/>
     406        <Caret Line="322" Column="1" TopLine="309"/>
    388407      </Position4>
    389408      <Position5>
    390409        <Filename Value="../UMicroThreading.pas"/>
    391         <Caret Line="191" Column="1" TopLine="180"/>
     410        <Caret Line="326" Column="20" TopLine="309"/>
    392411      </Position5>
    393412      <Position6>
    394413        <Filename Value="../UMicroThreading.pas"/>
    395         <Caret Line="149" Column="1" TopLine="136"/>
     414        <Caret Line="169" Column="1" TopLine="156"/>
    396415      </Position6>
    397416      <Position7>
    398417        <Filename Value="../UMicroThreading.pas"/>
    399         <Caret Line="189" Column="1" TopLine="176"/>
     418        <Caret Line="363" Column="1" TopLine="350"/>
    400419      </Position7>
    401420      <Position8>
    402421        <Filename Value="../UMicroThreading.pas"/>
    403         <Caret Line="190" Column="1" TopLine="176"/>
     422        <Caret Line="322" Column="1" TopLine="309"/>
    404423      </Position8>
    405424      <Position9>
    406425        <Filename Value="../UMicroThreading.pas"/>
    407         <Caret Line="185" Column="1" TopLine="176"/>
     426        <Caret Line="330" Column="1" TopLine="309"/>
    408427      </Position9>
    409428      <Position10>
    410429        <Filename Value="../UMicroThreading.pas"/>
    411         <Caret Line="186" Column="1" TopLine="176"/>
     430        <Caret Line="316" Column="1" TopLine="309"/>
    412431      </Position10>
    413432      <Position11>
    414433        <Filename Value="../UMicroThreading.pas"/>
    415         <Caret Line="191" Column="1" TopLine="176"/>
     434        <Caret Line="169" Column="1" TopLine="156"/>
    416435      </Position11>
    417436      <Position12>
    418437        <Filename Value="../UMicroThreading.pas"/>
    419         <Caret Line="149" Column="1" TopLine="136"/>
     438        <Caret Line="316" Column="1" TopLine="303"/>
    420439      </Position12>
    421440      <Position13>
    422441        <Filename Value="../UMicroThreading.pas"/>
    423         <Caret Line="156" Column="1" TopLine="136"/>
     442        <Caret Line="330" Column="16" TopLine="317"/>
    424443      </Position13>
    425444      <Position14>
    426445        <Filename Value="../UMicroThreading.pas"/>
    427         <Caret Line="157" Column="1" TopLine="136"/>
     446        <Caret Line="363" Column="1" TopLine="350"/>
    428447      </Position14>
    429448      <Position15>
    430         <Filename Value="../UMicroThreading.pas"/>
    431         <Caret Line="158" Column="1" TopLine="136"/>
     449        <Filename Value="UMainForm.pas"/>
     450        <Caret Line="228" Column="1" TopLine="208"/>
    432451      </Position15>
    433452      <Position16>
    434         <Filename Value="../UMicroThreading.pas"/>
    435         <Caret Line="189" Column="1" TopLine="176"/>
     453        <Filename Value="UMainForm.pas"/>
     454        <Caret Line="235" Column="1" TopLine="215"/>
    436455      </Position16>
    437456      <Position17>
    438         <Filename Value="../UMicroThreading.pas"/>
    439         <Caret Line="190" Column="1" TopLine="176"/>
     457        <Filename Value="UMainForm.pas"/>
     458        <Caret Line="184" Column="28" TopLine="182"/>
    440459      </Position17>
    441460      <Position18>
    442         <Filename Value="../UMicroThreading.pas"/>
    443         <Caret Line="409" Column="21" TopLine="387"/>
     461        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/inc/system.inc"/>
     462        <Caret Line="660" Column="22" TopLine="656"/>
    444463      </Position18>
    445464      <Position19>
    446465        <Filename Value="../UMicroThreading.pas"/>
    447         <Caret Line="206" Column="18" TopLine="201"/>
     466        <Caret Line="527" Column="78" TopLine="504"/>
    448467      </Position19>
    449468      <Position20>
    450469        <Filename Value="../UMicroThreading.pas"/>
    451         <Caret Line="21" Column="15" TopLine="7"/>
     470        <Caret Line="531" Column="51" TopLine="513"/>
    452471      </Position20>
    453472      <Position21>
    454         <Filename Value="../UMicroThreading.pas"/>
    455         <Caret Line="123" Column="50" TopLine="110"/>
     473        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/win/syswin.inc"/>
     474        <Caret Line="208" Column="27" TopLine="194"/>
    456475      </Position21>
    457476      <Position22>
    458477        <Filename Value="../UMicroThreading.pas"/>
    459         <Caret Line="165" Column="29" TopLine="145"/>
     478        <Caret Line="531" Column="46" TopLine="522"/>
    460479      </Position22>
    461480      <Position23>
    462481        <Filename Value="../UMicroThreading.pas"/>
    463         <Caret Line="148" Column="31" TopLine="135"/>
     482        <Caret Line="161" Column="27" TopLine="158"/>
    464483      </Position23>
    465484      <Position24>
    466485        <Filename Value="../UMicroThreading.pas"/>
    467         <Caret Line="165" Column="26" TopLine="152"/>
     486        <Caret Line="195" Column="43" TopLine="180"/>
    468487      </Position24>
    469488      <Position25>
    470489        <Filename Value="../UMicroThreading.pas"/>
    471         <Caret Line="148" Column="31" TopLine="148"/>
     490        <Caret Line="211" Column="43" TopLine="198"/>
    472491      </Position25>
    473492      <Position26>
    474493        <Filename Value="../UMicroThreading.pas"/>
    475         <Caret Line="150" Column="31" TopLine="135"/>
     494        <Caret Line="241" Column="45" TopLine="226"/>
    476495      </Position26>
    477496      <Position27>
    478497        <Filename Value="../UMicroThreading.pas"/>
    479         <Caret Line="80" Column="33" TopLine="68"/>
     498        <Caret Line="542" Column="1" TopLine="524"/>
    480499      </Position27>
    481500      <Position28>
    482501        <Filename Value="../UMicroThreading.pas"/>
    483         <Caret Line="143" Column="12" TopLine="136"/>
     502        <Caret Line="538" Column="39" TopLine="525"/>
    484503      </Position28>
    485504      <Position29>
    486505        <Filename Value="../UMicroThreading.pas"/>
    487         <Caret Line="144" Column="36" TopLine="128"/>
     506        <Caret Line="181" Column="1" TopLine="155"/>
    488507      </Position29>
    489508      <Position30>
    490         <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/objpas/sysutils/osutilsh.inc"/>
    491         <Caret Line="27" Column="11" TopLine="14"/>
     509        <Filename Value="../UMicroThreading.pas"/>
     510        <Caret Line="350" Column="22" TopLine="337"/>
    492511      </Position30>
    493512    </JumpHistory>
     
    525544      <Item3>
    526545        <Source Value="umainform.pas"/>
    527         <Line Value="58"/>
     546        <Line Value="62"/>
    528547      </Item3>
    529548      <Item4>
  • MicroThreading/Demo/UMainForm.lfm

    r142 r144  
    11object Form1: TForm1
    2   Left = 298
     2  Left = 300
    33  Height = 510
    4   Top = 144
     4  Top = 137
    55  Width = 703
    66  Caption = 'MicroThreading demo'
     
    9898  end
    9999  object Button4: TButton
    100     Left = 136
     100    Left = 120
    101101    Height = 25
    102102    Top = 12
    103     Width = 75
     103    Width = 88
    104104    Caption = 'Start workers'
    105105    OnClick = Button4Click
     
    116116    Value = 20
    117117  end
     118  object Button5: TButton
     119    Left = 168
     120    Height = 25
     121    Top = 48
     122    Width = 131
     123    Caption = 'Get max TThread count'
     124    OnClick = Button5Click
     125    TabOrder = 7
     126  end
     127  object Button6: TButton
     128    Left = 88
     129    Height = 25
     130    Top = 48
     131    Width = 75
     132    Caption = 'Button6'
     133    OnClick = Button6Click
     134    TabOrder = 8
     135  end
    118136  object Timer1: TTimer
    119137    Interval = 100
  • MicroThreading/Demo/UMainForm.pas

    r142 r144  
    2424    Button3: TButton;
    2525    Button4: TButton;
     26    Button5: TButton;
     27    Button6: TButton;
    2628    Label1: TLabel;
    2729    Label2: TLabel;
     
    3436    procedure Button3Click(Sender: TObject);
    3537    procedure Button4Click(Sender: TObject);
     38    procedure Button5Click(Sender: TObject);
     39    procedure Button6Click(Sender: TObject);
    3640    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    3741    procedure FormCreate(Sender: TObject);
     
    157161  for I := 0 to SpinEdit1.Value do
    158162    Scheduler.AddMethod(Worker);
     163end;
     164
     165procedure TForm1.Button5Click(Sender: TObject);
     166var
     167  NewThread: TThread;
     168  I: Integer;
     169begin
     170  try
     171    I := 0;
     172    while True do begin
     173      NewThread := TThread.Create(True);
     174      NewThread.FreeOnTerminate:= False;
     175      Inc(I);
     176    end;
     177  except
     178    ShowMessage('Application can create ' + IntToStr(I) +' TThread instances');
     179  end;
     180end;
     181
     182procedure TForm1.Button6Click(Sender: TObject);
     183begin
     184  ShowMessage(IntToStr(GetThreadID));
    159185end;
    160186
  • MicroThreading/UMicroThreading.pas

    r143 r144  
    1717  TMicroThread = class;
    1818  TMicroThreadScheduler = class;
     19  TMicroThreadManager = class;
    1920
    2021  TMicroThreadState = (tsWaiting, tsRunning, tsBlocked, tsSuspended,
    2122    tsSleeping);
    22 
    2323
    2424  { TMicroThread }
     
    2727  private
    2828    FFreeOnTerminate: Boolean;
    29     FStack: Pointer;
    30     FStackSize: Integer;
    3129    FExecutionStartTime: TDateTime;
    3230    FExecutionEndTime: TDateTime;
    3331    FExecutionTime: TDateTime;
     32    FStack: Pointer;
    3433    FStackPointer: Pointer;
     34    FStackSize: Integer;
    3535    FBasePointer: Pointer;
    3636    FWakeupTime: TDateTime;
     
    4343    Priority: Integer;
    4444    State: TMicroThreadState;
     45    Manager: TMicroThreadManager;
    4546    Scheduler: TMicroThreadScheduler;
    4647    procedure Execute; virtual;
     
    7980  TMicroThreadSchedulerPoolThread = class(TThread)
    8081    Scheduler: TMicroThreadScheduler;
     82    Manager: TMicroThreadManager;
    8183    procedure Execute; override;
    8284  end;
     
    8486  TThreadPool = class(TObjectList)
    8587
     88  end;
     89
     90  { TMicroThreadManager }
     91
     92  TMicroThreadManager = class
     93  private
     94    FStack: Pointer;
     95    FStackSize: Pointer;
     96    FStackPointer: Pointer;
     97    FBasePointer: Pointer;
     98    FSelected: TMicroThread;
     99    FExecuteCount: Integer;
     100    FExecutedCount: Integer;
     101    FTerminated: Boolean;
     102    FTempPointer: Pointer;
     103    function Execute(Count: Integer): Integer;
     104  public
     105    Scheduler: TMicroThreadScheduler;
     106    CurrentMicroThread: TMicroThread;
     107    procedure Yield(MicroThread: TMicroThread);
     108    constructor Create;
     109    destructor Destroy; override;
    86110  end;
    87111
     
    93117    RoundRobinIndex: Integer;
    94118    LastId: Integer;
    95     FMainStackPointer: Pointer;
    96     FMainBasePointer: Pointer;
    97     FSelected: TMicroThread;
    98     FTempPointer: Pointer;
    99119    FFrequency: Int64;
    100     FExecuteCount: Integer;
    101     FExecutedCount: Integer;
     120    FThreadPoolSize: Integer;
    102121    FTerminated: Boolean;
    103     FThreadPoolSize: Integer;
    104122    function GetMicroThreadCount: Integer;
    105123    function GetThreadPoolSize: Integer;
    106124    procedure SetThreadPoolSize(const AValue: Integer);
    107     procedure Yield(MicroThread: TMicroThread);
     125    function GetNextMicroThread: TMicroThread;
    108126  public
     127    MainThreadManager: TMicroThreadManager;
    109128    MicroThreads: TObjectList; // TList<TMicroThread>
    110129    Lock: TCriticalSection;
    111     CurrentMicroThread: TMicroThread;
    112130    function GetNow: TDateTime;
    113131    function Add(MicroThread: TMicroThread): Integer;
     
    115133    constructor Create;
    116134    destructor Destroy; override;
    117     function Execute(Count: Integer): Integer;
    118135    procedure Start;
    119136    procedure Stop;
     
    132149implementation
    133150
    134 { TMicroThreadSchedulerPoolThread }
    135 
    136 procedure TMicroThreadSchedulerPoolThread.Execute;
    137 var
    138   ExecutedCount: Integer;
    139 begin
    140   inherited Execute;
    141   try
    142     repeat
    143       ExecutedCount := Scheduler.Execute(10);
    144       if ExecutedCount = 0 then Sleep(1);
    145     until Terminated;
    146   except
    147     on E: Exception do
    148       //ExceptionHandler(E);
    149   end;
    150 end;
    151 
    152 { TMicroThreadMethod }
    153 
    154 procedure TMicroThreadMethod.Execute;
    155 begin
    156   inherited Execute;
    157   Method(Self);
    158 end;
    159 
    160 
    161 { TMicroThread }
    162 
    163 procedure TMicroThread.Execute;
    164 begin
    165 
    166 end;
    167 
    168 procedure TMicroThread.Yield;
    169 begin
    170   Scheduler.Yield(Self);
    171 end;
    172 
    173 procedure TMicroThread.WaitFor;
    174 begin
    175   while not FFinished do begin
    176     Sleep(1);
    177   end;
    178 end;
    179 
    180 procedure TMicroThread.Sleep(Duration: TDateTime);
    181 begin
    182   FWakeUpTime := Scheduler.GetNow + Duration;
    183   State := tsSleeping;
    184   Yield;
    185 end;
    186 
    187 function TMicroThread.WaitForSignal(Signal: TEvent): TWaitResult;
    188 begin
    189   repeat
    190     Result := Signal.WaitFor(1);
    191     Sleep(1);
    192   until Result <> wrTimeout;
    193 end;
    194 
    195 constructor TMicroThread.Create(CreateSuspended: Boolean;
    196   const StackSize: SizeUInt = DefaultStackSize);
    197 begin
    198   FStackSize := StackSize;
    199   FStack := GetMem(FStackSize);
    200   FBasePointer := FStack + FStackSize;
    201   FStackPointer := FBasePointer - 20;
    202   FExecutionTime := 0;
    203   FTerminated := False;
    204   if CreateSuspended then
    205     State := tsSuspended;
    206   FFreeOnTerminate := True;
    207 end;
    208 
    209 procedure TMicroThread.Terminate;
    210 begin
    211   FTerminated := True;
    212 end;
    213 
    214 destructor TMicroThread.Destroy;
    215 begin
    216   Terminate;
    217   WaitFor;
    218   // Microthread is finished, remove it from queue
    219   try
    220     Scheduler.Lock.Acquire;
    221     Scheduler.MicroThreads.Delete(Scheduler.MicroThreads.IndexOf(Self));
    222   finally
    223     Scheduler.Lock.Release;
    224   end;
    225   FreeMem(FStack);
    226   inherited Destroy;
    227 end;
    228 
    229 procedure TMicroThread.Start;
    230 begin
    231   State := tsWaiting;
    232 end;
    233 
    234 procedure TMicroThread.Stop;
    235 begin
    236   State := tsSuspended;
    237 end;
    238 
    239 
    240 { TMicroThreadScheduler }
    241 
    242 function TMicroThreadScheduler.GetNow: TDateTime;
    243 var
    244   {$IFDEF Linux}T: TimeVal;{$ENDIF}
    245   {$IFDEF Windows}TimerValue: Int64;{$ENDIF}
    246 begin
    247   {$IFDEF Windows}
    248   QueryPerformanceCounter(TimerValue);
    249   //Result := Int64(TimeStampToMSecs(DateTimeToTimeStamp(Now)) * 1000) // an alternative Win32 timebase
    250   Result := TimerValue / FFrequency;
    251   {$ENDIF}
    252   {$IFDEF Linux}
    253   fpgettimeofday(@t, nil);
    254    // Build a 64 bit microsecond tick from the seconds and microsecond longints
    255   Result := (Int64(t.tv_sec) * 1000000) + t.tv_usec;
    256   {$ENDIF}
    257 
    258   Result := (Trunc(Now / OneSecond) + Frac(Result)) * OneSecond;
    259 end;
    260 
    261 function TMicroThreadScheduler.Add(MicroThread: TMicroThread): Integer;
    262 begin
    263   Inc(LastId);
    264   MicroThread.Scheduler := Self;
    265   MicroThread.Id := LastId;
    266   Result := MicroThreads.Add(MicroThread);
    267 end;
    268 
    269 function TMicroThreadScheduler.AddMethod(Method: TMicroThreadEvent): Integer;
    270 var
    271   NewMicroThread: TMicroThreadMethod;
    272 begin
    273   NewMicroThread := TMicroThreadMethod.Create(False);
    274   NewMicroThread.Method := Method;
    275   NewMicroThread.Scheduler := Self;
    276   Result := Add(NewMicroThread);
    277 end;
    278 
    279 constructor TMicroThreadScheduler.Create;
    280 begin
    281   Lock := TCriticalSection.Create;
    282   MicroThreads := TObjectList.Create;
    283   ThreadPool := TThreadPool.Create;
    284   {$IFDEF Windows}
    285   QueryPerformanceFrequency(FFrequency);
    286   {$ENDIF}
    287   RoundRobinIndex := -1;
    288 end;
    289 
    290 destructor TMicroThreadScheduler.Destroy;
    291 begin
    292   FTerminated := True;
    293   ThreadPool.Free;
    294   MicroThreads.Free;
    295   Lock.Free;
    296   inherited Destroy;
    297 end;
    298 
    299 function TMicroThreadScheduler.Execute(Count: Integer): Integer;
    300 begin
     151var
     152  StaticManagers: TObjectList; // TList<TMicroThreadManager>;
     153  StaticManager: TMicroThreadManager;
     154  StaticMicroThread: TMicroThread;
     155
     156  function GetMicroThreadId: Integer;
     157  var
     158    I: Integer;
     159    CurrentStack: Pointer;
     160  begin
     161    asm
     162      mov CurrentStack, sp
     163    end;
     164    with MainScheduler do begin
     165      try
     166        Lock.Acquire;
     167        I := 0;
     168        while (I < MicroThreads.Count) and
     169          not ((CurrentStack >= TMicroThread(MicroThreads[I]).FStack) and
     170          (CurrentStack <= (TMicroThread(MicroThreads[I]).FStack +
     171          TMicroThread(MicroThreads[I]).FStackSize))) do Inc(I);
     172        if I < MicroThreads.Count then begin
     173          Result := TMicroThread(MicroThreads[I]).Id;
     174        end else Result := -1;
     175      finally
     176        Lock.Release;
     177      end;
     178    end;
     179  end;
     180
     181{ TMicroThreadManager }
     182
     183function TMicroThreadManager.Execute(Count: Integer): Integer;
     184begin
     185  FStack := StackBottom;
     186  FStackSize := StackBottom + StackLength;
    301187  FExecuteCount := Count;
    302188  FExecutedCount := 0;
     
    305191end;
    306192
    307 procedure TMicroThreadScheduler.Start;
    308 var
    309   Executed: Integer;
    310 begin
    311   FTerminated := False;
    312   repeat
    313     Executed := Execute(10);
    314     Application.ProcessMessages;
    315     if Executed = 0 then Sleep(1);
    316   until FTerminated;
    317 end;
    318 
    319 procedure TMicroThreadScheduler.Stop;
    320 begin
    321   FTerminated := True;
    322 end;
    323 
    324 var
    325   StaticMicroThread: TMicroThread;
    326   StaticScheduler: TMicroThreadScheduler;
    327 
    328 procedure TMicroThreadScheduler.Yield(MicroThread: TMicroThread);
     193procedure TMicroThreadManager.Yield(MicroThread: TMicroThread);
    329194var
    330195  I: Integer;
    331196  Time: TDateTime;
    332197begin
    333   Time := GetNow;
     198  Time := Scheduler.GetNow;
    334199  if Assigned(MicroThread) then begin
     200    MicroThread.Manager := nil;
    335201    MicroThread.FExecutionEndTime := Time;
    336202    MicroThread.FExecutionTime := MicroThread.FExecutionTime +
     
    346212      mov [eax].TMicroThread.FBasePointer, edx
    347213    end;
    348     StaticScheduler := MicroThread.Scheduler;
     214    StaticManager := MicroThread.Manager;
    349215    asm
    350216      // Restore scheduler stack
    351       mov eax, StaticScheduler  // Self is invalid before BP restore
    352       mov edx, [eax].TMicroThreadScheduler.FMainStackPointer
     217      mov eax, StaticManager  // Self is invalid before BP restore
     218      mov edx, [eax].TMicroThreadManager.FStackPointer
    353219      mov esp, edx
    354       mov edx, [eax].TMicroThreadScheduler.FMainBasePointer
     220      mov edx, [eax].TMicroThreadManager.FBasePointer
    355221      mov ebp, edx
    356222    end;
     
    358224  end;
    359225
    360   // Try to find new microthread for execution
    361   FSelected := nil;
     226  FSelected := Scheduler.GetNextMicroThread;
     227
     228  if Assigned(FSelected) and (FExecutedCount < FExecuteCount) then begin
     229    FSelected.Manager := Self;
     230    Inc(FExecutedCount);
     231    CurrentMicroThread := FSelected;
     232    asm
     233      // Store scheduler stack
     234      mov eax, Self
     235      mov edx, esp
     236      mov [eax].TMicroThreadManager.FStackPointer, edx
     237      mov edx, ebp
     238      mov [eax].TMicroThreadManager.FBasePointer, edx
     239    end;
     240    if not FSelected.FExecuted then begin
     241      FSelected.FExecuted := True;
     242      FSelected.State := tsRunning;
     243      FSelected.FExecutionStartTime := Time;
     244      FTempPointer := FSelected.FStackPointer;
     245      asm
     246        // Restore microthread stack
     247        mov eax, Self
     248        mov edx, [eax].TMicroThreadManager.FTempPointer
     249        mov esp, edx
     250      end;
     251      StaticMicroThread := FSelected; // BP will be change and Self pointer will be invalid
     252      FTempPointer := FSelected.FBasePointer;
     253      asm
     254        mov eax, Self
     255        mov edx, [eax].TMicroThreadManager.FTempPointer
     256        mov ebp, edx
     257      end;
     258      StaticMicroThread.Execute;
     259      //FSelected.Method(FSelected);
     260      StaticManager := StaticMicroThread.Manager;
     261      asm
     262        // Restore scheduler stack
     263        mov eax, StaticManager // Self is invalid before BP restore
     264        mov edx, [eax].TMicroThreadManager.FStackPointer
     265        mov esp, edx
     266        mov edx, [eax].TMicroThreadManager.FBasePointer
     267        mov ebp, edx
     268      end;
     269      FSelected.Manager := nil;
     270      FSelected.FExecutionEndTime := Time;
     271      FSelected.FExecutionTime := FSelected.FExecutionTime +
     272       (FSelected.FExecutionEndTime - FSelected.FExecutionStartTime);
     273      FSelected.FFinished := True;
     274      if FSelected.FFreeOnTerminate then begin
     275        FSelected.Free;
     276      end;;
     277    end else
     278    if FSelected.State = tsWaiting then begin
     279      // Execute selected thread
     280      FSelected.State := tsRunning;
     281      FSelected.FExecutionStartTime := Time;
     282      FTempPointer := FSelected.FStackPointer;
     283      asm
     284        // Restore microthread stack
     285        mov eax, Self
     286        mov edx, [eax].TMicroThreadManager.FTempPointer
     287        mov esp, edx
     288      end;
     289      FTempPointer := FSelected.FBasePointer;
     290      asm
     291        mov eax, Self
     292        mov edx, [eax].TMicroThreadManager.FTempPointer
     293        mov ebp, edx
     294      end;
     295    end;
     296  end;
     297end;
     298
     299constructor TMicroThreadManager.Create;
     300begin
     301
     302end;
     303
     304destructor TMicroThreadManager.Destroy;
     305begin
     306  inherited Destroy;
     307end;
     308
     309{ TMicroThreadSchedulerPoolThread }
     310
     311procedure TMicroThreadSchedulerPoolThread.Execute;
     312var
     313  ExecutedCount: Integer;
     314begin
     315  inherited Execute;
     316  try
     317    repeat
     318      ExecutedCount := Manager.Execute(10);
     319      if ExecutedCount = 0 then Sleep(1);
     320    until Terminated;
     321  except
     322    on E: Exception do
     323      //ExceptionHandler(E);
     324  end;
     325end;
     326
     327{ TMicroThreadMethod }
     328
     329procedure TMicroThreadMethod.Execute;
     330begin
     331  inherited Execute;
     332  Method(Self);
     333end;
     334
     335
     336{ TMicroThread }
     337
     338procedure TMicroThread.Execute;
     339begin
     340
     341end;
     342
     343procedure TMicroThread.Yield;
     344begin
     345  Manager.Yield(Self);
     346end;
     347
     348procedure TMicroThread.WaitFor;
     349begin
     350  if GetMicroThreadId <> -1 then
     351  while not FFinished do begin
     352    Sleep(1);
     353  end;
     354end;
     355
     356procedure TMicroThread.Sleep(Duration: TDateTime);
     357begin
     358  FWakeUpTime := Scheduler.GetNow + Duration;
     359  State := tsSleeping;
     360  Yield;
     361end;
     362
     363function TMicroThread.WaitForSignal(Signal: TEvent): TWaitResult;
     364begin
     365  repeat
     366    Result := Signal.WaitFor(1);
     367    Sleep(1);
     368  until Result <> wrTimeout;
     369end;
     370
     371constructor TMicroThread.Create(CreateSuspended: Boolean;
     372  const StackSize: SizeUInt = DefaultStackSize);
     373begin
     374  FStackSize := StackSize;
     375  FStack := GetMem(FStackSize);
     376  FBasePointer := FStack + FStackSize;
     377  FStackPointer := FBasePointer - 20;
     378  FExecutionTime := 0;
     379  FTerminated := False;
     380  if CreateSuspended then
     381    State := tsSuspended;
     382  FFreeOnTerminate := True;
     383end;
     384
     385procedure TMicroThread.Terminate;
     386begin
     387  FTerminated := True;
     388end;
     389
     390destructor TMicroThread.Destroy;
     391begin
     392  Terminate;
     393  WaitFor;
     394  // Microthread is finished, remove it from queue
     395  try
     396    Manager.Scheduler.Lock.Acquire;
     397    Manager.Scheduler.MicroThreads.Delete(Manager.Scheduler.MicroThreads.IndexOf(Self));
     398  finally
     399    Manager.Scheduler.Lock.Release;
     400  end;
     401  FreeMem(FStack);
     402  inherited Destroy;
     403end;
     404
     405procedure TMicroThread.Start;
     406begin
     407  State := tsWaiting;
     408end;
     409
     410procedure TMicroThread.Stop;
     411begin
     412  State := tsSuspended;
     413end;
     414
     415
     416{ TMicroThreadScheduler }
     417
     418function TMicroThreadScheduler.GetNow: TDateTime;
     419var
     420  {$IFDEF Linux}T: TimeVal;{$ENDIF}
     421  {$IFDEF Windows}TimerValue: Int64;{$ENDIF}
     422begin
     423  {$IFDEF Windows}
     424  QueryPerformanceCounter(TimerValue);
     425  //Result := Int64(TimeStampToMSecs(DateTimeToTimeStamp(Now)) * 1000) // an alternative Win32 timebase
     426  Result := TimerValue / FFrequency;
     427  {$ENDIF}
     428
     429  {$IFDEF Linux}
     430  fpgettimeofday(@t, nil);
     431   // Build a 64 bit microsecond tick from the seconds and microsecond longints
     432  Result := (Int64(t.tv_sec) * 1000000) + t.tv_usec;
     433  {$ENDIF}
     434
     435  Result := (Trunc(Now / OneSecond) + Frac(Result)) * OneSecond;
     436end;
     437
     438function TMicroThreadScheduler.Add(MicroThread: TMicroThread): Integer;
     439begin
     440  Inc(LastId);
     441  MicroThread.Scheduler := Self;
     442  MicroThread.Id := LastId;
     443  Result := MicroThreads.Add(MicroThread);
     444end;
     445
     446function TMicroThreadScheduler.AddMethod(Method: TMicroThreadEvent): Integer;
     447var
     448  NewMicroThread: TMicroThreadMethod;
     449begin
     450  NewMicroThread := TMicroThreadMethod.Create(False);
     451  NewMicroThread.Method := Method;
     452  NewMicroThread.Scheduler := Self;
     453  Result := Add(NewMicroThread);
     454end;
     455
     456constructor TMicroThreadScheduler.Create;
     457begin
     458  Lock := TCriticalSection.Create;
     459  MicroThreads := TObjectList.Create;
     460  ThreadPool := TThreadPool.Create;
     461  {$IFDEF Windows}
     462  QueryPerformanceFrequency(FFrequency);
     463  {$ENDIF}
     464  RoundRobinIndex := -1;
     465  MainThreadManager := TMicroThreadManager.Create;
     466  MainThreadManager.Scheduler := Self;
     467end;
     468
     469destructor TMicroThreadScheduler.Destroy;
     470begin
     471  MainThreadManager.Free;
     472  FTerminated := True;
     473  ThreadPool.Free;
     474  MicroThreads.Free;
     475  Lock.Free;
     476  inherited Destroy;
     477end;
     478
     479procedure TMicroThreadScheduler.Start;
     480var
     481  Executed: Integer;
     482begin
     483  FTerminated := False;
     484  repeat
     485    Executed := MainThreadManager.Execute(10);
     486    Application.ProcessMessages;
     487    if Executed = 0 then Sleep(1);
     488  until FTerminated;
     489end;
     490
     491procedure TMicroThreadScheduler.Stop;
     492begin
     493  FTerminated := True;
     494end;
     495
     496function TMicroThreadScheduler.GetNextMicroThread: TMicroThread;
     497var
     498  I: Integer;
     499begin
     500  Result := nil;
    362501  try
    363502    Lock.Acquire;
     
    381520    end;
    382521    if I < MicroThreads.Count then begin
    383       FSelected := TMicroThread(MicroThreads[RoundRobinIndex]);
     522      Result := TMicroThread(MicroThreads[RoundRobinIndex]);
    384523    end;
    385524  finally
    386525    Lock.Release;
    387   end;
    388 
    389   if Assigned(FSelected) and (FExecutedCount < FExecuteCount) then begin
    390     Inc(FExecutedCount);
    391     CurrentMicroThread := FSelected;
    392     asm
    393       // Store scheduler stack
    394       mov eax, Self
    395       mov edx, esp
    396       mov [eax].TMicroThreadScheduler.FMainStackPointer, edx
    397       mov edx, ebp
    398       mov [eax].TMicroThreadScheduler.FMainBasePointer, edx
    399     end;
    400     if not FSelected.FExecuted then begin
    401       FSelected.FExecuted := True;
    402       FSelected.State := tsRunning;
    403       FSelected.FExecutionStartTime := Time;
    404       FTempPointer := FSelected.FStackPointer;
    405       asm
    406         // Restore microthread stack
    407         mov eax, Self
    408         mov edx, [eax].TMicroThreadScheduler.FTempPointer
    409         mov esp, edx
    410       end;
    411       StaticMicroThread := FSelected; // BP will be change and Self pointer will be invalid
    412       FTempPointer := FSelected.FBasePointer;
    413       asm
    414         mov eax, Self
    415         mov edx, [eax].TMicroThreadScheduler.FTempPointer
    416         mov ebp, edx
    417       end;
    418       StaticMicroThread.Execute;
    419       //FSelected.Method(FSelected);
    420       StaticScheduler := StaticMicroThread.Scheduler;
    421       asm
    422         // Restore scheduler stack
    423         mov eax, StaticScheduler // Self is invalid before BP restore
    424         mov edx, [eax].TMicroThreadScheduler.FMainStackPointer
    425         mov esp, edx
    426         mov edx, [eax].TMicroThreadScheduler.FMainBasePointer
    427         mov ebp, edx
    428       end;
    429       FSelected.FExecutionEndTime := Time;
    430       FSelected.FExecutionTime := FSelected.FExecutionTime +
    431        (FSelected.FExecutionEndTime - FSelected.FExecutionStartTime);
    432       FSelected.FFinished := True;
    433       if FSelected.FFreeOnTerminate then begin
    434         FSelected.Free;
    435       end;;
    436     end else
    437     if FSelected.State = tsWaiting then begin
    438       // Execute selected thread
    439       FSelected.State := tsRunning;
    440       FSelected.FExecutionStartTime := Time;
    441       FTempPointer := FSelected.FStackPointer;
    442       asm
    443         // Restore microthread stack
    444         mov eax, Self
    445         mov edx, [eax].TMicroThreadScheduler.FTempPointer
    446         mov esp, edx
    447       end;
    448       FTempPointer := FSelected.FBasePointer;
    449       asm
    450         mov eax, Self
    451         mov edx, [eax].TMicroThreadScheduler.FTempPointer
    452         mov ebp, edx
    453       end;
    454     end;
    455526  end;
    456527end;
     
    478549initialization
    479550
     551StaticManagers := TObjectList.Create;
    480552MainScheduler := TMicroThreadScheduler.Create;
    481553
     
    483555
    484556MainScheduler.Free;
     557StaticManagers.Free;
    485558
    486559end.
Note: See TracChangeset for help on using the changeset viewer.