Ignore:
Timestamp:
Jan 28, 2011, 2:12:42 PM (14 years ago)
Author:
george
Message:
  • Modified: Restructuralized code for support for pending state changes.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • MicroThreading/UPlatform.pas

    r149 r156  
    88  {$IFDEF Windows}Windows,{$ENDIF}
    99  {$IFDEF Linux}BaseUnix, UnixUtil, Unix,{$ENDIF}
    10   Classes, SysUtils, DateUtils;
     10  Classes, SysUtils, DateUtils, SyncObjs;
    1111
    1212function NowPrecise: TDateTime;
     
    2020{$ENDIF}
    2121
     22var
     23  NowPreciseLock: TCriticalSection;
    2224
    2325function NowPrecise: TDateTime;
     
    2628  {$IFDEF Windows}TimerValue: Int64;{$ENDIF}
    2729begin
    28   {$IFDEF Windows}
    29   QueryPerformanceCounter(TimerValue);
    30   //Result := Int64(TimeStampToMSecs(DateTimeToTimeStamp(Now)) * 1000) // an alternative Win32 timebase
    31   Result := TimerValue / PerformanceFrequency;
    32   {$ENDIF}
     30  try
     31    NowPreciseLock.Acquire;
     32    {$IFDEF Windows}
     33    QueryPerformanceCounter(TimerValue);
     34    //Result := Int64(TimeStampToMSecs(DateTimeToTimeStamp(Now)) * 1000) // an alternative Win32 timebase
     35    Result := TimerValue / PerformanceFrequency;
     36    {$ENDIF}
    3337
    34   {$IFDEF Linux}
    35   fpgettimeofday(@t, nil);
    36    // Build a 64 bit microsecond tick from the seconds and microsecond longints
    37   Result := t.tv_sec + t.tv_usec / 1000000;
    38   {$ENDIF}
     38    {$IFDEF Linux}
     39    fpgettimeofday(@t, nil);
     40     // Build a 64 bit microsecond tick from the seconds and microsecond longints
     41    Result := t.tv_sec + t.tv_usec / 1000000;
     42    {$ENDIF}
    3943
    40   Result := (Trunc(Now / OneSecond) + Frac(Result)) * OneSecond;
     44    Result := (Trunc(Now / OneSecond) + Frac(Result)) * OneSecond;
     45  finally
     46    NowPreciseLock.Release;
     47  end;
    4148end;
    4249
     
    5865QueryPerformanceFrequency(PerformanceFrequency);
    5966{$ENDIF}
     67NowPreciseLock := TCriticalSection.Create;
     68
     69finalization
     70
     71NowPreciseLock.Free;
    6072
    6173end.
Note: See TracChangeset for help on using the changeset viewer.