Browse Source

TPlatform.GetTickCount

and clean some unused vars
PascalCoin 7 years ago
parent
commit
0ebd28043d
4 changed files with 28 additions and 27 deletions
  1. 11 10
      src/core/UPoolMining.pas
  2. 4 4
      src/core/URPC.pas
  3. 6 6
      src/core/UTCPIP.pas
  4. 7 7
      src/core/UThread.pas

+ 11 - 10
src/core/UPoolMining.pas

@@ -164,7 +164,7 @@ Const
 
 implementation
 
-Uses ULog, Variants, UTime, UNetProtocol;
+Uses ULog, Variants, UTime, UNetProtocol, UBaseTypes;
 
 Type TPendingResponseMessage = Record
        sendDateTime : TDateTime;
@@ -222,7 +222,7 @@ end;
 function TJSONRPCTcpIpClient.DoProcessBuffer(SenderThread : TPCThread; MaxWaitMiliseconds : Cardinal; DeleteBufferOnExit : Boolean; var ResponseMethod : String; var jsonObject : TPCJSONObject) : Boolean;
 var last_bytes_read : Integer;
   jsonData : TPCJSONData;
-  tc : Cardinal;
+  tc : TTickCount;
   ms : TMemoryStream;
   i,lasti : Integer;
   continue : Boolean;
@@ -286,15 +286,15 @@ var islocked : Boolean;
 begin
   Result := false;
   ResponseMethod := '';
-  tc := GetTickCount;
+  tc := TPlatform.GetTickCount;
   Repeat
     islocked := FLockProcessBuffer.TryEnter;
-  until (islocked) Or ((GetTickCount>(tc+MaxWaitMiliseconds)) And (MaxWaitMiliseconds<>0));
+  until (islocked) Or ((TPlatform.GetTickCount>(tc+MaxWaitMiliseconds)) And (MaxWaitMiliseconds<>0));
   If Not islocked then exit;
   try
     if Assigned(SenderThread) then continue := Not SenderThread.Terminated
     else continue := true;
-    while (Connected) And ((GetTickCount<=(tc+MaxWaitMiliseconds)) Or (MaxWaitMiliseconds=0)) And (continue) do begin
+    while (Connected) And ((TPlatform.GetTickCount<=(tc+MaxWaitMiliseconds)) Or (MaxWaitMiliseconds=0)) And (continue) do begin
       last_bytes_read := 0;
       ms := ReadBufferLock;
       try
@@ -432,7 +432,8 @@ end;
 
 function TJSONRPCTcpIpClient.SendJSONRPCMethodAndWait(const method: String; params: TPCJSONList; MaxWaitMiliseconds: Cardinal; resultObject : TPCJSONObject; processEventOnInvalid : TProcessJSONObjectEvent = Nil) : Boolean;
 Var nId : Cardinal;
-  tc,maxw : Cardinal;
+  tc : TTickCount;
+  maxw : Cardinal;
   json : TPCJSONObject;
   rm : String;
 begin
@@ -441,11 +442,11 @@ begin
   try
     nId := GetNewId;
     SendJSONRPCMethod(method,params,nId);
-    tc := GetTickCount;
+    tc := TPlatform.GetTickCount;
     json := TPCJSONObject.Create;
     Try
       repeat
-        maxw := MaxWaitMiliseconds - (GetTickCount - tc);
+        maxw := MaxWaitMiliseconds - (TPlatform.GetTickCount - tc);
         if maxw<1 then maxw := 1
         else if maxw>10000 then maxw := 10000;
         If DoProcessBuffer(nil,maxw,true,rm,json) then begin
@@ -460,7 +461,7 @@ begin
             end else TLog.NewLog(lterror,Classname,'Lost JSON message! '+json.ToJSON(false));
           end;
         end;
-      until (Result) Or (GetTickCount > (tc+MaxWaitMiliseconds));
+      until (Result) Or (TPlatform.GetTickCount > (tc+MaxWaitMiliseconds));
     finally
       json.free;
     end;
