TimeStamp Class

John M McIntosh johnmci at smalltalkconsulting.com
Mon Apr 11 04:55:05 UTC 2005


Well most modern CPU have counters tied to Ghz/Mhz cycles so that you  
can calculate a nano-second time value if you know the multiplers  
values to use,
some operating systems actually provide calls to get that information.

See
http://developer.apple.com/qa/qa2004/qa1398.html

This means of course returning a 64bit value small integer to large  
positive integers to the caller, exactly how many milliseconds are  
there from 1900 (or what the epoc is) ? Does that include leap-seconds  
too? Sounds like a nice plugin project, or via FFI, or for most VM's  
another primitive call.

Current the mac os-x uses time  gettimeofDay (and I think all Unix  
based VMs)  for the millisecond prim call, carefull reading shows we  
*could* return microseconds (if supported).

/*	Return the value of the millisecond clock as an integer. Note that  
the millisecond clock wraps around periodically.
On some platforms it can wrap daily. The range is limited to  
SmallInteger maxVal / 2 to allow delays of up to that length without  
overflowing a SmallInteger. */

int primitiveMillisecondClock(void) {
register struct foo * foo = &fum;
     int oop;
     int sp;

	/* begin pop:thenPush: */
	oop = ((((ioMSecs()) & MillisecondClockMask) << 1) | 1);
	longAtput(sp = foo->stackPointer - ((1 - 1) * 4), oop);
	foo->stackPointer = sp;
}

int ioMicroMSecs(void)
{
   struct timeval now;
   gettimeofday(&now, 0);
   if ((now.tv_usec-= startUpTime.tv_usec) < 0) {
     now.tv_usec+= 1000000;
     now.tv_sec-= 1;
   }
   now.tv_sec-= startUpTime.tv_sec;
   return (now.tv_usec / 1000 + now.tv_sec * 1000);
}


see man
gettimeofday()
The system's notion of the current Greenwich time and the current time
      zone is obtained with the gettimeofday() call, and set with the
      settimeofday() call.  The time is expressed in seconds and  
microseconds
      since midnight (0 hour), January 1, 1970.  The resolution of the  
system
      clock is hardware dependent, and the time may be updated  
continuously or
      in ``ticks.''  If tp or tzp is NULL, the associated time  
information will
      not be returned or set.

      The structures pointed to by tp and tzp are defined in  
<sys/time.h> as:

      struct timeval {
              long    tv_sec;         /* seconds since Jan. 1, 1970 */
              long    tv_usec;        /* and microseconds */
      };

      struct timezone {
              int     tz_minuteswest; /* of Greenwich */
              int     tz_dsttime;     /* type of dst correction to apply  
*/
      };

      The timezone structure indicates the local time zone (measured in  
minutes
      of time westward from Greenwich), and a flag that, if nonzero,  
indicates
      that Daylight Saving time applies locally during the appropriate  
part of
      the year.


On Apr 10, 2005, at 6:13 PM, Chris Muller wrote:

>
> VisualAge says its millisecondClock is "guaranteed" to never roll.  If  
> this is
> true, does anyone know how they achieved this?  It would be nice to  
> have
> reliable millisecond support in Squeak even in year-long-running  
> Squeak images.
>
>
--
======================================================================== 
===
John M. McIntosh <johnmci at smalltalkconsulting.com> 1-800-477-2659
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
======================================================================== 
===




More information about the Squeak-dev mailing list