Changeset 164


Ignore:
Timestamp:
Feb 8, 2011, 11:05:30 AM (13 years ago)
Author:
george
Message:
  • Modified: Optimalized microthread execution from main thread.
  • Fixed: Passthrough of WaitFor on already signaled event.
Location:
MicroThreading
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • MicroThreading/Demo/Demo.lpi

    r162 r164  
    4343      </Item3>
    4444    </RequiredPackages>
    45     <Units Count="28">
     45    <Units Count="30">
    4646      <Unit0>
    4747        <Filename Value="Demo.lpr"/>
     
    5959        <ResourceBaseClass Value="Form"/>
    6060        <UnitName Value="UMainForm"/>
    61         <EditorIndex Value="6"/>
    62         <WindowIndex Value="0"/>
    63         <TopLine Value="372"/>
    64         <CursorPos X="21" Y="378"/>
     61        <IsVisibleTab Value="True"/>
     62        <EditorIndex Value="9"/>
     63        <WindowIndex Value="0"/>
     64        <TopLine Value="332"/>
     65        <CursorPos X="23" Y="342"/>
    6566        <UsageCount Value="270"/>
    6667        <Loaded Value="True"/>
     
    7071        <Filename Value="../UMicroThreading.pas"/>
    7172        <UnitName Value="UMicroThreading"/>
    72         <IsVisibleTab Value="True"/>
    7373        <EditorIndex Value="0"/>
    7474        <WindowIndex Value="0"/>
    75         <TopLine Value="976"/>
    76         <CursorPos X="18" Y="986"/>
     75        <TopLine Value="986"/>
     76        <CursorPos X="19" Y="1000"/>
    7777        <UsageCount Value="136"/>
    7878        <Loaded Value="True"/>
     
    126126        <Filename Value="../UPlatform.pas"/>
    127127        <UnitName Value="UPlatform"/>
    128         <WindowIndex Value="0"/>
    129         <TopLine Value="23"/>
    130         <CursorPos X="31" Y="38"/>
     128        <EditorIndex Value="3"/>
     129        <WindowIndex Value="0"/>
     130        <TopLine Value="25"/>
     131        <CursorPos X="41" Y="39"/>
    131132        <UsageCount Value="37"/>
     133        <Loaded Value="True"/>
    132134      </Unit9>
    133135      <Unit10>
     
    136138        <ResourceBaseClass Value="Form"/>
    137139        <UnitName Value="UMicroThreadList"/>
    138         <EditorIndex Value="4"/>
    139         <WindowIndex Value="0"/>
    140         <TopLine Value="83"/>
    141         <CursorPos X="84" Y="94"/>
     140        <EditorIndex Value="7"/>
     141        <WindowIndex Value="0"/>
     142        <TopLine Value="53"/>
     143        <CursorPos X="61" Y="61"/>
    142144        <UsageCount Value="23"/>
    143145        <Loaded Value="True"/>
     
    239241        <Filename Value="../../../../Projekty2/FreePascalManager/trunk/Instance/1/FPC/packages/fcl-base/src/syncobjs.pp"/>
    240242        <UnitName Value="syncobjs"/>
    241         <EditorIndex Value="5"/>
     243        <EditorIndex Value="8"/>
    242244        <WindowIndex Value="0"/>
    243245        <TopLine Value="35"/>
     
    248250      <Unit25>
    249251        <Filename Value="../../../../Projekty2/FreePascalManager/trunk/Instance/1/Lazarus/lcl/include/customlistview.inc"/>
    250         <EditorIndex Value="1"/>
     252        <EditorIndex Value="4"/>
    251253        <WindowIndex Value="0"/>
    252254        <TopLine Value="548"/>
     
    257259      <Unit26>
    258260        <Filename Value="../../../../Projekty2/FreePascalManager/trunk/Instance/1/Lazarus/lcl/include/listitem.inc"/>
    259         <EditorIndex Value="2"/>
     261        <EditorIndex Value="5"/>
    260262        <WindowIndex Value="0"/>
    261263        <TopLine Value="798"/>
     
    266268      <Unit27>
    267269        <Filename Value="../../../../Projekty2/FreePascalManager/trunk/Instance/1/Lazarus/lcl/include/listitems.inc"/>
    268         <EditorIndex Value="3"/>
     270        <EditorIndex Value="6"/>
    269271        <WindowIndex Value="0"/>
    270272        <TopLine Value="65"/>
     
    273275        <Loaded Value="True"/>
    274276      </Unit27>
     277      <Unit28>
     278        <Filename Value="../../../../Projekty2/FreePascalManager/trunk/Instance/1/Lazarus/lcl/forms.pp"/>
     279        <UnitName Value="Forms"/>
     280        <EditorIndex Value="1"/>
     281        <WindowIndex Value="0"/>
     282        <TopLine Value="1398"/>
     283        <CursorPos X="15" Y="1309"/>
     284        <UsageCount Value="10"/>
     285        <Loaded Value="True"/>
     286      </Unit28>
     287      <Unit29>
     288        <Filename Value="../../../../Projekty2/FreePascalManager/trunk/Instance/1/Lazarus/lcl/include/application.inc"/>
     289        <EditorIndex Value="2"/>
     290        <WindowIndex Value="0"/>
     291        <TopLine Value="2161"/>
     292        <CursorPos X="33" Y="2161"/>
     293        <UsageCount Value="10"/>
     294        <Loaded Value="True"/>
     295      </Unit29>
    275296    </Units>
    276297    <JumpHistory Count="30" HistoryIndex="29">
    277298      <Position1>
    278         <Filename Value="../UMicroThreading.pas"/>
    279         <Caret Line="371" Column="16" TopLine="350"/>
     299        <Filename Value="UMainForm.pas"/>
     300        <Caret Line="374" Column="21" TopLine="368"/>
    280301      </Position1>
    281302      <Position2>
    282         <Filename Value="../UMicroThreading.pas"/>
    283         <Caret Line="652" Column="38" TopLine="631"/>
     303        <Filename Value="UMainForm.pas"/>
     304        <Caret Line="373" Column="21" TopLine="367"/>
    284305      </Position2>
    285306      <Position3>
    286         <Filename Value="../UMicroThreading.pas"/>
    287         <Caret Line="746" Column="12" TopLine="725"/>
     307        <Filename Value="UMainForm.pas"/>
     308        <Caret Line="372" Column="21" TopLine="366"/>
    288309      </Position3>
    289310      <Position4>
    290         <Filename Value="../UMicroThreading.pas"/>
    291         <Caret Line="750" Column="31" TopLine="729"/>
     311        <Filename Value="../UMicroThreadList.pas"/>
     312        <Caret Line="94" Column="84" TopLine="83"/>
    292313      </Position4>
    293314      <Position5>
    294         <Filename Value="../UMicroThreading.pas"/>
    295         <Caret Line="753" Column="26" TopLine="732"/>
     315        <Filename Value="../UMicroThreadList.pas"/>
     316        <Caret Line="17" Column="7" TopLine="4"/>
    296317      </Position5>
    297318      <Position6>
    298         <Filename Value="../UMicroThreading.pas"/>
    299         <Caret Line="935" Column="13" TopLine="914"/>
     319        <Filename Value="../UMicroThreadList.pas"/>
     320        <Caret Line="15" Column="38" TopLine="7"/>
    300321      </Position6>
    301322      <Position7>
    302         <Filename Value="../UMicroThreading.pas"/>
    303         <Caret Line="983" Column="31" TopLine="968"/>
     323        <Filename Value="../UMicroThreadList.pas"/>
     324        <Caret Line="17" Column="12" TopLine="4"/>
    304325      </Position7>
    305326      <Position8>
    306         <Filename Value="../UMicroThreading.pas"/>
    307         <Caret Line="1013" Column="24" TopLine="992"/>
     327        <Filename Value="../UMicroThreadList.pas"/>
     328        <Caret Line="18" Column="12" TopLine="4"/>
    308329      </Position8>
    309330      <Position9>
    310         <Filename Value="../UMicroThreading.pas"/>
    311         <Caret Line="8" Column="19" TopLine="1"/>
     331        <Filename Value="../UMicroThreadList.pas"/>
     332        <Caret Line="19" Column="12" TopLine="4"/>
    312333      </Position9>
    313334      <Position10>
    314         <Filename Value="../UMicroThreading.pas"/>
    315         <Caret Line="652" Column="51" TopLine="639"/>
     335        <Filename Value="../UMicroThreadList.pas"/>
     336        <Caret Line="20" Column="12" TopLine="4"/>
    316337      </Position10>
    317338      <Position11>
    318         <Filename Value="../UMicroThreading.pas"/>
    319         <Caret Line="645" Column="28" TopLine="639"/>
     339        <Filename Value="../UMicroThreadList.pas"/>
     340        <Caret Line="21" Column="12" TopLine="4"/>
    320341      </Position11>
    321342      <Position12>
    322         <Filename Value="../UMicroThreading.pas"/>
    323         <Caret Line="653" Column="43" TopLine="639"/>
     343        <Filename Value="../UMicroThreadList.pas"/>
     344        <Caret Line="22" Column="12" TopLine="4"/>
    324345      </Position12>
    325346      <Position13>
    326         <Filename Value="../UMicroThreading.pas"/>
    327         <Caret Line="479" Column="1" TopLine="466"/>
     347        <Filename Value="UMainForm.pas"/>
     348        <Caret Line="372" Column="21" TopLine="26"/>
    328349      </Position13>
    329350      <Position14>
    330         <Filename Value="../UMicroThreading.pas"/>
    331         <Caret Line="712" Column="1" TopLine="699"/>
     351        <Filename Value="../UMicroThreadList.pas"/>
     352        <Caret Line="23" Column="12" TopLine="13"/>
    332353      </Position14>
    333354      <Position15>
    334         <Filename Value="../UMicroThreading.pas"/>
    335         <Caret Line="582" Column="18" TopLine="571"/>
     355        <Filename Value="../UMicroThreadList.pas"/>
     356        <Caret Line="68" Column="3" TopLine="53"/>
    336357      </Position15>
    337358      <Position16>
    338         <Filename Value="../UMicroThreading.pas"/>
    339         <Caret Line="583" Column="65" TopLine="571"/>
     359        <Filename Value="../UMicroThreadList.pas"/>
     360        <Caret Line="69" Column="1" TopLine="53"/>
    340361      </Position16>
    341362      <Position17>
    342         <Filename Value="../UMicroThreading.pas"/>
    343         <Caret Line="582" Column="20" TopLine="571"/>
     363        <Filename Value="UMainForm.pas"/>
     364        <Caret Line="85" Column="15" TopLine="69"/>
    344365      </Position17>
    345366      <Position18>
    346         <Filename Value="../UMicroThreading.pas"/>
    347         <Caret Line="583" Column="1" TopLine="571"/>
     367        <Filename Value="../UMicroThreadList.pas"/>
     368        <Caret Line="9" Column="43" TopLine="1"/>
    348369      </Position18>
    349370      <Position19>
    350         <Filename Value="../UMicroThreading.pas"/>
    351         <Caret Line="711" Column="1" TopLine="698"/>
     371        <Filename Value="../UMicroThreadList.pas"/>
     372        <Caret Line="72" Column="1" TopLine="53"/>
    352373      </Position19>
    353374      <Position20>
    354375        <Filename Value="../UMicroThreading.pas"/>
    355         <Caret Line="712" Column="1" TopLine="698"/>
     376        <Caret Line="1006" Column="18" TopLine="991"/>
    356377      </Position20>
    357378      <Position21>
    358379        <Filename Value="../UMicroThreading.pas"/>
    359         <Caret Line="713" Column="1" TopLine="698"/>
     380        <Caret Line="1010" Column="26" TopLine="991"/>
    360381      </Position21>
    361382      <Position22>
    362383        <Filename Value="../UMicroThreading.pas"/>
    363         <Caret Line="714" Column="1" TopLine="698"/>
     384        <Caret Line="1009" Column="22" TopLine="991"/>
    364385      </Position22>
    365386      <Position23>
    366387        <Filename Value="../UMicroThreading.pas"/>
    367         <Caret Line="715" Column="1" TopLine="698"/>
     388        <Caret Line="1004" Column="43" TopLine="991"/>
    368389      </Position23>
    369390      <Position24>
    370         <Filename Value="../UMicroThreadList.pas"/>
    371         <Caret Line="95" Column="54" TopLine="83"/>
     391        <Filename Value="UMainForm.pas"/>
     392        <Caret Line="337" Column="23" TopLine="327"/>
    372393      </Position24>
    373394      <Position25>
    374         <Filename Value="../UMicroThreading.pas"/>
    375         <Caret Line="240" Column="45" TopLine="227"/>
     395        <Filename Value="UMainForm.pas"/>
     396        <Caret Line="338" Column="23" TopLine="328"/>
    376397      </Position25>
    377398      <Position26>
    378         <Filename Value="../UMicroThreading.pas"/>
    379         <Caret Line="984" Column="40" TopLine="979"/>
     399        <Filename Value="UMainForm.pas"/>
     400        <Caret Line="339" Column="23" TopLine="329"/>
    380401      </Position26>
    381402      <Position27>
    382         <Filename Value="../UMicroThreading.pas"/>
    383         <Caret Line="992" Column="38" TopLine="979"/>
     403        <Filename Value="UMainForm.pas"/>
     404        <Caret Line="338" Column="23" TopLine="328"/>
    384405      </Position27>
    385406      <Position28>
    386         <Filename Value="../UMicroThreading.pas"/>
    387         <Caret Line="989" Column="55" TopLine="976"/>
     407        <Filename Value="UMainForm.pas"/>
     408        <Caret Line="339" Column="23" TopLine="329"/>
    388409      </Position28>
    389410      <Position29>
    390         <Filename Value="../UMicroThreading.pas"/>
    391         <Caret Line="990" Column="24" TopLine="976"/>
     411        <Filename Value="UMainForm.pas"/>
     412        <Caret Line="340" Column="23" TopLine="330"/>
    392413      </Position29>
    393414      <Position30>
    394         <Filename Value="../UMicroThreading.pas"/>
    395         <Caret Line="989" Column="29" TopLine="976"/>
     415        <Filename Value="UMainForm.pas"/>
     416        <Caret Line="341" Column="23" TopLine="331"/>
    396417      </Position30>
    397418    </JumpHistory>
  • MicroThreading/Demo/UMainForm.lfm

    r162 r164  
    55  Width = 816
    66  Caption = 'MicroThreading demo'
    7   ClientHeight = 533
     7  ClientHeight = 514
    88  ClientWidth = 816
     9  Menu = MainMenu1
    910  OnCreate = FormCreate
    1011  OnDestroy = FormDestroy
     
    1314  object PageControl1: TPageControl
    1415    Left = 8
    15     Height = 519
     16    Height = 500
    1617    Top = 8
    1718    Width = 802
     
    2223    object TabSheet2: TTabSheet
    2324      Caption = 'Scheduler state'
    24       ClientHeight = 493
     25      ClientHeight = 474
    2526      ClientWidth = 794
    2627      object GroupBox1: TGroupBox
     
    3334        ClientWidth = 201
    3435        TabOrder = 0
    35         object Label5: TLabel
    36           Left = 9
    37           Height = 14
    38           Top = 4
    39           Width = 117
    40           Caption = 'Logical processor count:'
    41           ParentColor = False
    42         end
    43         object Label6: TLabel
    44           Left = 150
    45           Height = 14
    46           Top = 4
    47           Width = 13
    48           Caption = '    '
    49           ParentColor = False
    50         end
    51         object Label7: TLabel
    52           Left = 8
    53           Height = 14
    54           Top = 20
    55           Width = 69
    56           Caption = 'Thread count:'
    57           ParentColor = False
    58         end
    59         object Label8: TLabel
    60           Left = 9
    61           Height = 14
    62           Top = 36
    63           Width = 95
    64           Caption = 'Micro thread count:'
    65           ParentColor = False
    66         end
    67         object Label9: TLabel
    68           Left = 150
    69           Height = 14
    70           Top = 20
    71           Width = 13
    72           Caption = '    '
    73           ParentColor = False
    74         end
    75         object Label10: TLabel
    76           Left = 151
    77           Height = 14
    78           Top = 36
    79           Width = 13
    80           Caption = '    '
    81           ParentColor = False
    82         end
    8336        object Label15: TLabel
    8437          Left = 9
     
    403356    top = 115
    404357  end
     358  object MainMenu1: TMainMenu
     359    left = 512
     360    top = 115
     361    object MenuItem1: TMenuItem
     362      Caption = 'New Item1'
     363      object MenuItem2: TMenuItem
     364        Caption = 'New Item2'
     365      end
     366      object MenuItem4: TMenuItem
     367        Caption = 'New Item4'
     368      end
     369    end
     370    object MenuItem3: TMenuItem
     371      Caption = 'New Item3'
     372    end
     373  end
    405374end
  • MicroThreading/Demo/UMainForm.pas

    r162 r164  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ComCtrls, ExtCtrls, Spin, UMicroThreading, DateUtils, UPlatform,
     9  ComCtrls, ExtCtrls, Spin, Menus, UMicroThreading, DateUtils, UPlatform,
    1010  UMicroThreadList, UThreadEx;
    1111
     
    4646    GroupBox2: TGroupBox;
    4747    GroupBox3: TGroupBox;
    48     Label10: TLabel;
    4948    Label11: TLabel;
    5049    Label12: TLabel;
     
    5756    Label3: TLabel;
    5857    Label4: TLabel;
    59     Label5: TLabel;
    60     Label6: TLabel;
    61     Label7: TLabel;
    62     Label8: TLabel;
    63     Label9: TLabel;
     58    MainMenu1: TMainMenu;
    6459    Memo1: TMemo;
     60    MenuItem1: TMenuItem;
     61    MenuItem2: TMenuItem;
     62    MenuItem3: TMenuItem;
     63    MenuItem4: TMenuItem;
    6564    PageControl1: TPageControl;
    6665    SpinEdit1: TSpinEdit;
     
    134133  DoubleBuffered := True;
    135134//  ListView1.DoubleBuffered := True;
    136   Label6.Caption := IntToStr(GetLogicalProcessorCount);
    137135  Event := TMicroThreadEvent.Create;
    138136  MicroThreadList := TMicroThreadList.Create(Self);
     
    345343  Label2.Caption := DateTimeToStr(NowPrecise) + ' ' +
    346344    FloatToStr(Frac(NowPrecise / OneSecond));
    347   Label9.Caption := IntToStr(MainScheduler.ThreadPoolCount);
    348   Label10.Caption := IntToStr(MainScheduler.MicroThreadCount);
    349345end;
    350346
  • MicroThreading/UMicroThreadList.lfm

    r162 r164  
    11object MicroThreadListForm: TMicroThreadListForm
    2   Left = 367
     2  Left = 476
    33  Height = 423
    4   Top = 118
     4  Top = 111
    55  Width = 569
    66  Caption = 'Microthread list'
    77  ClientHeight = 423
    88  ClientWidth = 569
     9  OnClose = FormClose
    910  OnHide = FormHide
    1011  OnShow = FormShow
    1112  LCLVersion = '0.9.31'
    12   object Panel1: TPanel
    13     Left = 0
    14     Height = 248
    15     Top = 0
    16     Width = 569
    17     Align = alTop
    18     BevelOuter = bvNone
    19     ClientHeight = 248
    20     ClientWidth = 569
     13  object PageControl1: TPageControl
     14    Left = 8
     15    Height = 409
     16    Top = 7
     17    Width = 553
     18    ActivePage = TabSheet1
     19    Anchors = [akTop, akLeft, akRight, akBottom]
     20    TabIndex = 0
    2121    TabOrder = 0
    22     object Label1: TLabel
    23       Left = 8
    24       Height = 14
    25       Top = 8
    26       Width = 67
    27       Caption = 'Microthreads:'
    28       ParentColor = False
     22    object TabSheet1: TTabSheet
     23      Caption = 'State'
     24      ClientHeight = 383
     25      ClientWidth = 545
     26      object Label5: TLabel
     27        Left = 9
     28        Height = 14
     29        Top = 11
     30        Width = 117
     31        Caption = 'Logical processor count:'
     32        ParentColor = False
     33      end
     34      object Label7: TLabel
     35        Left = 8
     36        Height = 14
     37        Top = 27
     38        Width = 69
     39        Caption = 'Thread count:'
     40        ParentColor = False
     41      end
     42      object Label8: TLabel
     43        Left = 9
     44        Height = 14
     45        Top = 43
     46        Width = 95
     47        Caption = 'Micro thread count:'
     48        ParentColor = False
     49      end
     50      object Label10: TLabel
     51        Left = 151
     52        Height = 14
     53        Top = 43
     54        Width = 13
     55        Caption = '    '
     56        ParentColor = False
     57      end
     58      object Label9: TLabel
     59        Left = 150
     60        Height = 14
     61        Top = 27
     62        Width = 13
     63        Caption = '    '
     64        ParentColor = False
     65      end
     66      object Label6: TLabel
     67        Left = 150
     68        Height = 14
     69        Top = 11
     70        Width = 13
     71        Caption = '    '
     72        ParentColor = False
     73      end
     74      object Label1: TLabel
     75        Left = 8
     76        Height = 14
     77        Top = 63
     78        Width = 128
     79        Caption = 'Main thread loop duration:'
     80        ParentColor = False
     81      end
     82      object Label2: TLabel
     83        Left = 148
     84        Height = 14
     85        Top = 64
     86        Width = 13
     87        Caption = '    '
     88        ParentColor = False
     89      end
    2990    end
    30     object ListView1: TListView
    31       Left = 8
    32       Height = 218
    33       Top = 24
    34       Width = 557
    35       Anchors = [akTop, akLeft, akRight, akBottom]
    36       Columns = <     
    37         item
    38           Caption = 'Id'
    39           Width = 40
    40         end     
    41         item
    42           Caption = 'Usage'
    43         end     
    44         item
    45           Caption = 'Priority'
    46           Width = 40
    47         end     
    48         item
    49           Caption = 'State'
    50           Width = 60
    51         end     
    52         item
    53           Caption = 'Block state'
    54         end     
    55         item
    56           Caption = 'Execution time'
    57           Width = 70
    58         end     
    59         item
    60           Caption = 'Tick count'
    61         end     
    62         item
    63           Caption = 'Completion'
    64         end     
    65         item
    66           Caption = 'Used stack'
    67         end     
    68         item
    69           Caption = 'Name'
    70           Width = 70
    71         end>
    72       OwnerData = True
    73       ReadOnly = True
    74       RowSelect = True
    75       TabOrder = 0
    76       ViewStyle = vsReport
    77       OnData = ListView1Data
     91    object TabSheet2: TTabSheet
     92      Caption = 'Threads'
     93      ClientHeight = 383
     94      ClientWidth = 545
     95      object ListView2: TListView
     96        Left = 4
     97        Height = 376
     98        Top = 3
     99        Width = 536
     100        Anchors = [akTop, akLeft, akRight, akBottom]
     101        Columns = <       
     102          item
     103            Caption = 'Id'
     104          end       
     105          item
     106            Caption = 'State'
     107            Width = 100
     108          end       
     109          item
     110            Caption = 'Microthread Id'
     111            Width = 70
     112          end       
     113          item
     114            Caption = 'Loop duration'
     115            Width = 70
     116          end>
     117        OwnerData = True
     118        ReadOnly = True
     119        RowSelect = True
     120        TabOrder = 0
     121        ViewStyle = vsReport
     122        OnData = ListView2Data
     123      end
    78124    end
    79   end
    80   object Panel2: TPanel
    81     Left = 0
    82     Height = 170
    83     Top = 253
    84     Width = 569
    85     Align = alClient
    86     BevelOuter = bvNone
    87     ClientHeight = 170
    88     ClientWidth = 569
    89     TabOrder = 1
    90     object ListView2: TListView
    91       Left = 8
    92       Height = 142
    93       Top = 19
    94       Width = 557
    95       Anchors = [akTop, akLeft, akRight, akBottom]
    96       Columns = <     
    97         item
    98           Caption = 'Id'
    99         end     
    100         item
    101           Caption = 'State'
    102           Width = 100
    103         end     
    104         item
    105           Caption = 'Microthread Id'
    106           Width = 70
    107         end     
    108         item
    109           Caption = 'Loop duration'
    110           Width = 70
    111         end>
    112       OwnerData = True
    113       ReadOnly = True
    114       RowSelect = True
    115       TabOrder = 0
    116       ViewStyle = vsReport
    117       OnData = ListView2Data
     125    object TabSheet3: TTabSheet
     126      Caption = 'Microthreads'
     127      ClientHeight = 383
     128      ClientWidth = 545
     129      object ListView1: TListView
     130        Left = 4
     131        Height = 376
     132        Top = 3
     133        Width = 537
     134        Anchors = [akTop, akLeft, akRight, akBottom]
     135        Columns = <       
     136          item
     137            Caption = 'Id'
     138            Width = 40
     139          end       
     140          item
     141            Caption = 'Usage'
     142          end       
     143          item
     144            Caption = 'Priority'
     145            Width = 40
     146          end       
     147          item
     148            Caption = 'State'
     149            Width = 60
     150          end       
     151          item
     152            Caption = 'Block state'
     153          end       
     154          item
     155            Caption = 'Execution time'
     156            Width = 70
     157          end       
     158          item
     159            Caption = 'Tick count'
     160          end       
     161          item
     162            Caption = 'Completion'
     163          end       
     164          item
     165            Caption = 'Used stack'
     166          end       
     167          item
     168            Caption = 'Name'
     169            Width = 70
     170          end>
     171        OwnerData = True
     172        ReadOnly = True
     173        RowSelect = True
     174        TabOrder = 0
     175        ViewStyle = vsReport
     176        OnData = ListView1Data
     177      end
    118178    end
    119     object Label2: TLabel
    120       Left = 8
    121       Height = 14
    122       Top = 3
    123       Width = 44
    124       Caption = 'Threads:'
    125       ParentColor = False
    126     end
    127   end
    128   object Splitter1: TSplitter
    129     Cursor = crVSplit
    130     Left = 0
    131     Height = 5
    132     Top = 248
    133     Width = 569
    134     Align = alTop
    135     ResizeAnchor = akTop
    136179  end
    137180  object TimerRedraw: TTimer
    138181    Enabled = False
    139     Interval = 50
     182    Interval = 200
    140183    OnTimer = TimerRedrawTimer
    141184    left = 192
  • MicroThreading/UMicroThreadList.pas

    r162 r164  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
    9   ExtCtrls, StdCtrls, DateUtils;
     9  ExtCtrls, StdCtrls, DateUtils, UPlatform;
    1010
    1111type
     
    1414
    1515  TMicroThreadListForm = class(TForm)
     16  published
     17    Label10: TLabel;
     18    Label5: TLabel;
     19    Label6: TLabel;
     20    Label7: TLabel;
     21    Label8: TLabel;
     22    Label9: TLabel;
     23    TimerRedraw: TTimer;
    1624    Label1: TLabel;
    1725    Label2: TLabel;
    1826    ListView1: TListView;
    1927    ListView2: TListView;
    20     Panel1: TPanel;
    21     Panel2: TPanel;
    22     Splitter1: TSplitter;
    23     TimerRedraw: TTimer;
     28    PageControl1: TPageControl;
     29    TabSheet1: TTabSheet;
     30    TabSheet2: TTabSheet;
     31    TabSheet3: TTabSheet;
     32    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    2433    procedure FormHide(Sender: TObject);
    2534    procedure FormShow(Sender: TObject);
     
    5766  ListView2.Items[-1];
    5867  ListView2.Refresh;
     68
     69  Label6.Caption := IntToStr(GetLogicalProcessorCount);
     70  Label9.Caption := IntToStr(MainScheduler.ThreadPoolCount);
     71  Label10.Caption := IntToStr(MainScheduler.MicroThreadCount);
     72  Label2.Caption := FloatToStr(MainScheduler.MainThreadOutsideDuration / OneMillisecond) + ' ms';
    5973end;
    6074
     
    120134end;
    121135
     136procedure TMicroThreadListForm.FormClose(Sender: TObject;
     137  var CloseAction: TCloseAction);
     138begin
     139  TimerRedraw.Enabled := False;
     140end;
     141
    122142
    123143end.
  • MicroThreading/UMicroThreading.pas

    r162 r164  
    2424
    2525const
    26   DefaultStackSize = $4000;
     26  DefaultStackSize = $8000;
    2727
    2828resourcestring
     
    210210    FMainThreadStarter: TTimer;
    211211    FEvents: TObjectList;
     212    FMainThreadOutsideStart: TDateTime;
     213    FMainThreadOutsideDuration: TDateTime;
    212214    function GetMicroThreadCount: Integer;
    213215    function GetThreadPoolCount: Integer;
     
    241243    property Active: Boolean read FActive write SetActive;
    242244    property UseMainThread: Boolean read FUseMainThread write SetUseMainThread;
     245    property MainThreadOutsideDuration: TDateTime read FMainThreadOutsideDuration;
    243246  end;
    244247
     
    339342  MT := GetCurrentMicroThread;
    340343  if Assigned(MT) then Result := MT.WaitForEvent(Event, Duration)
    341     else raise Exception.Create(SNotInThread);
     344    else begin
     345      while not Event.Signaled do begin
     346        Sleep(1);
     347        Application.ProcessMessages;
     348      end;
     349      //raise Exception.Create(SNotInThread);
    342350//    else Result := Event.WaitFor(Trunc(Duration / OneMillisecond));
     351    end;
    343352end;
    344353
     
    487496function TMicroThreadManager.Execute(Count: Integer): Integer;
    488497begin
    489   FLoopStart := NowPrecise;
     498  //FLoopStart := NowPrecise;
    490499  FStack := StackBottom;
    491500  FStackSize := StackBottom + StackLength;
     
    494503  Yield;
    495504  Result := FExecutedCount;
    496   FLoopDuration := NowPrecise - FLoopStart;
     505  //FLoopDuration := NowPrecise - FLoopStart;
    497506end;
    498507
     
    615624begin
    616625  if Assigned(FThread) then
    617     FThread.Synchronize(FThread, AMethod);
     626    FThread.Synchronize(FThread, AMethod)
     627    else AMethod;
    618628end;
    619629
     
    744754procedure TMicroThread.WaitFor;
    745755begin
    746   if GetMicroThreadId <> -1 then
    747   while not ((FState = tsBlocked) and (FBlockState = tbsTerminated)) do begin
    748     MTSleep(1);
     756  if GetMicroThreadId <> -1 then begin
     757    // Called from another microthread
     758    while not ((FState = tsBlocked) and (FBlockState = tbsTerminated)) do begin
     759      MTSleep(1);
     760    end;
     761  end else begin
     762    // Called directly from main thread
     763    while not ((FState = tsBlocked) and (FBlockState = tbsTerminated)) do begin
     764      Sleep(1);
     765      Application.ProcessMessages;
     766    end;
    749767  end;
    750768end;
     
    762780  try
    763781    Event.FMicroThreadsLock.Acquire;
     782    if Event.Signaled then begin
     783      Result := wrSignaled;
     784      Exit;
     785    end;
    764786    Event.FMicroThreads.Add(Self);
    765787    FBlockTime := NowPrecise + Duration;
     
    890912  FMainThreadManager.FScheduler := Self;
    891913  UseMainThread := False;
    892   BurstCount := 100;
     914  BurstCount := 50;
    893915end;
    894916
     
    9841006begin
    9851007//  try
    986     Duration := 100 * OneMillisecond;
    987     StartTime := NowPrecise;
     1008    FMainThreadOutsideDuration := NowPrecise - FMainThreadOutsideStart;
     1009    BurstCount := 1;
     1010    Duration := 50 * OneMillisecond;
     1011    StartTime := Now;
    9881012    Executed := -1;
    989     while (Executed <> 0) and ((NowPrecise - StartTime) < Duration) do begin
     1013    while (Executed <> 0) and ((Now - StartTime) < Duration) do begin
    9901014      Executed := FMainThreadManager.Execute(BurstCount);
    9911015    end;
     
    9991023//    raise;
    10001024//  end;
     1025  FMainThreadOutsideStart := NowPrecise;
    10011026end;
    10021027
  • MicroThreading/UPlatform.pas

    r156 r164  
    2828  {$IFDEF Windows}TimerValue: Int64;{$ENDIF}
    2929begin
    30   try
    31     NowPreciseLock.Acquire;
     30//  Result := Now;
     31  //try
     32    //NowPreciseLock.Acquire;
    3233    {$IFDEF Windows}
    3334    QueryPerformanceCounter(TimerValue);
     
    4243    {$ENDIF}
    4344
    44     Result := (Trunc(Now / OneSecond) + Frac(Result)) * OneSecond;
    45   finally
    46     NowPreciseLock.Release;
    47   end;
     45    Result := Result * OneSecond;
     46    //Result := (Trunc(Now / OneSecond) + Frac(Result)) * OneSecond;
     47  //finally
     48    //NowPreciseLock.Release;
     49  //end;
    4850end;
    4951
Note: See TracChangeset for help on using the changeset viewer.