Use VFS method xCurrentTimeInt64 instead of xCurrentTime when it is available.

Provide an implementation of xCurrentTimeInt64 for os_unix.c.

FossilOrigin-Name: ab77b3ae6da3370d8bc3b2c9c0edc723b69f5a95
This commit is contained in:
drh
2010-05-03 14:32:30 +00:00
parent e8e1c9d50e
commit b7e8ea2015
9 changed files with 75 additions and 69 deletions
+4 -13
View File
@@ -314,10 +314,8 @@ static int parseYyyyMmDd(const char *zDate, DateTime *p){
** Set the time to the current time reported by the VFS
*/
static void setDateTimeToCurrent(sqlite3_context *context, DateTime *p){
double r;
sqlite3 *db = sqlite3_context_db_handle(context);
sqlite3OsCurrentTime(db->pVfs, &r);
p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);
sqlite3OsCurrentTimeInt64(db->pVfs, &p->iJD);
p->validJD = 1;
}
@@ -1038,22 +1036,15 @@ static void currentTimeFunc(
time_t t;
char *zFormat = (char *)sqlite3_user_data(context);
sqlite3 *db;
double rT;
sqlite3_int64 iT;
char zBuf[20];
UNUSED_PARAMETER(argc);
UNUSED_PARAMETER(argv);
db = sqlite3_context_db_handle(context);
sqlite3OsCurrentTime(db->pVfs, &rT);
#ifndef SQLITE_OMIT_FLOATING_POINT
t = 86400.0*(rT - 2440587.5) + 0.5;
#else
/* without floating point support, rT will have
** already lost fractional day precision.
*/
t = 86400 * (rT - 2440587) - 43200;
#endif
sqlite3OsCurrentTimeInt64(db->pVfs, &iT);
t = (iT - 100*(sqlite3_int64)244058755)/1000;
#ifdef HAVE_GMTIME_R
{
struct tm sNow;
+10 -2
View File
@@ -161,8 +161,16 @@ int sqlite3OsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
int sqlite3OsSleep(sqlite3_vfs *pVfs, int nMicro){
return pVfs->xSleep(pVfs, nMicro);
}
int sqlite3OsCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
return pVfs->xCurrentTime(pVfs, pTimeOut);
int sqlite3OsCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *pTimeOut){
int rc;
if( pVfs->iVersion>=2 && pVfs->xCurrentTimeInt64 ){
rc = pVfs->xCurrentTimeInt64(pVfs, pTimeOut);
}else{
double r;
rc = pVfs->xCurrentTime(pVfs, &r);
*pTimeOut = (sqlite3_int64)(r*86400000.0);
}
return rc;
}
int sqlite3OsOpenMalloc(
+1 -1
View File
@@ -259,7 +259,7 @@ void sqlite3OsDlClose(sqlite3_vfs *, void *);
#endif /* SQLITE_OMIT_LOAD_EXTENSION */
int sqlite3OsRandomness(sqlite3_vfs *, int, char *);
int sqlite3OsSleep(sqlite3_vfs *, int);
int sqlite3OsCurrentTime(sqlite3_vfs *, double*);
int sqlite3OsCurrentTimeInt64(sqlite3_vfs *, sqlite3_int64*);
/*
** Convenience functions for opening and closing files using
+38 -25
View File
@@ -4515,36 +4515,49 @@ static int unixSleep(sqlite3_vfs *NotUsed, int microseconds){
int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */
#endif
/*
** Find the current time (in Universal Coordinated Time). Write into *piNow
** the current time and date as a Julian Day number times 86_400_000. In
** other words, write into *piNow the number of milliseconds since the Julian
** epoch of noon in Greenwich on November 24, 4714 B.C according to the
** proleptic Gregorian calendar.
**
** On success, return 0. Return 1 if the time and date cannot be found.
*/
static int unixCurrentTimeInt64(sqlite3_vfs *NotUsed, sqlite3_int64 *piNow){
static const sqlite3_int64 unixEpoch = 24405875*(sqlite3_int64)8640000;
#if defined(NO_GETTOD)
time_t t;
time(&t);
*piNow = ((sqlite3_int64)i)*1000 + unixEpoch;
#elif OS_VXWORKS
struct timespec sNow;
clock_gettime(CLOCK_REALTIME, &sNow);
*piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_nsec/1000000;
#else
struct timeval sNow;
gettimeofday(&sNow, 0);
*piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_usec/1000;
#endif
#ifdef SQLITE_TEST
if( sqlite3_current_time ){
*piNow = 1000*(sqlite3_int64)sqlite3_current_time + unixEpoch;
}
#endif
UNUSED_PARAMETER(NotUsed);
return 0;
}
/*
** Find the current time (in Universal Coordinated Time). Write the
** current time and date as a Julian Day number into *prNow and
** return 0. Return 1 if the time and date cannot be found.
*/
static int unixCurrentTime(sqlite3_vfs *NotUsed, double *prNow){
#if defined(SQLITE_OMIT_FLOATING_POINT)
time_t t;
time(&t);
*prNow = (((sqlite3_int64)t)/8640 + 24405875)/10;
#elif defined(NO_GETTOD)
time_t t;
time(&t);
*prNow = t/86400.0 + 2440587.5;
#elif OS_VXWORKS
struct timespec sNow;
clock_gettime(CLOCK_REALTIME, &sNow);
*prNow = 2440587.5 + sNow.tv_sec/86400.0 + sNow.tv_nsec/86400000000000.0;
#else
struct timeval sNow;
gettimeofday(&sNow, 0);
*prNow = 2440587.5 + sNow.tv_sec/86400.0 + sNow.tv_usec/86400000000.0;
#endif
#ifdef SQLITE_TEST
if( sqlite3_current_time ){
*prNow = sqlite3_current_time/86400.0 + 2440587.5;
}
#endif
UNUSED_PARAMETER(NotUsed);
sqlite3_int64 i;
unixCurrentTimeInt64(0, &i);
*prNow = i*86400000.0;
return 0;
}
@@ -6601,7 +6614,7 @@ int sqlite3_os_init(void){
unixShmLock, /* xShmLock */ \
unixShmClose, /* xShmClose */ \
0, /* xRename */ \
0, /* xCurrentTimeInt64 */ \
unixCurrentTimeInt64, /* xCurrentTimeInt64 */ \
}
/*
+1 -1
View File
@@ -346,7 +346,7 @@ static int devsymSleep(sqlite3_vfs *pVfs, int nMicro){
** Return the current time as a Julian Day number in *pTimeOut.
*/
static int devsymCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
return sqlite3OsCurrentTime(g.pVfs, pTimeOut);
return g.pVfs->xCurrentTime(g.pVfs, pTimeOut);
}
+1 -1
View File
@@ -801,7 +801,7 @@ static int jtSleep(sqlite3_vfs *pVfs, int nMicro){
** Return the current time as a Julian Day number in *pTimeOut.
*/
static int jtCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
return sqlite3OsCurrentTime(g.pVfs, pTimeOut);
return g.pVfs->xCurrentTime(g.pVfs, pTimeOut);
}
/**************************************************************************
+4 -10
View File
@@ -377,9 +377,7 @@ static int sqlite3Step(Vdbe *p){
#ifndef SQLITE_OMIT_TRACE
if( db->xProfile && !db->init.busy ){
double rNow;
sqlite3OsCurrentTime(db->pVfs, &rNow);
p->startTime = (u64)((rNow - (int)rNow)*3600.0*24.0*1000000000.0);
sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
}
#endif
@@ -400,13 +398,9 @@ static int sqlite3Step(Vdbe *p){
/* Invoke the profile callback if there is one
*/
if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy && p->zSql ){
double rNow;
u64 elapseTime;
sqlite3OsCurrentTime(db->pVfs, &rNow);
elapseTime = (u64)((rNow - (int)rNow)*3600.0*24.0*1000000000.0);
elapseTime -= p->startTime;
db->xProfile(db->pProfileArg, p->zSql, elapseTime);
sqlite3_int64 iNow;
sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
db->xProfile(db->pProfileArg, p->zSql, iNow - p->startTime);
}
#endif