@@ -877,7 +878,7 @@ begin
     inc(FIncomingsCounter);
     SendJobToMiner(nil,bClient,false,null);
     while (Active) And (Client.Connected) do begin
-      doDelete := bClient.LastReadTC+1000<GetTickCount;  // TODO: Protect GetTickCount overflow
+      doDelete := bClient.LastReadTC+1000<TPlatform.GetTickCount;  // TODO: Protect GetTickCount overflow
       jsonobj := TPCJSONObject.Create;
       try
         if bClient.DoProcessBuffer(nil,1000,doDelete,rmethod,jsonobj) then begin

+ 4 - 4
src/core/URPC.pas

@@ -21,7 +21,7 @@ interface
 
 Uses UThread, ULog, UConst, UNode, UAccounts, UCrypto, UBlockChain,
   UNetProtocol, UOpTransaction, UWallet, UTime, UAES, UECIES, UTxMultiOperation,
-  UJSONFunctions, classes, blcksock, synsock, IniFiles, Variants, math;
+  UJSONFunctions, classes, blcksock, synsock, IniFiles, Variants, math, UBaseTypes;
 
 Const
   CT_RPC_ErrNum_InternalError = 100;
@@ -511,11 +511,11 @@ var
   valid : Boolean;
   i : Integer;
   Headers : TStringList;
-  tc : Cardinal;
+  tc : TTickCount;
   callcounter : Int64;
 begin
   callcounter := _RPCServer.GetNewCallCounter;
-  tc := GetTickCount;
+  tc := TPlatform.GetTickCount;
   methodName := '';
   paramsTxt := '';
   // IP Protection
@@ -647,7 +647,7 @@ begin
           FSock.SendBuffer(addr(jsonresponsetxt[1]),Length(jsonresponsetxt));
         end;
       end;
-      _RPCServer.AddRPCLog(FSock.GetRemoteSinIP+':'+InttoStr(FSock.GetRemoteSinPort),'Method:'+methodName+' Params:'+paramsTxt+' '+Inttostr(errNum)+':'+errDesc+' Time:'+FormatFloat('0.000',(GetTickCount - tc)/1000));
+      _RPCServer.AddRPCLog(FSock.GetRemoteSinIP+':'+InttoStr(FSock.GetRemoteSinPort),'Method:'+methodName+' Params:'+paramsTxt+' '+Inttostr(errNum)+':'+errDesc+' Time:'+FormatFloat('0.000',(TPlatform.GetTickCount - tc)/1000));
     finally
       jsonresponse.free;
       Headers.Free;

+ 6 - 6
src/core/UTCPIP.pas

@@ -35,7 +35,7 @@ uses
   {$IFDEF DelphiSockets}
   Sockets,
   {$ENDIF}
-  Classes, Sysutils,
+  Classes, Sysutils, UBaseTypes,
   UThread, SyncObjs;
 
 type
@@ -113,7 +113,7 @@ type
     FSendBuffer : TMemoryStream;
     FReadBuffer : TMemoryStream;
     FCritical : TPCCriticalSection;
-    FLastReadTC : Cardinal;
+    FLastReadTC : TTickCount;
     FBufferedNetTcpIpClientThread : TBufferedNetTcpIpClientThread;
   protected
     Function DoWaitForDataInherited(WaitMilliseconds : Integer) : Boolean;
@@ -124,7 +124,7 @@ type
     Procedure WriteBufferToSend(SendData : TStream);
     Function ReadBufferLock : TMemoryStream;
     Procedure ReadBufferUnlock;
-    Property LastReadTC : Cardinal read FLastReadTC;
+    Property LastReadTC : TTickCount read FLastReadTC;
   End;
 
   {$IFDEF Synapse}
@@ -562,7 +562,7 @@ var SendBuffStream : TStream;
         if (last_bytes_read>0) then begin
           ms := FBufferedNetTcpIpClient.ReadBufferLock;
           Try
