pike.git
/
src
/
builtin.cmod
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/builtin.cmod:3216:
*! last whole second, respectively. (See also @[predef::time()]) *! *! @note *! Please note that these variables will continually update when *! they are requested, there is no need to create new Time() *! objects. */ PIKEFUN int `sec() {
-
extern
struct timeval
current_time
;
+
struct timeval
now
;
if( THIS->hard_update )
-
GETTIMEOFDAY( &
current
_
time
);
+
ACCURATE_
GETTIMEOFDAY( &
now );
+
else
+
INACCURATE
_
GETTIMEOFDAY(
&now
);
-
RETURN
current_time
.tv_sec;
+
RETURN
now
.tv_sec;
} PIKEFUN int `usec() {
-
extern
struct timeval
current_time
;
+
struct timeval
now
;
if( THIS->hard_update )
-
GETTIMEOFDAY( &
current
_
time
);
+
ACCURATE_
GETTIMEOFDAY( &
now );
+
else
+
INACCURATE
_
GETTIMEOFDAY(
&now
);
-
RETURN
current_time
.tv_usec;
+
RETURN
now
.tv_usec;
} /*! @decl int usec_full *! *! The number of microseconds since the epoch. Please note that *! pike needs to have been compiled with bignum support for this *! variable to contain sensible values. */ PIKEFUN int `usec_full() {
-
extern
struct timeval
current_time
;
+
struct timeval
now
;
if( THIS->hard_update )
-
GETTIMEOFDAY( &
current
_
time
);
+
ACCURATE_
GETTIMEOFDAY( &
now );
+
else
+
INACCURATE
_
GETTIMEOFDAY(
&now
);
#ifdef AUTO_BIGNUM
-
push_int(
current_time
.tv_sec );
+
push_int(
now
.tv_sec );
push_int( 1000000 ); f_multiply( 2 );
-
push_int(
current_time
.tv_usec );
+
push_int(
now
.tv_usec );
f_add( 2 ); return; #else
-
RETURN (
current_time
.tv_sec * 1000000 +
current_time
.tv_usec);
+
RETURN (
now
.tv_sec * 1000000 +
now
.tv_usec);
#endif } /*! @decl protected void create( int fast ); *! *! If @[fast] is true, do not request a new time from the system, *! instead use the global current time variable. *! *! This will only work in callbacks, but can save significant amounts *! of CPU.
pike.git/src/builtin.cmod:3290:
PIKECLASS Timer { CVAR struct timeval last_time; CVAR int hard_update; /*! @decl float peek() *! Return the time in seconds since the last time @[get] was called. */ PIKEFUN float peek( ) {
-
extern
struct timeval
current_time
;
+
struct timeval
now
;
FLOAT_TYPE res; if( THIS->hard_update )
-
GETTIMEOFDAY( &
current
_
time
);
-
res =
current_time
.tv_sec-THIS->last_time.tv_sec +
-
(
current_time
.tv_usec-THIS->last_time.tv_usec)/(FLOAT_TYPE) 1000000.0;
+
ACCURATE_
GETTIMEOFDAY( &
now );
+
else
+
INACCURATE
_
GETTIMEOFDAY(
&now
);
+
res =
now
.tv_sec-THIS->last_time.tv_sec +
+
(
now
.tv_usec-THIS->last_time.tv_usec)/(FLOAT_TYPE) 1000000.0;
RETURN res; } /*! @decl float get() *! Return the time in seconds since the last time get was called. *! The first time this method is called the time since the object *! was created is returned instead. */ PIKEFUN float get( ) {
-
extern struct timeval current_time;
+
f_Timer_peek( 0 );
-
THIS->last_time
= current_time
;
+
INACCURATE_GETTIMEOFDAY(&
THIS->last_time
)
;
return; } /*! @decl protected void create( int|void fast ) *! Create a new timer object. The timer keeps track of relative time *! with sub-second precision. *! *! If @[fast] is specified, the timer will not do system calls to get *! the current time but instead use the one maintained by pike. This *! will result in faster but more or less inexact timekeeping. *! The pike maintained time is only updated when a @[Pike.Backend] *! object stops waiting and starts executing code. */ PIKEFUN void create( int|zero|void fast ) flags ID_PROTECTED; {
-
extern struct timeval current_time;
+
THIS->hard_update = !fast; if( THIS->hard_update )
-
GETTIMEOFDAY( &
current
_time );
-
THIS->last_time
= current_time
;
+
ACCURATE_
GETTIMEOFDAY( &
THIS->last
_time );
+
else
+
INACCURATE_GETTIMEOFDAY( &
THIS->last_time
)
;
} } /*! @endclass */ /*! @endmodule */