UnixOperatingSystem.st
changeset 22841 63cdbb2f19b2
parent 22829 f8f21ccd46d5
child 22968 411d41553689
equal deleted inserted replaced
22840:7069c0491453 22841:63cdbb2f19b2
 10216     struct timespec ts;
 10216     struct timespec ts;
 10217     static int has_clock_gettime = 1;
 10217     static int has_clock_gettime = 1;
 10218     unsigned long _secs, _millis, _nanos;
 10218     unsigned long _secs, _millis, _nanos;
 10219 
 10219 
 10220     if (has_clock_gettime) {
 10220     if (has_clock_gettime) {
 10221 	if (clock_gettime(CLOCK_REALTIME, &ts) != -1) {
 10221         if (clock_gettime(CLOCK_REALTIME, &ts) != -1) {
 10222 	    _secs = ts.tv_sec;
 10222             _secs = ts.tv_sec;
 10223 	    _millis = ts.tv_nsec / 1000000;
 10223             _millis = ts.tv_nsec / 1000000;
 10224 	    _nanos = ts.tv_nsec % 1000000;
 10224             _nanos = ts.tv_nsec % 1000000;
 10225 
 10225 
 10226 	    seconds = __MKUINT(_secs);
 10226             seconds = __MKUINT(_secs);
 10227 	    millis = __MKUINT(_millis);
 10227             millis = __MKUINT(_millis);
 10228 	    nanos = __MKUINT(_nanos);
 10228             nanos = __MKUINT(_nanos);
 10229 	} else {
 10229         } else {
 10230 	    /*
 10230             /*
 10231 	     * clock_gettime is not implemented in the kernel
 10231              * clock_gettime is not implemented in the kernel
 10232 	     * fall through to alternative implementation
 10232              * fall through to alternative implementation
 10233 	     */
 10233              */
 10234 	    has_clock_gettime = 0;
 10234             has_clock_gettime = 0;
 10235 	}
 10235         }
 10236     }
 10236     }
 10237 # endif
 10237 # endif
 10238 %}.
 10238 %}.
 10239     seconds notNil ifTrue:[
 10239     seconds notNil ifTrue:[
 10240 	^ { ((seconds * 1000) + millis) . nanos }
 10240         ^ { ((seconds * 1000) + millis) . nanos }
 10241     ].
 10241     ].
 10242     ^ super getOSTimeInNanos
 10242     ^ super getOSTimeWithNanos
 10243 
 10243 
 10244     "
 10244     "
 10245      OperatingSystem getOSTimeInNanos printCR.
 10245      OperatingSystem getOSTimeWithNanos printCR.
 10246      Delay waitForSeconds:0.1.
 10246      Delay waitForSeconds:0.1.
 10247      OperatingSystem getOSTimeInNanos printCR.
 10247      OperatingSystem getOSTimeWithNanos printCR.
 10248     "
 10248     "
       
 10249 
       
 10250     "Modified: / 09-05-2018 / 17:25:31 / stefan"
 10249 !
 10251 !
 10250 
 10252 
 10251 getRealNanosecondTime
 10253 getRealNanosecondTime
 10252     "This returns the microsecond timers value - if available.
 10254     "This returns the microsecond timers value - if available.
 10253      On some machines, times with this precision may not be available,
 10255      On some machines, times with this precision may not be available,