[fpc-pascal] How to get UTC time

2007-02-13 Thread Michel Meunier

Hello,

I work on a program wich need the UTC time, and this program will run 
with Windows and Linux.

So how is it possible to calculate the UTC time under these two OS.
For example, the Now function with Windows, give me local time.
Best regards

--
Michel Meunier

Web: www.etoiles-a-bleau.fr


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Question on how to avoid memory trouble

2007-02-13 Thread Florian Klaempfl
Vincent Snijders schrieb:
 Helmut Hartl schreef:
 
 http://www.research.ibm.com/people/m/michael/pldi-2004.pdf

 
 This one is not lock free, because it uses atomic instructions used by
 the cpu, which are essentially fine grained locks.

Exactly, and cmpxchg etc. are really expensive too. Since the original
FPC heap uses already several pools, it should be easily possible to
make it scale better in multi threaded applications.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


RE: [fpc-pascal] Question on how to avoid memory trouble

2007-02-13 Thread Helmut Hartl
   
   This one is not lock free, because it uses atomic 
  instructions used by 
   the cpu, which are essentially fine grained locks.
  
  Exactly, and cmpxchg etc. are really expensive too. Since 
  the original FPC heap uses already several pools, it should 
  be easily possible to make it scale better in multi threaded 
  applications.

Fine that sounds really nice - Do you already have a idea what
is not optimal and can be enhanced ?
Maybe I will find the time to give it a try 

helmut
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Question on how to avoid memory trouble

2007-02-13 Thread Jonas Maebe


On 13 feb 2007, at 13:12, Helmut Hartl wrote:


Exactly, and cmpxchg etc. are really expensive too. Since
the original FPC heap uses already several pools, it should
be easily possible to make it scale better in multi threaded
applications.


Fine that sounds really nice - Do you already have a idea what
is not optimal and can be enhanced ?


The default memory manager is always entirely locked, while  
differently sized blocks are allocated from different pools. So it  
should be possible to lock only one pool per allocation.  
Additionally, getting a block from a pool may even be possibly using  
a few atomic operations rather than by acquiring a lock.


See rtl/inc/heap.inc


Jonas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Florian Blog?

2007-02-13 Thread Florian Klaempfl
Tiziano_mk schrieb:
 
 
 Just looking on page: http://www.freepascal.org/aboutus.var
 
 I found that there is a link to Florian's blog:
 
 http://www.de.freepascal.org/~florian/nucleus/

http://www.florianklaempfl.de/nucleus

Not used much though.

 
 but I got the ususal error 404:
 
 
 any hint?
 
 tiziano
 ___
 fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
 http://lists.freepascal.org/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to get UTC time

2007-02-13 Thread Pete Cervasio
On Tuesday 13 February 2007 03:37, Michel Meunier wrote:

 I work on a program wich need the UTC time, and this program will run
 with Windows and Linux.
 So how is it possible to calculate the UTC time under these two OS.

Hello, Michel.

I do not program under Windows, so I cannot answer that part of the question, 
but getting the UTC time under Linux is quite easy.  I have written a utc_now 
function which I use under both Kylix and Free Pascal.  If you can find the 
answer for Windows, then it should be easy enough to combine the two into one 
function with an {$ifdef }.

There may be (and there probably are) better ways of doing it, but this works 
for me.  It needs both the SysUtils and Libc units, which I'm already using 
for other declarations anyway.

//
// Routine: utc_now
//
// Purpose: Returns the current UTC time as a TDateTime value.
//
function utc_now : TDateTime;
var
  timeval: TTimeVal;
  timezone: PTimeZone;
  a: Double;
begin
  TimeZone := nil;
  GetTimeOfDay (TimeVal, TimeZone);
  // Convert to milliseconds
  a := (TimeVal.tv_sec * 1000.0) + (TimeVal.tv_usec / 1000.0);
  Result := (a / MSecsPerDay) + UnixDateDelta;
end;

I hope this helps,
Pete C.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to get UTC time

2007-02-13 Thread Marco van de Voort
 for me.  It needs both the SysUtils and Libc units, which I'm already using 
 for other declarations anyway.

Libc is a legacy unit, better use the proper (portable) units, and you'll
spare yourself a libc dependancy, AND make it portable across unices:

{$mode Delphi}
uses unix,sysutils,baseunix;

 function utc_now : TDateTime;
 var
   timeval: TTimeVal;
   timezone: PTimeZone;
   a: Double;
 begin
   TimeZone := nil;
   fpGetTimeOfDay (@TimeVal, TimeZone);
   // Convert to milliseconds
   a := (TimeVal.tv_sec * 1000.0) + (TimeVal.tv_usec / 1000.0);
   Result := (a / MSecsPerDay) + UnixDateDelta;
 end;

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to get UTC time

2007-02-13 Thread Pete Cervasio
On Tuesday 13 February 2007 14:25, Marco van de Voort wrote:
  for me.  It needs both the SysUtils and Libc units, which I'm already
  using for other declarations anyway.

 Libc is a legacy unit, better use the proper (portable) units, and you'll
 spare yourself a libc dependancy, AND make it portable across unices:

However, to compile in Kylix as well (which I believe my post stated I need) 
then there would have to be a bunch of ifdefs spread around since the 'unix' 
and 'baseunix' units don't exist there (and consequently, there is no 
fpGetTimeOfDay function).  Also, since the original questioner wanted it to 
work under Windows, there would be even more ifdefs.  It makes me glad that  
I only have to deal with Kylix and FPC under Linux.  :)

To answer that how to do this under Windows part of the original question, 
it looks like it's just as easy.  The GetSystemTime API routine returns the 
current date and time in UTC form.  There's a function in SysUtils to convert 
the TSystemTime into a TDateTime, so the following should work.  I only 
tested it in Delphi 5 under Wine, because that's all I have on this system 
for such things:

{$ifdef MSWINDOWS}
{ This uses SysUtils and Windows. }
function emt_now: TDateTime;
var
  st: TSystemTime;
begin
  GetSystemTime (st);
  Result := SystemTimeToDateTime (st);
end;
{$endif}

Adding this to the previous bit of code, and properly supporting compilation 
with FPC under *nix and Windows, as well as Delphi and Kylix, is left as an 
exercise for the interested reader.  ;-)

Best regards,
Pete C.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal