Browse Source

GUI: thread-safe safebox access

Herman Schoenfeld 7 years ago
parent
commit
b2ac7e50a8
1 changed files with 26 additions and 22 deletions
  1. 26 22
      src/core/UDataSources.pas

+ 26 - 22
src/core/UDataSources.pas

@@ -445,30 +445,34 @@ begin
   node := TNode.Node;
   if Not Assigned(Node)
     then exit;
-  accountBlockOps := GC.AddObject(TOperationsResumeList.Create ) as TOperationsResumeList;
-  list := GC.AddObject( Classes.TList.Create ) as Classes.TList;
-  for acc in FAccounts do begin
-    // Load pending operations first
-    list.Clear;
-    accountBlockOps.Clear;
-    Node.Operations.OperationsHashTree.GetOperationsAffectingAccount( acc, list );
-    if list.Count > 0 then
-      for i := list.Count - 1 downto 0 do begin
-        Op := node.Operations.OperationsHashTree.GetOperation( PtrInt( list[i] ) );
-        If TPCOperation.OperationToOperationResume( 0, Op, acc, OPR ) then begin
-          OPR.NOpInsideBlock := i;
-          OPR.Block := Node.Operations.OperationBlock.block; ;
-          OPR.Balance := Node.Operations.SafeBoxTransaction.Account( acc {Op.SignerAccount} ).balance;
-          AContainer.Add(OPR);
-        end;
-    end;
+  TUserInterface.Node.Bank.SafeBox.StartThreadSafe;
+  try
+    accountBlockOps := GC.AddObject(TOperationsResumeList.Create ) as TOperationsResumeList;
+    list := GC.AddObject( Classes.TList.Create ) as Classes.TList;
+    for acc in FAccounts do begin
+      // Load pending operations first
+      list.Clear;
+      accountBlockOps.Clear;
+      Node.Operations.OperationsHashTree.GetOperationsAffectingAccount( acc, list );
+      if list.Count > 0 then
+        for i := list.Count - 1 downto 0 do begin
+          Op := node.Operations.OperationsHashTree.GetOperation( PtrInt( list[i] ) );
+          If TPCOperation.OperationToOperationResume( 0, Op, acc, OPR ) then begin
+            OPR.NOpInsideBlock := i;
+            OPR.Block := Node.Operations.OperationBlock.block; ;
+            OPR.Balance := Node.Operations.SafeBoxTransaction.Account( acc {Op.SignerAccount} ).balance;
+            AContainer.Add(OPR);
+          end;
+      end;
 
-    // Load block ops
-    Node.GetStoredOperationsFromAccount(accountBlockOps, acc, MaxInt, 0, MaxInt);
-    for i := 0 to accountBlockOps.Count - 1 do
-      AContainer.Add(accountBlockOps[i]);
+      // Load block ops
+      Node.GetStoredOperationsFromAccount(accountBlockOps, acc, MaxInt, 0, MaxInt);
+      for i := 0 to accountBlockOps.Count - 1 do
+        AContainer.Add(accountBlockOps[i]);
+    end;
+  finally
+   TUserInterface.Node.Bank.SafeBox.EndThreadSave;
   end;
-
 end;
 
 { TPendingOperationsDataSource }