-            FBufferedNetTcpIpClient.FLastReadTC := GetTickCount;
+            FBufferedNetTcpIpClient.FLastReadTC := TPlatform.GetTickCount;
             lastpos := ms.Position;
             ms.Position := ms.Size;
             ms.Write(ReceiveBuffer,last_bytes_read);
@@ -608,7 +608,7 @@ begin
         If (Not Terminated) And (FBufferedNetTcpIpClient.Connected) then DoReceiveBuf;
         // Send Data
         If (Not Terminated) And (FBufferedNetTcpIpClient.Connected) then DoSendBuf;
-      end else FBufferedNetTcpIpClient.FLastReadTC := GetTickCount;
+      end else FBufferedNetTcpIpClient.FLastReadTC := TPlatform.GetTickCount;
       // Sleep
       Sleep(10); // Slepp 10 is better than sleep 1
     end;
@@ -629,7 +629,7 @@ end;
 constructor TBufferedNetTcpIpClient.Create(AOwner: TComponent);
 begin
   inherited;
-  FLastReadTC := GetTickCount;
+  FLastReadTC := TPlatform.GetTickCount;
   FCritical := TPCCriticalSection.Create('TBufferedNetTcpIpClient_Critical');
   FSendBuffer := TMemoryStream.Create;
   FReadBuffer := TMemoryStream.Create;

+ 7 - 7
src/core/UThread.pas

@@ -349,9 +349,9 @@ end;
 {$IFDEF HIGHLOG}
 procedure TPCCriticalSection.Acquire;
 Var continue, logged : Boolean;
-  startTC : Cardinal;
+  startTC : TTickCount;
 begin
-  startTC := GetTickCount;
+  startTC := TPlatform.GetTickCount;
   FCounterLock.Acquire;
   try
     FWaitingForCounter := FWaitingForCounter + 1;
@@ -362,18 +362,18 @@ begin
   Repeat
     continue := inherited TryEnter;
     if (Not continue) then begin
-      If (not logged) And ((FStartedTimestamp>0) And ((FStartedTimestamp+1000)<GetTickCount)) then begin
+      If (not logged) And ((FStartedTimestamp>0) And ((FStartedTimestamp+1000)<TPlatform.GetTickCount)) then begin
         logged := true;
         TLog.NewLog(ltdebug,ClassName,'ALERT Critical section '+IntToHex(PtrInt(Self),8)+' '+Name+
           ' locked by '+IntToHex(FCurrentThread,8)+' waiting '+
-          IntToStr(FWaitingForCounter)+' elapsed milis: '+IntToStr(GetTickCount-FStartedTimestamp) );
+          IntToStr(FWaitingForCounter)+' elapsed milis: '+IntToStr(TPlatform.GetTickCount-FStartedTimestamp) );
         continue := true;
         inherited;
       end else sleep(1);
     end;
   Until continue;
   if (logged) then begin
-    TLog.NewLog(ltdebug,Classname,'ENTER Critical section '+IntToHex(PtrInt(Self),8)+' '+Name+' elapsed milis: '+IntToStr(GetTickCount - startTC) );
+    TLog.NewLog(ltdebug,Classname,'ENTER Critical section '+IntToHex(PtrInt(Self),8)+' '+Name+' elapsed milis: '+IntToStr(TPlatform.GetTickCount - startTC) );
   end;
   FCounterLock.Acquire;
   try
@@ -382,7 +382,7 @@ begin
     FCounterLock.Release;
   end;
   FCurrentThread := TThread.CurrentThread.ThreadID;
-  FStartedTimestamp := GetTickCount;
+  FStartedTimestamp := TPlatform.GetTickCount;
   inherited;
 end;
 {$ENDIF}
@@ -422,7 +422,7 @@ begin
   end;
   If inherited TryEnter then begin
     FCurrentThread := TThread.CurrentThread.ThreadID;
-    FStartedTimestamp := GetTickCount;
+    FStartedTimestamp := TPlatform.GetTickCount;
     Result := true;
   end else Result := false;
   FCounterLock.Acquire;