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
 implementation
 
 
-Uses ULog, Variants, UTime, UNetProtocol;
+Uses ULog, Variants, UTime, UNetProtocol, UBaseTypes;
 
 
 Type TPendingResponseMessage = Record
 Type TPendingResponseMessage = Record
        sendDateTime : TDateTime;
        sendDateTime : TDateTime;
@@ -222,7 +222,7 @@ end;
 function TJSONRPCTcpIpClient.DoProcessBuffer(SenderThread : TPCThread; MaxWaitMiliseconds : Cardinal; DeleteBufferOnExit : Boolean; var ResponseMethod : String; var jsonObject : TPCJSONObject) : Boolean;
 function TJSONRPCTcpIpClient.DoProcessBuffer(SenderThread : TPCThread; MaxWaitMiliseconds : Cardinal; DeleteBufferOnExit : Boolean; var ResponseMethod : String; var jsonObject : TPCJSONObject) : Boolean;
 var last_bytes_read : Integer;
 var last_bytes_read : Integer;
   jsonData : TPCJSONData;
   jsonData : TPCJSONData;
-  tc : Cardinal;
+  tc : TTickCount;
   ms : TMemoryStream;
   ms : TMemoryStream;
   i,lasti : Integer;
   i,lasti : Integer;
   continue : Boolean;
   continue : Boolean;
@@ -286,15 +286,15 @@ var islocked : Boolean;
 begin
 begin
   Result := false;
   Result := false;
   ResponseMethod := '';
   ResponseMethod := '';
-  tc := GetTickCount;
+  tc := TPlatform.GetTickCount;
   Repeat
   Repeat
     islocked := FLockProcessBuffer.TryEnter;
     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;
   If Not islocked then exit;
   try
   try
     if Assigned(SenderThread) then continue := Not SenderThread.Terminated
     if Assigned(SenderThread) then continue := Not SenderThread.Terminated
     else continue := true;
     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;
       last_bytes_read := 0;
       ms := ReadBufferLock;
       ms := ReadBufferLock;
       try
       try
@@ -432,7 +432,8 @@ end;
 
 
 function TJSONRPCTcpIpClient.SendJSONRPCMethodAndWait(const method: String; params: TPCJSONList; MaxWaitMiliseconds: Cardinal; resultObject : TPCJSONObject; processEventOnInvalid : TProcessJSONObjectEvent = Nil) : Boolean;
 function TJSONRPCTcpIpClient.SendJSONRPCMethodAndWait(const method: String; params: TPCJSONList; MaxWaitMiliseconds: Cardinal; resultObject : TPCJSONObject; processEventOnInvalid : TProcessJSONObjectEvent = Nil) : Boolean;
 Var nId : Cardinal;
 Var nId : Cardinal;
-  tc,maxw : Cardinal;
+  tc : TTickCount;
+  maxw : Cardinal;
   json : TPCJSONObject;
   json : TPCJSONObject;
   rm : String;
   rm : String;
 begin
 begin
@@ -441,11 +442,11 @@ begin
   try
   try
     nId := GetNewId;
     nId := GetNewId;
     SendJSONRPCMethod(method,params,nId);
     SendJSONRPCMethod(method,params,nId);
-    tc := GetTickCount;
+    tc := TPlatform.GetTickCount;
     json := TPCJSONObject.Create;
     json := TPCJSONObject.Create;
     Try
     Try
       repeat
       repeat
-        maxw := MaxWaitMiliseconds - (GetTickCount - tc);
+        maxw := MaxWaitMiliseconds - (TPlatform.GetTickCount - tc);
         if maxw<1 then maxw := 1
         if maxw<1 then maxw := 1
         else if maxw>10000 then maxw := 10000;
         else if maxw>10000 then maxw := 10000;
         If DoProcessBuffer(nil,maxw,true,rm,json) then begin
         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 else TLog.NewLog(lterror,Classname,'Lost JSON message! '+json.ToJSON(false));
           end;
           end;
         end;
         end;
-      until (Result) Or (GetTickCount > (tc+MaxWaitMiliseconds));
+      until (Result) Or (TPlatform.GetTickCount > (tc+MaxWaitMiliseconds));
     finally
     finally
       json.free;
       json.free;
     end;
     end;
@@ -877,7 +878,7 @@ begin
     inc(FIncomingsCounter);
     inc(FIncomingsCounter);
     SendJobToMiner(nil,bClient,false,null);
     SendJobToMiner(nil,bClient,false,null);
     while (Active) And (Client.Connected) do begin
     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;
       jsonobj := TPCJSONObject.Create;
       try
       try
         if bClient.DoProcessBuffer(nil,1000,doDelete,rmethod,jsonobj) then begin
         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,
 Uses UThread, ULog, UConst, UNode, UAccounts, UCrypto, UBlockChain,
   UNetProtocol, UOpTransaction, UWallet, UTime, UAES, UECIES, UTxMultiOperation,
   UNetProtocol, UOpTransaction, UWallet, UTime, UAES, UECIES, UTxMultiOperation,
-  UJSONFunctions, classes, blcksock, synsock, IniFiles, Variants, math;
+  UJSONFunctions, classes, blcksock, synsock, IniFiles, Variants, math, UBaseTypes;
 
 
 Const
 Const
   CT_RPC_ErrNum_InternalError = 100;
   CT_RPC_ErrNum_InternalError = 100;
@@ -511,11 +511,11 @@ var
   valid : Boolean;
   valid : Boolean;
   i : Integer;
   i : Integer;
   Headers : TStringList;
   Headers : TStringList;
-  tc : Cardinal;
+  tc : TTickCount;
   callcounter : Int64;
   callcounter : Int64;
 begin
 begin
   callcounter := _RPCServer.GetNewCallCounter;
   callcounter := _RPCServer.GetNewCallCounter;
-  tc := GetTickCount;
+  tc := TPlatform.GetTickCount;
   methodName := '';
   methodName := '';
   paramsTxt := '';
   paramsTxt := '';
   // IP Protection
   // IP Protection
@@ -647,7 +647,7 @@ begin
           FSock.SendBuffer(addr(jsonresponsetxt[1]),Length(jsonresponsetxt));
           FSock.SendBuffer(addr(jsonresponsetxt[1]),Length(jsonresponsetxt));
         end;
         end;
       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
     finally
       jsonresponse.free;
       jsonresponse.free;
       Headers.Free;
       Headers.Free;

+ 6 - 6
src/core/UTCPIP.pas

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

+ 7 - 7
src/core/UThread.pas

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