Skip to content

Commit 9d240e1

Browse files
committed
Better function list updating in regards to locking
1 parent a78a9e4 commit 9d240e1

File tree

3 files changed

+40
-28
lines changed

3 files changed

+40
-28
lines changed

Source/ide/simba.form_functionlist.lfm

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
object SimbaFunctionListForm: TSimbaFunctionListForm
22
Left = -838
3-
Height = 463
3+
Height = 810
44
Top = 278
5-
Width = 428
5+
Width = 749
66
Caption = 'Function List'
7+
DesignTimePPI = 168
78
ShowInTaskBar = stAlways
89
LCLVersion = '4.0.0.4'
910
object Images: TImageList
1011
OnGetWidthForPPI = ImagesGetWidthForPPI
11-
Left = 172
12-
Top = 243
12+
Left = 301
13+
Top = 425
1314
Bitmap = {
1415
4C7A090000001000000010000000FE0900000000000078DAED98075454571A80
1516
D9933DD9B886C4355911980288D83642C482C678442C31C9311AC41A8393444D

Source/ide/simba.form_functionlist.pas

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
interface
1111

1212
uses
13-
Classes, SysUtils, Forms, Controls, ComCtrls, ExtCtrls, Menus, ImgList, syncobjs,
13+
Classes, SysUtils, Forms, Controls, ComCtrls, ExtCtrls, Menus, ImgList,
1414
simba.base,
15+
simba.containers,
1516
simba.ide_codetools_parser,
1617
simba.ide_codetools_insight,
1718
simba.ide_tab,
@@ -85,11 +86,13 @@ TSimbaFunctionListForm = class(TForm)
8586
Images: TImageList;
8687

8788
procedure ImagesGetWidthForPPI(Sender: TCustomImageList; AImageWidth, APPI: Integer; var AResultWidth: Integer);
89+
protected type
90+
TFunctionListPageList = specialize TSimbaList<TSimbaFunctionListPage>;
8891
protected
89-
FUpdateLock: TCriticalSection;
9092
FUpdateThread: TThread;
9193
FIsIdle: Boolean;
9294
FNotebook: TSimbaNotebook;
95+
FPendingRemoves: TFunctionListPageList;
9396

9497
function PageForTab(Tab: TSimbaScriptTab): TSimbaPage;
9598

@@ -120,10 +123,10 @@ implementation
120123
simba.ide_utils,
121124
simba.ide_showdeclaration,
122125
simba.vartype_string,
123-
simba.threading,
124126
simba.form_tabs,
125127
simba.nativeinterface,
126-
simba.fs;
128+
simba.fs,
129+
simba.threading;
127130

128131
const
129132
IMG_FOLDER = 0;
@@ -605,9 +608,9 @@ constructor TSimbaFunctionListPage.Create(AOwner: TComponent);
605608
FIncludesNode := FTreeView.AddNode('Includes', IMG_FOLDER);
606609
FPluginsNode := FTreeView.AddNode('Plugins', IMG_FOLDER);
607610

608-
FScriptNodeState := TTreeNodeExpandedState.Create(TTreeNode(nil));
611+
FScriptNodeState := TTreeNodeExpandedState.Create(TTreeNode(nil));
609612
FIncludesNodeState := TTreeNodeExpandedState.Create(TTreeNode(nil));
610-
FPluginsNodeState := TTreeNodeExpandedState.Create(TTreeNode(nil));
613+
FPluginsNodeState := TTreeNodeExpandedState.Create(TTreeNode(nil));
611614

612615
SimbaIDEEvents.Register(Self, SimbaIDEEvent.TAB_MODIFIED, @DoEditorModified);
613616
SimbaIDEEvents.Register(Self, SimbaIDEEvent.TAB_CHANGE, @DoEditorModified); // force a update on change
@@ -678,7 +681,7 @@ procedure TSimbaFunctionListPage.Fill;
678681
end;
679682

680683
begin
681-
if not FNeedUpdate then
684+
if (not FNeedUpdate) then
682685
Exit;
683686

684687
RunInMainThread(@BeginUpdate);
@@ -716,12 +719,13 @@ procedure TSimbaFunctionListForm.DoUpdateThread;
716719
try
717720
while not TThread.CurrentThread.CheckTerminated do
718721
begin
719-
if FIsIdle and FUpdateLock.TryEnter() then
720-
try
722+
if FIsIdle then
723+
begin
721724
if (FNotebook.ActivePage <> nil) then
722725
TSimbaFunctionListPage(FNotebook.ActivePage).Fill();
723-
finally
724-
FUpdateLock.Leave();
726+
727+
while (FPendingRemoves.Count > 0) do
728+
RunInMainThread(@FPendingRemoves.Pop.Free);
725729
end;
726730

727731
Sleep(350);
@@ -748,7 +752,7 @@ procedure TSimbaFunctionListForm.DoTabClosed(Sender: TObject);
748752
begin
749753
Page := PageForTab(TSimbaScriptTab(Sender));
750754
if (Page <> nil) then
751-
Page.Free();
755+
FPendingRemoves.Add(TSimbaFunctionListPage(Page));
752756

753757
{$IFDEF DEBUG}
754758
WriteLn('DoTabClosed: PageCount=',FNotebook.PageCount);
@@ -782,11 +786,11 @@ constructor TSimbaFunctionListForm.Create(TheOwner: TComponent);
782786
begin
783787
inherited Create(TheOwner);
784788

785-
SimbaIDEEvents.Register(Self, SimbaIDEEvent.CODETOOLS_SETUP, @DoCodetoolsSetup);
786-
SimbaIDEEvents.Register(Self, SimbaIDEEvent.TAB_CHANGE, @DoTabChange);
787-
SimbaIDEEvents.Register(Self, SimbaIDEEvent.TAB_CLOSED, @DoTabClosed);
788-
SimbaIDEEvents.Register(Self, SimbaIDEEvent.TAB_ADD, @DoTabAdd);
789-
SimbaIDEEvents.Register(Self, SimbaIDEEvent.SPLITTER_DOUBLE_CLICK, @DoDoubleClickSplitter);
789+
SimbaIDEEvents.Register(Self, SimbaIDEEvent.CODETOOLS_SETUP, @DoCodetoolsSetup);
790+
SimbaIDEEvents.Register(Self, SimbaIDEEvent.TAB_CHANGE, @DoTabChange);
791+
SimbaIDEEvents.Register(Self, SimbaIDEEvent.TAB_CLOSED, @DoTabClosed);
792+
SimbaIDEEvents.Register(Self, SimbaIDEEvent.TAB_ADD, @DoTabAdd);
793+
SimbaIDEEvents.Register(Self, SimbaIDEEvent.SPLITTER_DOUBLE_CLICK, @DoDoubleClickSplitter);
790794

791795
with TIdleTimer.Create(Self) do
792796
begin
@@ -802,18 +806,16 @@ constructor TSimbaFunctionListForm.Create(TheOwner: TComponent);
802806
FNotebook.Parent := Self;
803807
FNotebook.Align := alClient;
804808

805-
FUpdateLock := TCriticalSection.Create();
809+
FPendingRemoves := TFunctionListPageList.Create();
806810
end;
807811

808812
destructor TSimbaFunctionListForm.Destroy;
809813
begin
810-
FUpdateLock.Enter();
811814
FUpdateThread.Terminate();
812815
FUpdateThread.WaitFor();
813-
FUpdateLock.Leave();
814816

815-
FreeAndNil(FUpdateLock);
816817
FreeAndNil(FUpdateThread);
818+
FreeAndNil(FPendingRemoves);
817819

818820
inherited Destroy();
819821
end;

Source/simba.containers.pas

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ interface
2121

2222
type
2323
generic TSimbaList<_T> = class(TObject)
24-
private
25-
function GetFirst: _T;
26-
function GetLast: _T;
2724
public type
2825
TArr = array of _T;
2926
protected
3027
FArr: TArr;
3128
FCount: Integer;
3229

30+
function GetPop: _T; virtual;
31+
function GetFirst: _T; virtual;
32+
function GetLast: _T; virtual;
3333
function GetItem(Index: Integer): _T; virtual;
3434
procedure SetItem(Index: Integer; AValue: _T); virtual;
3535
public
@@ -41,6 +41,7 @@ generic TSimbaList<_T> = class(TObject)
4141
property Count: Integer read FCount;
4242
property Items[Index: Integer]: _T read GetItem write SetItem; default;
4343

44+
property Pop: _T read GetPop;
4445
property First: _T read GetFirst;
4546
property Last: _T read GetLast;
4647
end;
@@ -223,6 +224,14 @@ function TSimbaList.GetLast: _T;
223224
Result := FArr[FCount - 1];
224225
end;
225226

227+
function TSimbaList.GetPop: _T;
228+
begin
229+
if (FCount = 0) then
230+
SimbaException('%s.Pop: Index %d out of bounds', [ClassName, FCount - 1]);
231+
Result := FArr[FCount - 1];
232+
Dec(FCount);
233+
end;
234+
226235
function TSimbaList.GetItem(Index: Integer): _T;
227236
begin
228237
if (Index < 0) or (Index >= FCount) then

0 commit comments

Comments
 (0)