Changeset 156 for MicroThreading


Ignore:
Timestamp:
Jan 28, 2011, 2:12:42 PM (13 years ago)
Author:
george
Message:
  • Modified: Restructuralized code for support for pending state changes.
Location:
MicroThreading
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • MicroThreading/Demo/Demo.lpi

    r155 r156  
    3939      </Item2>
    4040    </RequiredPackages>
    41     <Units Count="63">
     41    <Units Count="65">
    4242      <Unit0>
    4343        <Filename Value="Demo.lpr"/>
    4444        <IsPartOfProject Value="True"/>
    4545        <UnitName Value="Demo"/>
    46         <EditorIndex Value="4"/>
    4746        <WindowIndex Value="0"/>
    4847        <TopLine Value="1"/>
    49         <CursorPos X="21" Y="18"/>
    50         <UsageCount Value="70"/>
    51         <Loaded Value="True"/>
     48        <CursorPos X="34" Y="16"/>
     49        <UsageCount Value="82"/>
    5250      </Unit0>
    5351      <Unit1>
     
    5755        <ResourceBaseClass Value="Form"/>
    5856        <UnitName Value="UMainForm"/>
    59         <EditorIndex Value="0"/>
    60         <WindowIndex Value="0"/>
    61         <TopLine Value="206"/>
    62         <CursorPos X="1" Y="211"/>
    63         <UsageCount Value="70"/>
     57        <EditorIndex Value="9"/>
     58        <WindowIndex Value="0"/>
     59        <TopLine Value="270"/>
     60        <CursorPos X="1" Y="284"/>
     61        <UsageCount Value="82"/>
    6462        <Loaded Value="True"/>
    6563        <LoadedDesigner Value="True"/>
     
    6967        <UnitName Value="UMicroThreading"/>
    7068        <IsVisibleTab Value="True"/>
    71         <EditorIndex Value="2"/>
    72         <WindowIndex Value="0"/>
    73         <TopLine Value="708"/>
    74         <CursorPos X="24" Y="718"/>
    75         <UsageCount Value="37"/>
     69        <EditorIndex Value="0"/>
     70        <WindowIndex Value="0"/>
     71        <TopLine Value="513"/>
     72        <CursorPos X="9" Y="525"/>
     73        <UsageCount Value="43"/>
    7674        <Loaded Value="True"/>
    7775      </Unit2>
     
    8280        <TopLine Value="55"/>
    8381        <CursorPos X="3" Y="70"/>
    84         <UsageCount Value="9"/>
     82        <UsageCount Value="8"/>
    8583      </Unit3>
    8684      <Unit4>
     
    8987        <TopLine Value="346"/>
    9088        <CursorPos X="24" Y="351"/>
    91         <UsageCount Value="7"/>
     89        <UsageCount Value="6"/>
    9290      </Unit4>
    9391      <Unit5>
     
    9694        <TopLine Value="1"/>
    9795        <CursorPos X="1" Y="1"/>
    98         <UsageCount Value="7"/>
     96        <UsageCount Value="6"/>
    9997        <DefaultSyntaxHighlighter Value="XML"/>
    10098      </Unit5>
     
    105103        <TopLine Value="286"/>
    106104        <CursorPos X="1" Y="1"/>
    107         <UsageCount Value="7"/>
     105        <UsageCount Value="6"/>
    108106      </Unit6>
    109107      <Unit7>
     
    113111        <TopLine Value="1"/>
    114112        <CursorPos X="1" Y="8"/>
    115         <UsageCount Value="9"/>
     113        <UsageCount Value="8"/>
    116114        <DefaultSyntaxHighlighter Value="Delphi"/>
    117115      </Unit7>
     
    122120        <TopLine Value="56"/>
    123121        <CursorPos X="24" Y="77"/>
    124         <UsageCount Value="18"/>
     122        <UsageCount Value="17"/>
    125123        <DefaultSyntaxHighlighter Value="Delphi"/>
    126124      </Unit8>
     
    131129        <TopLine Value="264"/>
    132130        <CursorPos X="37" Y="141"/>
    133         <UsageCount Value="18"/>
     131        <UsageCount Value="17"/>
    134132        <DefaultSyntaxHighlighter Value="Delphi"/>
    135133      </Unit9>
     
    140138        <TopLine Value="302"/>
    141139        <CursorPos X="5" Y="33"/>
    142         <UsageCount Value="7"/>
     140        <UsageCount Value="6"/>
    143141      </Unit10>
    144142      <Unit11>
     
    147145        <TopLine Value="479"/>
    148146        <CursorPos X="3" Y="494"/>
    149         <UsageCount Value="10"/>
     147        <UsageCount Value="9"/>
    150148      </Unit11>
    151149      <Unit12>
     
    154152        <TopLine Value="1046"/>
    155153        <CursorPos X="34" Y="1053"/>
    156         <UsageCount Value="16"/>
     154        <UsageCount Value="15"/>
    157155      </Unit12>
    158156      <Unit13>
     
    161159        <TopLine Value="317"/>
    162160        <CursorPos X="1" Y="341"/>
    163         <UsageCount Value="9"/>
     161        <UsageCount Value="8"/>
    164162      </Unit13>
    165163      <Unit14>
     
    168166        <TopLine Value="45"/>
    169167        <CursorPos X="1" Y="62"/>
    170         <UsageCount Value="9"/>
     168        <UsageCount Value="8"/>
    171169      </Unit14>
    172170      <Unit15>
     
    175173        <TopLine Value="1670"/>
    176174        <CursorPos X="1" Y="1685"/>
    177         <UsageCount Value="10"/>
     175        <UsageCount Value="9"/>
    178176      </Unit15>
    179177      <Unit16>
     
    183181        <TopLine Value="290"/>
    184182        <CursorPos X="36" Y="306"/>
    185         <UsageCount Value="19"/>
     183        <UsageCount Value="18"/>
    186184      </Unit16>
    187185      <Unit17>
     
    190188        <TopLine Value="67"/>
    191189        <CursorPos X="10" Y="91"/>
    192         <UsageCount Value="7"/>
     190        <UsageCount Value="6"/>
    193191      </Unit17>
    194192      <Unit18>
     
    197195        <TopLine Value="1823"/>
    198196        <CursorPos X="3" Y="1838"/>
    199         <UsageCount Value="11"/>
     197        <UsageCount Value="10"/>
    200198      </Unit18>
    201199      <Unit19>
     
    204202        <TopLine Value="1348"/>
    205203        <CursorPos X="1" Y="1363"/>
    206         <UsageCount Value="9"/>
     204        <UsageCount Value="8"/>
    207205      </Unit19>
    208206      <Unit20>
     
    211209        <TopLine Value="32"/>
    212210        <CursorPos X="48" Y="50"/>
    213         <UsageCount Value="8"/>
     211        <UsageCount Value="7"/>
    214212      </Unit20>
    215213      <Unit21>
     
    218216        <TopLine Value="8"/>
    219217        <CursorPos X="11" Y="25"/>
    220         <UsageCount Value="10"/>
     218        <UsageCount Value="9"/>
    221219      </Unit21>
    222220      <Unit22>
     
    226224        <TopLine Value="1"/>
    227225        <CursorPos X="25" Y="9"/>
    228         <UsageCount Value="11"/>
     226        <UsageCount Value="10"/>
    229227      </Unit22>
    230228      <Unit23>
     
    233231        <TopLine Value="38"/>
    234232        <CursorPos X="29" Y="50"/>
    235         <UsageCount Value="15"/>
     233        <UsageCount Value="14"/>
    236234      </Unit23>
    237235      <Unit24>
     
    240238        <TopLine Value="106"/>
    241239        <CursorPos X="10" Y="119"/>
    242         <UsageCount Value="18"/>
     240        <UsageCount Value="17"/>
    243241      </Unit24>
    244242      <Unit25>
     
    247245        <TopLine Value="254"/>
    248246        <CursorPos X="12" Y="258"/>
    249         <UsageCount Value="11"/>
     247        <UsageCount Value="10"/>
    250248      </Unit25>
    251249      <Unit26>
     
    255253        <TopLine Value="581"/>
    256254        <CursorPos X="11" Y="585"/>
    257         <UsageCount Value="11"/>
     255        <UsageCount Value="10"/>
    258256      </Unit26>
    259257      <Unit27>
    260258        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/win/wininc/redef.inc"/>
    261         <WindowIndex Value="0"/>
    262         <TopLine Value="525"/>
    263         <CursorPos X="11" Y="538"/>
    264         <UsageCount Value="11"/>
     259        <EditorIndex Value="7"/>
     260        <WindowIndex Value="0"/>
     261        <TopLine Value="739"/>
     262        <CursorPos X="27" Y="752"/>
     263        <UsageCount Value="17"/>
     264        <Loaded Value="True"/>
    265265      </Unit27>
    266266      <Unit28>
    267267        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/packages/fcl-base/src/syncobjs.pp"/>
    268268        <UnitName Value="syncobjs"/>
    269         <WindowIndex Value="0"/>
    270         <TopLine Value="57"/>
    271         <CursorPos X="16" Y="70"/>
    272         <UsageCount Value="12"/>
     269        <EditorIndex Value="2"/>
     270        <WindowIndex Value="0"/>
     271        <TopLine Value="104"/>
     272        <CursorPos X="28" Y="106"/>
     273        <UsageCount Value="14"/>
     274        <Loaded Value="True"/>
    273275      </Unit28>
    274276      <Unit29>
    275277        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/inc/threadh.inc"/>
    276         <WindowIndex Value="0"/>
    277         <TopLine Value="18"/>
    278         <CursorPos X="50" Y="31"/>
    279         <UsageCount Value="12"/>
     278        <EditorIndex Value="3"/>
     279        <WindowIndex Value="0"/>
     280        <TopLine Value="138"/>
     281        <CursorPos X="11" Y="151"/>
     282        <UsageCount Value="14"/>
     283        <Loaded Value="True"/>
    280284      </Unit29>
    281285      <Unit30>
    282286        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/inc/thread.inc"/>
    283         <WindowIndex Value="0"/>
    284         <TopLine Value="109"/>
    285         <CursorPos X="3" Y="112"/>
    286         <UsageCount Value="12"/>
     287        <EditorIndex Value="4"/>
     288        <WindowIndex Value="0"/>
     289        <TopLine Value="199"/>
     290        <CursorPos X="3" Y="202"/>
     291        <UsageCount Value="14"/>
     292        <Loaded Value="True"/>
    287293      </Unit30>
    288294      <Unit31>
    289295        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/win/sysosh.inc"/>
    290         <WindowIndex Value="0"/>
    291         <TopLine Value="12"/>
    292         <CursorPos X="3" Y="25"/>
    293         <UsageCount Value="12"/>
     296        <EditorIndex Value="12"/>
     297        <WindowIndex Value="0"/>
     298        <TopLine Value="8"/>
     299        <CursorPos X="3" Y="33"/>
     300        <UsageCount Value="14"/>
     301        <Loaded Value="True"/>
    294302      </Unit31>
    295303      <Unit32>
    296304        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/objpas/classes/classesh.inc"/>
    297         <EditorIndex Value="8"/>
    298         <WindowIndex Value="0"/>
    299         <TopLine Value="1467"/>
    300         <CursorPos X="5" Y="1488"/>
    301         <UsageCount Value="18"/>
     305        <EditorIndex Value="10"/>
     306        <WindowIndex Value="0"/>
     307        <TopLine Value="302"/>
     308        <CursorPos X="19" Y="319"/>
     309        <UsageCount Value="20"/>
    302310        <Loaded Value="True"/>
    303311      </Unit32>
    304312      <Unit33>
    305313        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/win/tthread.inc"/>
    306         <EditorIndex Value="9"/>
    307314        <WindowIndex Value="0"/>
    308315        <TopLine Value="52"/>
    309316        <CursorPos X="25" Y="65"/>
    310         <UsageCount Value="15"/>
    311         <Loaded Value="True"/>
     317        <UsageCount Value="14"/>
    312318      </Unit33>
    313319      <Unit34>
     
    316322        <TopLine Value="130"/>
    317323        <CursorPos X="10" Y="143"/>
    318         <UsageCount Value="12"/>
     324        <UsageCount Value="11"/>
    319325      </Unit34>
    320326      <Unit35>
     
    323329        <TopLine Value="1923"/>
    324330        <CursorPos X="6" Y="1936"/>
    325         <UsageCount Value="12"/>
     331        <UsageCount Value="11"/>
    326332      </Unit35>
    327333      <Unit36>
    328334        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/objpas/classes/classes.inc"/>
    329         <EditorIndex Value="10"/>
    330335        <WindowIndex Value="0"/>
    331336        <TopLine Value="124"/>
    332337        <CursorPos X="3" Y="126"/>
    333         <UsageCount Value="18"/>
    334         <Loaded Value="True"/>
     338        <UsageCount Value="17"/>
    335339      </Unit36>
    336340      <Unit37>
     
    339343        <TopLine Value="181"/>
    340344        <CursorPos X="21" Y="194"/>
    341         <UsageCount Value="12"/>
     345        <UsageCount Value="11"/>
    342346      </Unit37>
    343347      <Unit38>
    344348        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/objpas/sysutils/osutilsh.inc"/>
    345         <EditorIndex Value="5"/>
    346349        <WindowIndex Value="0"/>
    347350        <TopLine Value="14"/>
    348351        <CursorPos X="17" Y="27"/>
    349         <UsageCount Value="13"/>
    350         <Loaded Value="True"/>
     352        <UsageCount Value="12"/>
    351353      </Unit38>
    352354      <Unit39>
     
    355357        <TopLine Value="2275"/>
    356358        <CursorPos X="39" Y="2285"/>
    357         <UsageCount Value="11"/>
     359        <UsageCount Value="10"/>
    358360      </Unit39>
    359361      <Unit40>
    360362        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/inc/systemh.inc"/>
    361         <EditorIndex Value="3"/>
    362363        <WindowIndex Value="0"/>
    363364        <TopLine Value="480"/>
    364365        <CursorPos X="3" Y="493"/>
    365         <UsageCount Value="10"/>
    366         <Loaded Value="True"/>
     366        <UsageCount Value="9"/>
    367367      </Unit40>
    368368      <Unit41>
     
    371371        <TopLine Value="197"/>
    372372        <CursorPos X="30" Y="208"/>
    373         <UsageCount Value="9"/>
     373        <UsageCount Value="8"/>
    374374      </Unit41>
    375375      <Unit42>
     
    378378        <TopLine Value="737"/>
    379379        <CursorPos X="21" Y="747"/>
    380         <UsageCount Value="9"/>
     380        <UsageCount Value="8"/>
    381381      </Unit42>
    382382      <Unit43>
     
    385385        <TopLine Value="96"/>
    386386        <CursorPos X="1" Y="1"/>
    387         <UsageCount Value="9"/>
     387        <UsageCount Value="8"/>
    388388      </Unit43>
    389389      <Unit44>
     
    392392        <TopLine Value="221"/>
    393393        <CursorPos X="1" Y="235"/>
    394         <UsageCount Value="12"/>
     394        <UsageCount Value="11"/>
    395395      </Unit44>
    396396      <Unit45>
    397397        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/lcl/interfaces/win32/win32object.inc"/>
     398        <EditorIndex Value="1"/>
    398399        <WindowIndex Value="0"/>
    399400        <TopLine Value="387"/>
    400401        <CursorPos X="1" Y="400"/>
    401         <UsageCount Value="12"/>
     402        <UsageCount Value="11"/>
     403        <Loaded Value="True"/>
    402404      </Unit45>
    403405      <Unit46>
     
    406408        <TopLine Value="6081"/>
    407409        <CursorPos X="6" Y="6094"/>
    408         <UsageCount Value="12"/>
     410        <UsageCount Value="11"/>
    409411      </Unit46>
    410412      <Unit47>
     
    413415        <TopLine Value="160"/>
    414416        <CursorPos X="12" Y="163"/>
    415         <UsageCount Value="9"/>
     417        <UsageCount Value="8"/>
    416418      </Unit47>
    417419      <Unit48>
    418420        <Filename Value="../UPlatform.pas"/>
    419421        <UnitName Value="UPlatform"/>
    420         <EditorIndex Value="12"/>
    421         <WindowIndex Value="0"/>
    422         <TopLine Value="19"/>
    423         <CursorPos X="1" Y="41"/>
    424         <UsageCount Value="17"/>
     422        <EditorIndex Value="6"/>
     423        <WindowIndex Value="0"/>
     424        <TopLine Value="23"/>
     425        <CursorPos X="31" Y="38"/>
     426        <UsageCount Value="23"/>
    425427        <Loaded Value="True"/>
    426428      </Unit48>
     
    430432        <TopLine Value="9153"/>
    431433        <CursorPos X="8" Y="9166"/>
    432         <UsageCount Value="9"/>
     434        <UsageCount Value="8"/>
    433435      </Unit49>
    434436      <Unit50>
     
    438440        <TopLine Value="1"/>
    439441        <CursorPos X="1" Y="1"/>
    440         <UsageCount Value="9"/>
     442        <UsageCount Value="8"/>
    441443      </Unit50>
    442444      <Unit51>
     
    445447        <TopLine Value="2380"/>
    446448        <CursorPos X="30" Y="2390"/>
    447         <UsageCount Value="9"/>
     449        <UsageCount Value="8"/>
    448450      </Unit51>
    449451      <Unit52>
     
    452454        <TopLine Value="150"/>
    453455        <CursorPos X="55" Y="162"/>
    454         <UsageCount Value="9"/>
     456        <UsageCount Value="8"/>
    455457      </Unit52>
    456458      <Unit53>
     
    459461        <TopLine Value="5227"/>
    460462        <CursorPos X="1" Y="5242"/>
    461         <UsageCount Value="9"/>
     463        <UsageCount Value="8"/>
    462464      </Unit53>
    463465      <Unit54>
     
    467469        <TopLine Value="102"/>
    468470        <CursorPos X="1" Y="121"/>
    469         <UsageCount Value="9"/>
     471        <UsageCount Value="8"/>
    470472      </Unit54>
    471473      <Unit55>
     
    474476        <TopLine Value="3515"/>
    475477        <CursorPos X="1" Y="3531"/>
    476         <UsageCount Value="9"/>
     478        <UsageCount Value="8"/>
    477479      </Unit55>
    478480      <Unit56>
     
    481483        <TopLine Value="1159"/>
    482484        <CursorPos X="1" Y="1174"/>
    483         <UsageCount Value="9"/>
     485        <UsageCount Value="8"/>
    484486      </Unit56>
    485487      <Unit57>
     
    487489        <EditorIndex Value="11"/>
    488490        <WindowIndex Value="0"/>
    489         <TopLine Value="590"/>
    490         <CursorPos X="14" Y="594"/>
    491         <UsageCount Value="13"/>
     491        <TopLine Value="909"/>
     492        <CursorPos X="26" Y="917"/>
     493        <UsageCount Value="15"/>
    492494        <Loaded Value="True"/>
    493495      </Unit57>
    494496      <Unit58>
    495497        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/lcl/interfaces/win32/win32callback.inc"/>
    496         <EditorIndex Value="7"/>
    497498        <WindowIndex Value="0"/>
    498499        <TopLine Value="1086"/>
    499500        <CursorPos X="1" Y="1099"/>
    500         <UsageCount Value="13"/>
    501         <Loaded Value="True"/>
     501        <UsageCount Value="12"/>
    502502      </Unit58>
    503503      <Unit59>
     
    507507        <TopLine Value="357"/>
    508508        <CursorPos X="3" Y="370"/>
    509         <UsageCount Value="11"/>
     509        <UsageCount Value="10"/>
    510510      </Unit59>
    511511      <Unit60>
    512512        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/lcl/customtimer.pas"/>
    513513        <UnitName Value="CustomTimer"/>
    514         <EditorIndex Value="6"/>
    515514        <WindowIndex Value="0"/>
    516515        <TopLine Value="40"/>
    517516        <CursorPos X="17" Y="53"/>
    518         <UsageCount Value="12"/>
    519         <Loaded Value="True"/>
     517        <UsageCount Value="11"/>
    520518      </Unit60>
    521519      <Unit61>
    522520        <Filename Value="../ReadMe.txt"/>
    523         <EditorIndex Value="13"/>
    524521        <WindowIndex Value="0"/>
    525522        <TopLine Value="1"/>
    526523        <CursorPos X="17" Y="14"/>
    527         <UsageCount Value="10"/>
    528         <Loaded Value="True"/>
     524        <UsageCount Value="9"/>
    529525        <DefaultSyntaxHighlighter Value="None"/>
    530526      </Unit61>
     
    532528        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/lcl/forms.pp"/>
    533529        <UnitName Value="Forms"/>
    534         <EditorIndex Value="1"/>
    535530        <WindowIndex Value="0"/>
    536531        <TopLine Value="57"/>
    537532        <CursorPos X="3" Y="70"/>
    538         <UsageCount Value="10"/>
    539         <Loaded Value="True"/>
     533        <UsageCount Value="9"/>
    540534      </Unit62>
     535      <Unit63>
     536        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/fpc/2.4.3/source/rtl/objpas/sysutils/sysutilh.inc"/>
     537        <EditorIndex Value="8"/>
     538        <WindowIndex Value="0"/>
     539        <TopLine Value="1"/>
     540        <CursorPos X="55" Y="4"/>
     541        <UsageCount Value="16"/>
     542        <Loaded Value="True"/>
     543      </Unit63>
     544      <Unit64>
     545        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/lcl/controls.pp"/>
     546        <UnitName Value="Controls"/>
     547        <EditorIndex Value="5"/>
     548        <WindowIndex Value="0"/>
     549        <TopLine Value="2660"/>
     550        <CursorPos X="1" Y="2673"/>
     551        <UsageCount Value="15"/>
     552        <Loaded Value="True"/>
     553      </Unit64>
    541554    </Units>
    542     <JumpHistory Count="30" HistoryIndex="29">
     555    <JumpHistory Count="30" HistoryIndex="28">
    543556      <Position1>
    544557        <Filename Value="../UMicroThreading.pas"/>
    545         <Caret Line="718" Column="1" TopLine="701"/>
     558        <Caret Line="773" Column="1" TopLine="760"/>
    546559      </Position1>
    547560      <Position2>
    548561        <Filename Value="../UMicroThreading.pas"/>
    549         <Caret Line="719" Column="1" TopLine="701"/>
     562        <Caret Line="774" Column="1" TopLine="760"/>
    550563      </Position2>
    551564      <Position3>
    552565        <Filename Value="../UMicroThreading.pas"/>
    553         <Caret Line="720" Column="1" TopLine="701"/>
     566        <Caret Line="772" Column="1" TopLine="760"/>
    554567      </Position3>
    555568      <Position4>
    556569        <Filename Value="../UMicroThreading.pas"/>
    557         <Caret Line="718" Column="1" TopLine="701"/>
     570        <Caret Line="773" Column="1" TopLine="760"/>
    558571      </Position4>
    559572      <Position5>
    560573        <Filename Value="../UMicroThreading.pas"/>
    561         <Caret Line="719" Column="1" TopLine="701"/>
     574        <Caret Line="774" Column="1" TopLine="760"/>
    562575      </Position5>
    563576      <Position6>
    564577        <Filename Value="../UMicroThreading.pas"/>
    565         <Caret Line="720" Column="1" TopLine="701"/>
     578        <Caret Line="772" Column="1" TopLine="760"/>
    566579      </Position6>
    567580      <Position7>
    568581        <Filename Value="../UMicroThreading.pas"/>
    569         <Caret Line="718" Column="1" TopLine="701"/>
     582        <Caret Line="773" Column="1" TopLine="760"/>
    570583      </Position7>
    571584      <Position8>
    572585        <Filename Value="../UMicroThreading.pas"/>
    573         <Caret Line="719" Column="1" TopLine="701"/>
     586        <Caret Line="774" Column="1" TopLine="760"/>
    574587      </Position8>
    575588      <Position9>
    576589        <Filename Value="../UMicroThreading.pas"/>
    577         <Caret Line="720" Column="1" TopLine="701"/>
     590        <Caret Line="772" Column="1" TopLine="760"/>
    578591      </Position9>
    579592      <Position10>
    580593        <Filename Value="../UMicroThreading.pas"/>
    581         <Caret Line="670" Column="3" TopLine="664"/>
     594        <Caret Line="773" Column="1" TopLine="760"/>
    582595      </Position10>
    583596      <Position11>
    584597        <Filename Value="../UMicroThreading.pas"/>
    585         <Caret Line="706" Column="1" TopLine="693"/>
     598        <Caret Line="774" Column="1" TopLine="760"/>
    586599      </Position11>
    587600      <Position12>
    588601        <Filename Value="../UMicroThreading.pas"/>
    589         <Caret Line="771" Column="3" TopLine="767"/>
     602        <Caret Line="772" Column="1" TopLine="760"/>
    590603      </Position12>
    591604      <Position13>
    592605        <Filename Value="../UMicroThreading.pas"/>
    593         <Caret Line="719" Column="12" TopLine="699"/>
     606        <Caret Line="773" Column="1" TopLine="760"/>
    594607      </Position13>
    595608      <Position14>
    596609        <Filename Value="../UMicroThreading.pas"/>
    597         <Caret Line="718" Column="1" TopLine="699"/>
     610        <Caret Line="774" Column="1" TopLine="760"/>
    598611      </Position14>
    599612      <Position15>
    600613        <Filename Value="../UMicroThreading.pas"/>
    601         <Caret Line="719" Column="1" TopLine="699"/>
     614        <Caret Line="772" Column="1" TopLine="760"/>
    602615      </Position15>
    603616      <Position16>
    604617        <Filename Value="../UMicroThreading.pas"/>
    605         <Caret Line="720" Column="1" TopLine="699"/>
     618        <Caret Line="773" Column="1" TopLine="760"/>
    606619      </Position16>
    607620      <Position17>
    608621        <Filename Value="../UMicroThreading.pas"/>
    609         <Caret Line="718" Column="1" TopLine="699"/>
     622        <Caret Line="774" Column="1" TopLine="760"/>
    610623      </Position17>
    611624      <Position18>
    612625        <Filename Value="../UMicroThreading.pas"/>
    613         <Caret Line="719" Column="1" TopLine="699"/>
     626        <Caret Line="772" Column="1" TopLine="760"/>
    614627      </Position18>
    615628      <Position19>
    616629        <Filename Value="../UMicroThreading.pas"/>
    617         <Caret Line="720" Column="1" TopLine="699"/>
     630        <Caret Line="773" Column="1" TopLine="760"/>
    618631      </Position19>
    619632      <Position20>
    620633        <Filename Value="../UMicroThreading.pas"/>
    621         <Caret Line="718" Column="1" TopLine="699"/>
     634        <Caret Line="774" Column="1" TopLine="760"/>
    622635      </Position20>
    623636      <Position21>
    624637        <Filename Value="../UMicroThreading.pas"/>
    625         <Caret Line="719" Column="1" TopLine="699"/>
     638        <Caret Line="772" Column="1" TopLine="760"/>
    626639      </Position21>
    627640      <Position22>
    628641        <Filename Value="../UMicroThreading.pas"/>
    629         <Caret Line="718" Column="1" TopLine="699"/>
     642        <Caret Line="773" Column="1" TopLine="760"/>
    630643      </Position22>
    631644      <Position23>
    632645        <Filename Value="../UMicroThreading.pas"/>
    633         <Caret Line="719" Column="1" TopLine="699"/>
     646        <Caret Line="774" Column="1" TopLine="760"/>
    634647      </Position23>
    635648      <Position24>
    636649        <Filename Value="../UMicroThreading.pas"/>
    637         <Caret Line="720" Column="1" TopLine="699"/>
     650        <Caret Line="810" Column="35" TopLine="796"/>
    638651      </Position24>
    639652      <Position25>
    640         <Filename Value="../UMicroThreading.pas"/>
    641         <Caret Line="718" Column="1" TopLine="699"/>
     653        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/lcl/interfaces/win32/win32object.inc"/>
     654        <Caret Line="400" Column="1" TopLine="387"/>
    642655      </Position25>
    643656      <Position26>
    644657        <Filename Value="../UMicroThreading.pas"/>
    645         <Caret Line="719" Column="1" TopLine="699"/>
     658        <Caret Line="524" Column="9" TopLine="513"/>
    646659      </Position26>
    647660      <Position27>
    648661        <Filename Value="../UMicroThreading.pas"/>
    649         <Caret Line="4" Column="72" TopLine="1"/>
     662        <Caret Line="523" Column="1" TopLine="513"/>
    650663      </Position27>
    651664      <Position28>
    652665        <Filename Value="../UMicroThreading.pas"/>
    653         <Caret Line="166" Column="26" TopLine="144"/>
     666        <Caret Line="524" Column="1" TopLine="513"/>
    654667      </Position28>
    655668      <Position29>
    656669        <Filename Value="../UMicroThreading.pas"/>
    657         <Caret Line="670" Column="24" TopLine="654"/>
     670        <Caret Line="526" Column="1" TopLine="513"/>
    658671      </Position29>
    659672      <Position30>
    660         <Filename Value="../UMicroThreading.pas"/>
    661         <Caret Line="783" Column="25" TopLine="766"/>
     673        <Filename Value="../../../../Programy/Lazarus/0.9.31_2.4.3/lcl/interfaces/win32/win32object.inc"/>
     674        <Caret Line="400" Column="1" TopLine="387"/>
    662675      </Position30>
    663676    </JumpHistory>
     
    679692        <StackChecks Value="True"/>
    680693      </Checks>
     694      <VerifyObjMethodCallValidity Value="True"/>
    681695    </CodeGeneration>
    682696    <Linking>
     
    698712  </CompilerOptions>
    699713  <Debugging>
     714    <BreakPoints Count="1">
     715      <Item1>
     716        <Source Value="../UMicroThreading.pas"/>
     717        <Line Value="523"/>
     718      </Item1>
     719    </BreakPoints>
    700720    <Watches Count="2">
    701721      <Item1>
  • MicroThreading/Demo/UMainForm.lfm

    r155 r156  
    33  Height = 533
    44  Top = 98
    5   Width = 775
     5  Width = 816
    66  Caption = 'MicroThreading demo'
    77  ClientHeight = 533
    8   ClientWidth = 775
     8  ClientWidth = 816
    99  OnCreate = FormCreate
    1010  OnDestroy = FormDestroy
     
    1515    Height = 519
    1616    Top = 8
    17     Width = 761
     17    Width = 802
    1818    ActivePage = TabSheet2
    1919    Anchors = [akTop, akLeft, akRight, akBottom]
    20     TabIndex = 1
     20    TabIndex = 0
    2121    TabOrder = 0
    22     object TabSheet1: TTabSheet
    23       Caption = 'Job control'
    24       ClientHeight = 493
    25       ClientWidth = 753
    26       object ButtonAddWorkers: TButton
    27         Left = 10
    28         Height = 25
    29         Top = 7
    30         Width = 104
    31         Caption = 'Add workers'
    32         OnClick = ButtonAddWorkersClick
    33         TabOrder = 0
    34       end
    35       object ButtonClearMicroThreads: TButton
    36         Left = 10
    37         Height = 25
    38         Top = 74
    39         Width = 104
    40         Caption = 'Clear jobs'
    41         OnClick = ButtonClearMicroThreadsClick
    42         TabOrder = 1
    43       end
    44       object Label4: TLabel
    45         Left = 124
    46         Height = 14
    47         Top = 14
    48         Width = 34
    49         Caption = 'Count:'
    50         ParentColor = False
    51       end
    52       object SpinEdit1: TSpinEdit
    53         Left = 204
    54         Height = 21
    55         Top = 11
    56         Width = 74
    57         MaxValue = 100000
    58         MinValue = 1
    59         TabStop = False
    60         TabOrder = 2
    61         Value = 2
    62       end
    63       object Memo1: TMemo
    64         Left = 316
    65         Height = 244
    66         Top = 14
    67         Width = 294
    68         Anchors = [akTop, akLeft, akBottom]
    69         ScrollBars = ssAutoBoth
    70         TabOrder = 3
    71       end
    72       object Button1: TButton
    73         Left = 12
    74         Height = 25
    75         Top = 138
    76         Width = 75
    77         Caption = 'Clear memo'
    78         OnClick = Button1Click
    79         TabOrder = 4
    80       end
    81       object Label12: TLabel
    82         Left = 123
    83         Height = 14
    84         Top = 38
    85         Width = 52
    86         Caption = 'Iterations:'
    87         ParentColor = False
    88       end
    89       object SpinEdit3: TSpinEdit
    90         Left = 204
    91         Height = 21
    92         Top = 36
    93         Width = 74
    94         MaxValue = 1000000000
    95         OnChange = SpinEdit3Change
    96         TabOrder = 5
    97         Value = 1000000
    98       end
    99     end
    10022    object TabSheet2: TTabSheet
    10123      Caption = 'Scheduler state'
    10224      ClientHeight = 493
    103       ClientWidth = 753
     25      ClientWidth = 794
    10426      object ListView1: TListView
    10527        Left = 222
    10628        Height = 460
    10729        Top = 24
    108         Width = 477
     30        Width = 567
    10931        Anchors = [akTop, akLeft, akRight, akBottom]
    11032        Columns = <       
     
    11436          end       
    11537          item
    116             Caption = 'Name'
    117           end       
    118           item
    11938            Caption = 'Usage'
    12039          end       
     
    13453          end       
    13554          item
     55            Caption = 'Execution count'
     56          end       
     57          item
    13658            Caption = 'Completion'
    13759          end       
     
    13961            Caption = 'Used stack'
    14062            Width = 178
     63          end       
     64          item
     65            Caption = 'Name'
    14166          end>
    14267        OwnerData = True
     
    258183      end
    259184    end
     185    object TabSheet1: TTabSheet
     186      Caption = 'Job control'
     187      ClientHeight = 493
     188      ClientWidth = 794
     189      object ButtonAddWorkers: TButton
     190        Left = 10
     191        Height = 25
     192        Top = 7
     193        Width = 104
     194        Caption = 'Add workers'
     195        OnClick = ButtonAddWorkersClick
     196        TabOrder = 0
     197      end
     198      object ButtonClearMicroThreads: TButton
     199        Left = 10
     200        Height = 25
     201        Top = 74
     202        Width = 104
     203        Caption = 'Clear jobs'
     204        OnClick = ButtonClearMicroThreadsClick
     205        TabOrder = 1
     206      end
     207      object Label4: TLabel
     208        Left = 124
     209        Height = 14
     210        Top = 14
     211        Width = 34
     212        Caption = 'Count:'
     213        ParentColor = False
     214      end
     215      object SpinEdit1: TSpinEdit
     216        Left = 204
     217        Height = 21
     218        Top = 11
     219        Width = 74
     220        MaxValue = 100000
     221        MinValue = 1
     222        TabStop = False
     223        TabOrder = 2
     224        Value = 2
     225      end
     226      object Memo1: TMemo
     227        Left = 316
     228        Height = 244
     229        Top = 14
     230        Width = 294
     231        Anchors = [akTop, akLeft, akBottom]
     232        ScrollBars = ssAutoBoth
     233        TabOrder = 3
     234      end
     235      object Button1: TButton
     236        Left = 12
     237        Height = 25
     238        Top = 138
     239        Width = 75
     240        Caption = 'Clear memo'
     241        OnClick = Button1Click
     242        TabOrder = 4
     243      end
     244      object Label12: TLabel
     245        Left = 123
     246        Height = 14
     247        Top = 38
     248        Width = 52
     249        Caption = 'Iterations:'
     250        ParentColor = False
     251      end
     252      object SpinEdit3: TSpinEdit
     253        Left = 204
     254        Height = 21
     255        Top = 36
     256        Width = 74
     257        MaxValue = 1000000000
     258        OnChange = SpinEdit3Change
     259        TabOrder = 5
     260        Value = 10000000
     261      end
     262    end
    260263    object TabSheet3: TTabSheet
    261264      Caption = 'Testing'
     
    313316    top = 115
    314317  end
    315   object TimerSchedulerStart: TTimer
    316     Interval = 10
    317     OnTimer = TimerSchedulerStartTimer
    318     left = 429
    319     top = 163
    320   end
    321318end
  • MicroThreading/Demo/UMainForm.pas

    r155 r156  
    4646    TabSheet3: TTabSheet;
    4747    TimerRedraw: TTimer;
    48     TimerSchedulerStart: TTimer;
    4948    procedure Button1Click(Sender: TObject);
    5049    procedure ButtonSchedulerStartStopClick(Sender: TObject);
     
    6261    procedure SpinEdit3Change(Sender: TObject);
    6362    procedure TimerRedrawTimer(Sender: TObject);
    64     procedure TimerSchedulerStartTimer(Sender: TObject);
    6563  private
    6664    procedure Worker(MicroThread: TMicroThread);
     
    215213begin
    216214  Iterations := SpinEdit3.Value;
     215  SpinEdit2.Value := 20;
     216  ButtonAddWorkers.Click;
     217  ButtonSchedulerStartStop.Click;
    217218end;
    218219
     
    224225    with TMicroThread(MainScheduler.MicroThreads[Item.Index]) do begin
    225226      Item.Caption := IntToStr(Id);
    226       Item.SubItems.Add(Name);
    227227      Item.SubItems.Add('');
    228228      Item.SubItems.Add(IntToStr(Priority));
     
    230230      Item.SubItems.Add(MicroThreadBlockStateText[BlockState]);
    231231      Item.SubItems.Add(FloatToStr(ExecutionTime));
     232      Item.SubItems.Add(IntToStr(ExecutionCount));
    232233      Item.SubItems.Add(IntToStr(Trunc(Completion * 100)) + '%');
    233234      Item.SubItems.Add(IntToStr(StackUsed));
     235      Item.SubItems.Add(Name);
    234236    end;
    235237  finally
     
    260262end;
    261263
    262 procedure TMainForm.TimerSchedulerStartTimer(Sender: TObject);
    263 begin
    264   TimerSchedulerStart.Enabled := False;
    265   ButtonAddWorkers.Click;
    266   ButtonSchedulerStartStop.Click;
    267 end;
    268 
    269264procedure TMainForm.WorkerSubRoutine;
    270265begin
    271   MTSleep(1 * OneMillisecond);
     266  //MTSleep(1 * OneMillisecond);
    272267end;
    273268
     
    282277      Q := 0;
    283278      while Q < 100 do Inc(Q);
    284       Synchronize(WorkerDoWrite);
     279      //Synchronize(WorkerDoWrite);
    285280      //Memo1.Lines.Add(IntToStr(Id) + ': ' + IntToStr(I) + ' ' +
    286281      //  FloatToStr(ExecutionTime));
    287282      Completion := I / Iterations;
    288       //MTSleep(1 * Id * OneMillisecond);
     283      //MTSleep(1000 * OneMillisecond);
    289284      Yield;
    290       WorkerSubRoutine;
     285      //WorkerSubRoutine;
    291286    end;
    292287  end;
     
    295290procedure TMainForm.WorkerDoWrite;
    296291begin
    297   Memo1.Lines.Add('.');
     292  //Memo1.Lines.Add('.');
    298293end;
    299294
  • MicroThreading/UMicroThreading.pas

    r155 r156  
    2828  TMicroThreadManager = class;
    2929
    30   TMicroThreadState = (tsWaiting, tsRunning, tsBlocked, tsSuspended);
     30  TMicroThreadState = (tsNone, tsWaiting, tsRunning, tsBlocked, tsSuspended);
    3131  TMicroThreadBlockState = (tbsNone, tbsSleeping, tbsWaitFor, tbsTerminating,
    3232    tbsTerminated);
     
    5858    FExecutionEndTime: TDateTime;
    5959    FExecutionTime: TDateTime;
     60    FExecutionCount: Integer;
    6061    FStack: Pointer;
    6162    FStackPointer: Pointer;
     
    7374    function GetStackUsed: Integer;
    7475    function GetTerminated: Boolean;
     76    procedure SetManager(const AValue: TMicroThreadManager);
    7577    procedure SetScheduler(const AValue: TMicroThreadScheduler);
     78    procedure CheckStack;
    7679  public
    7780    Name: string;
     
    97100    property BlockState: TMicroThreadBlockState read FBlockState;
    98101    property ExecutionTime: TDateTime read FExecutionTime;
     102    property ExecutionCount: Integer read FExecutionCount;
    99103    property FreeOnTerminate: Boolean read FFreeOnTerminate
    100104      write FFreeOnTerminate;
     
    102106    property Scheduler: TMicroThreadScheduler read FScheduler
    103107      write SetScheduler;
    104     property Manager: TMicroThreadManager read FManager;
     108    property Manager: TMicroThreadManager read FManager write SetManager;
    105109    property StackUsed: Integer read GetStackUsed;
    106110  end;
     
    140144    FScheduler: TMicroThreadScheduler;
    141145    FThread: TMicroThreadThread;
     146    FId: Integer;
     147    procedure SetCurrentMicroThread(const AValue: TMicroThread);
    142148    function Execute(Count: Integer): Integer;
     149    property CurrentMicroThread: TMicroThread read FCurrentMicroThread
     150      write SetCurrentMicroThread;
    143151  public
    144     Id: Integer;
    145152    procedure Yield;
    146153    procedure Synchronize(AMethod: TThreadMethod);
     
    148155    destructor Destroy; override;
    149156    property Scheduler: TMicroThreadScheduler read FScheduler;
    150     property CurrentMicroThread: TMicroThread read FCurrentMicroThread;
    151157  end;
    152158
     
    176182    procedure SetActive(const AValue: Boolean);
    177183    procedure SetThreadPoolSize(const AValue: Integer);
    178     function GetNextMicroThread: TMicroThread;
     184    procedure GetNextMicroThread(Manager: TMicroThreadManager);
    179185    procedure ReleaseMicroThread(MicroThread: TMicroThread);
    180186    procedure SetUseMainThread(const AValue: Boolean);
     
    206212
    207213const
    208   MicroThreadStateText: array[TMicroThreadState] of string = ('Waiting',
     214  MicroThreadStateText: array[TMicroThreadState] of string = ('None', 'Waiting',
    209215    'Running', 'Blocked', 'Suspended');
    210216  MicroThreadBlockStateText: array[TMicroThreadBlockState] of string = ('None',
     
    214220procedure MTSleep(Duration: TDateTime);
    215221function MTWaitForEvent(Event: TMicroThreadEvent; Duration: TDateTime): TWaitResult;
     222procedure Log(Text: string);
     223
     224const
     225  LogFileName: string = 'Log.txt';
    216226
    217227implementation
     
    284294end;
    285295
     296var
     297  LogLock: TCriticalSection;
     298
     299procedure Log(Text: string);
     300var
     301  LogFile: TextFile;
     302begin
     303  try
     304    LogLock.Acquire;
     305    AssignFile(LogFile, LogFileName);
     306    if FileExists(LogFileName) then Append(LogFile)
     307      else Rewrite(LogFile);
     308    WriteLn(LogFile, Text);
     309    CloseFile(LogFile);
     310  finally
     311    LogLock.Release;
     312  end;
     313end;
     314
    286315{ TMicroThreadMethod }
    287316
     
    323352
    324353{ TMicroThreadManager }
     354
     355procedure TMicroThreadManager.SetCurrentMicroThread(const AValue: TMicroThread
     356  );
     357begin
     358  if FCurrentMicroThread = AValue then Exit;
     359  if Assigned(FCurrentMicroThread) then
     360    FCurrentMicroThread.FManager := nil;
     361  FCurrentMicroThread := AValue;
     362  if Assigned(FCurrentMicroThread) then
     363    FCurrentMicroThread.FManager := Self;
     364end;
    325365
    326366function TMicroThreadManager.Execute(Count: Integer): Integer;
     
    345385      mov eax, [ecx].TMicroThreadManager.FCurrentMicroThread
    346386      mov edx, esp
     387      mov ebx, ebp
    347388      mov [eax].TMicroThread.FStackPointer, edx
    348       mov edx, ebp
    349       mov [eax].TMicroThread.FBasePointer, edx
    350 
    351       // Restore FScheduler stack
     389      mov [eax].TMicroThread.FBasePointer, ebx
     390
     391      // Restore manager stack
    352392      mov edx, [ecx].TMicroThreadManager.FStackPointer
     393      mov ebx, [ecx].TMicroThreadManager.FBasePointer
    353394      mov esp, edx
    354       mov edx, [ecx].TMicroThreadManager.FBasePointer
    355       mov ebp, edx
     395      mov ebp, ebx
    356396    end;
    357     FCurrentMicroThread.FManager := nil;
     397    FCurrentMicroThread.CheckStack;
     398    if FCurrentMicroThread = nil then
     399      raise Exception.Create('x');
    358400    FScheduler.ReleaseMicroThread(FCurrentMicroThread);
    359     FCurrentMicroThread := nil;
    360401  end;
    361402
    362403  if FExecutedCount < FExecuteCount then begin
    363     FCurrentMicroThread := FScheduler.GetNextMicroThread;
    364 
     404    FScheduler.GetNextMicroThread(Self);
    365405    if Assigned(FCurrentMicroThread) then begin
    366406      Inc(FExecutedCount);
    367407      FCurrentMicroThread.FExecutionStartTime := NowPrecise;
    368       FCurrentMicroThread.FManager := Self;
    369408      asm
    370         // Store FScheduler stack
     409        // Store manager stack
    371410        mov eax, Self
    372411        mov edx, esp
     412        mov ebx, ebp
    373413        mov [eax].TMicroThreadManager.FStackPointer, edx
    374         mov edx, ebp
    375         mov [eax].TMicroThreadManager.FBasePointer, edx
     414        mov [eax].TMicroThreadManager.FBasePointer, ebx
    376415      end;
    377416      if not FCurrentMicroThread.FExecuted then begin
     417        // First time micro thread execution
    378418        FCurrentMicroThread.FExecuted := True;
    379419        asm
     
    382422          mov eax, [ecx].TMicroThreadManager.FCurrentMicroThread
    383423          mov edx, [eax].TMicroThread.FStackPointer
     424          mov ebx, [eax].TMicroThread.FBasePointer
    384425          mov esp, edx
    385           mov edx, [eax].TMicroThread.FBasePointer
    386           mov ebp, edx
     426          mov ebp, ebx
    387427          // We want to call virtual method Execute
    388428          // but virtual methods can be called only statically
     
    390430          call TMicroThread.CallExecute
    391431
    392           // Restore FScheduler stack
     432          // Restore manager stack
    393433          // ecx register is set by CallExecute to running micro thread
    394434          mov eax, [ecx].TMicroThread.FManager
    395435          mov edx, [eax].TMicroThreadManager.FStackPointer
     436          mov ebx, [eax].TMicroThreadManager.FBasePointer
    396437          mov esp, edx
    397           mov edx, [eax].TMicroThreadManager.FBasePointer
    398           mov ebp, edx
     438          mov ebp, ebx
    399439        end;
    400 
     440        FCurrentMicroThread.CheckStack;
    401441        FCurrentMicroThread.FExecutionEndTime := NowPrecise;
    402442        FCurrentMicroThread.FExecutionTime := FCurrentMicroThread.FExecutionTime +
    403443         (FCurrentMicroThread.FExecutionEndTime - FCurrentMicroThread.FExecutionStartTime);
    404         FCurrentMicroThread.FState := tsBlocked;
     444        FCurrentMicroThread.FStatePending := tsBlocked;
    405445        FCurrentMicroThread.FBlockState := tbsTerminated;
    406446        if FCurrentMicroThread.FFreeOnTerminate then begin
     
    414454          end;
    415455        end else begin
    416           FCurrentMicroThread.FManager := nil;
    417456          FScheduler.ReleaseMicroThread(FCurrentMicroThread);
    418457        end;
    419458        //FCurrentMicroThread.FManager := nil;
    420459        //FScheduler.ReleaseMicroThread(FCurrentMicroThread);
    421         FCurrentMicroThread := nil;
     460        //FCurrentMicroThread := nil;
    422461      end else
    423       //if FCurrentMicroThread.State = tsWaiting then
    424462      begin
    425         // Execute selected thread
     463        // Regular selected microthread execution
     464        FCurrentMicroThread.CheckStack;
    426465        asm
    427466          // Restore microthread stack
     
    429468          mov eax, [ecx].TMicroThreadManager.FCurrentMicroThread
    430469          mov edx, [eax].TMicroThread.FStackPointer
     470          mov ebx, [eax].TMicroThread.FBasePointer
    431471          mov esp, edx
    432           mov edx, [eax].TMicroThread.FBasePointer
    433           mov ebp, edx
     472          mov ebp, ebx
    434473        end;
    435474      end;
     
    464503  try
    465504    repeat
    466       ExecutedCount := Manager.Execute(10);
     505      ExecutedCount := Manager.Execute(100000);
    467506      if ExecutedCount = 0 then Sleep(1);
    468507    until Terminated;
    469508  except
    470     on E: Exception do
     509    on E: Exception do ;
    471510      //ExceptionHandler(E);
    472511  end;
     
    485524  Terminate;
    486525  repeat
    487     Application.ProcessMessages;
    488526    Sleep(1);
    489527  until ExecuteTerminated;
     
    522560end;
    523561
     562procedure TMicroThread.SetManager(const AValue: TMicroThreadManager);
     563begin
     564  if FManager = AValue then Exit;
     565  if Assigned(FManager) then FManager.CurrentMicroThread := nil;
     566  FManager := AValue;
     567  if Assigned(FManager) then FManager.CurrentMicroThread := Self;
     568end;
     569
    524570procedure TMicroThread.SetScheduler(const AValue: TMicroThreadScheduler);
    525571begin
     
    527573end;
    528574
     575procedure TMicroThread.CheckStack;
     576begin
     577  if not ((FStackPointer > FStack) and (FStackPointer < (FStack + FStackSize)))
     578    then raise EStackOverflow.Create(Format('Microthread %d stack error', [FId]));
     579end;
     580
    529581procedure TMicroThread.Execute;
    530582begin
     
    534586procedure TMicroThread.Yield;
    535587begin
     588  if not Assigned(FManager) then
     589    raise Exception.Create('Manager reference lost');
     590  FStatePending := tsWaiting;
    536591  FManager.Yield;
    537592end;
     
    582637  FExecutionTime := 0;
    583638  FState := tsWaiting;
    584   FStatePending := tsWaiting;
     639  FStatePending := tsNone;
    585640  if CreateSuspended then begin
    586641    FState := tsSuspended;
    587     FStatePending := tsSuspended;
    588642  end;
    589643  FFreeOnTerminate := True;
     
    717771    Application.ProcessMessages;
    718772    Sleep(1);
    719   until FMainThreadTerminated and (ThreadPoolSize = 0);
     773  until FMainThreadTerminated and (ThreadPoolCount = 0);
    720774  FState := ssStopped;
    721775end;
     
    730784    FThreadPool.OwnsObjects := False;
    731785    ThreadIndex := FThreadPool.IndexOf(Sender);
    732     if ThreadIndex <> -1 then FThreadPool.Delete(ThreadIndex);
     786    if ThreadIndex = -1 then
     787      raise Exception.Create('Trying to free thread not found in thread pool');
     788    FThreadPool.Delete(ThreadIndex);
     789  finally
    733790    FThreadPool.OwnsObjects := True;
    734   finally
    735791    FThreadPoolLock.Release;
    736792  end;
     
    748804        NewThread := TMicroThreadThread.Create(True);
    749805        NewThread.Manager.FScheduler := Self;
    750         NewThread.Manager.Id := FThreadPool.Count + 1;
     806        NewThread.Manager.FId := FThreadPool.Count + 1;
    751807        NewThread.Manager.FThread := NewThread;
    752808        NewThread.OnTerminate := PoolThreadTerminated;
     809        NewThread.FreeOnTerminate := True;
    753810        ThreadPool.Add(NewThread);
    754811        NewThread.Resume;
     
    778835end;
    779836
    780 function TMicroThreadScheduler.GetNextMicroThread: TMicroThread;
     837procedure TMicroThreadScheduler.GetNextMicroThread(Manager: TMicroThreadManager);
    781838var
    782839  I: Integer;
    783840  CurrentTime: TDateTime;
    784 begin
    785   CurrentTime := NowPrecise;
    786   Result := nil;
     841  Selected: TMicroThread;
     842begin
    787843  try
    788844    FMicroThreadsLock.Acquire;
     845    CurrentTime := NowPrecise;
    789846    I := 0;
     847    Selected := nil;
    790848    Inc(FRoundRobinIndex);
    791849    if FRoundRobinIndex >= FMicroThreads.Count then
     
    793851    while (I < FMicroThreads.Count) do
    794852    with TMicroThread(FMicroThreads[FRoundRobinIndex]) do begin
    795       FState := FStatePending;
    796853      if (FState = tsWaiting) then Break
    797854      else
     
    815872      // Go to next thread
    816873      Inc(I);
    817       Inc(FRoundRobinIndex);
    818       if FRoundRobinIndex >= FMicroThreads.Count then
    819         FRoundRobinIndex := 0;
     874      FRoundRobinIndex := (FRoundRobinIndex + 1) mod FMicroThreads.Count;
    820875    end;
    821876    if I < FMicroThreads.Count then begin
    822       Result := TMicroThread(FMicroThreads[FRoundRobinIndex]);
    823       Result.FState := tsRunning;
    824       Result.FStatePending := tsWaiting;
     877      if Assigned(Manager.FCurrentMicroThread) then
     878        raise Exception.Create('Manager have already have running microthread');
     879      Selected := TMicroThread(FMicroThreads[FRoundRobinIndex]);
     880      Selected.FState := tsRunning;
     881      Inc(Selected.FExecutionCount);
    825882    end;
     883    Manager.CurrentMicroThread := Selected;
    826884  finally
    827885    FMicroThreadsLock.Release;
     
    831889procedure TMicroThreadScheduler.ReleaseMicroThread(MicroThread: TMicroThread);
    832890begin
     891  if not Assigned(MicroThread) then
     892    raise Exception.Create('Can''t realease nil thread.');
    833893  try
    834894    FMicroThreadsLock.Acquire;
    835     MicroThread.FState := MicroThread.FStatePending;
     895    if MicroThread.FStatePending <> tsNone then begin
     896      MicroThread.FState := MicroThread.FStatePending;
     897      MicroThread.FStatePending := tsNone;
     898    end;
     899    MicroThread.Manager := nil;
    836900  finally
    837901    FMicroThreadsLock.Release;
     
    893957initialization
    894958
     959DeleteFile(LogFileName);
     960LogLock := TCriticalSection.Create;
    895961MainScheduler := TMicroThreadScheduler.Create;
    896962
     
    898964
    899965MainScheduler.Free;
     966LogLock.Free;
    900967
    901968end.
  • MicroThreading/UPlatform.pas

    r149 r156  
    88  {$IFDEF Windows}Windows,{$ENDIF}
    99  {$IFDEF Linux}BaseUnix, UnixUtil, Unix,{$ENDIF}
    10   Classes, SysUtils, DateUtils;
     10  Classes, SysUtils, DateUtils, SyncObjs;
    1111
    1212function NowPrecise: TDateTime;
     
    2020{$ENDIF}
    2121
     22var
     23  NowPreciseLock: TCriticalSection;
    2224
    2325function NowPrecise: TDateTime;
     
    2628  {$IFDEF Windows}TimerValue: Int64;{$ENDIF}
    2729begin
    28   {$IFDEF Windows}
    29   QueryPerformanceCounter(TimerValue);
    30   //Result := Int64(TimeStampToMSecs(DateTimeToTimeStamp(Now)) * 1000) // an alternative Win32 timebase
    31   Result := TimerValue / PerformanceFrequency;
    32   {$ENDIF}
     30  try
     31    NowPreciseLock.Acquire;
     32    {$IFDEF Windows}
     33    QueryPerformanceCounter(TimerValue);
     34    //Result := Int64(TimeStampToMSecs(DateTimeToTimeStamp(Now)) * 1000) // an alternative Win32 timebase
     35    Result := TimerValue / PerformanceFrequency;
     36    {$ENDIF}
    3337
    34   {$IFDEF Linux}
    35   fpgettimeofday(@t, nil);
    36    // Build a 64 bit microsecond tick from the seconds and microsecond longints
    37   Result := t.tv_sec + t.tv_usec / 1000000;
    38   {$ENDIF}
     38    {$IFDEF Linux}
     39    fpgettimeofday(@t, nil);
     40     // Build a 64 bit microsecond tick from the seconds and microsecond longints
     41    Result := t.tv_sec + t.tv_usec / 1000000;
     42    {$ENDIF}
    3943
    40   Result := (Trunc(Now / OneSecond) + Frac(Result)) * OneSecond;
     44    Result := (Trunc(Now / OneSecond) + Frac(Result)) * OneSecond;
     45  finally
     46    NowPreciseLock.Release;
     47  end;
    4148end;
    4249
     
    5865QueryPerformanceFrequency(PerformanceFrequency);
    5966{$ENDIF}
     67NowPreciseLock := TCriticalSection.Create;
     68
     69finalization
     70
     71NowPreciseLock.Free;
    6072
    6173end.
Note: See TracChangeset for help on using the changeset viewer.