1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

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

View File

@@ -1,8 +1,8 @@
-----BEGIN PGP SIGNED MESSAGE----- -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1 Hash: SHA1
C Merge\sthe\swrite-ahead-logging\schanges\sinto\sthe\strunk. C Use\sVFS\smethod\sxCurrentTimeInt64\sinstead\sof\sxCurrentTime\swhen\sit\sis\savailable.\nProvide\san\simplementation\sof\sxCurrentTimeInt64\sfor\sos_unix.c.
D 2010-05-03T14:08:28 D 2010-05-03T14:32:30
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in d83a0ffef3dcbfb08b410a6c6dd6c009ec9167fb F Makefile.in d83a0ffef3dcbfb08b410a6c6dd6c009ec9167fb
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -119,7 +119,7 @@ F src/build.c 11100b66fb97638d2d874c1d34d8db90650bb1d7
F src/callback.c 01843bdf4b0420fd28046525d150fcd9802931a9 F src/callback.c 01843bdf4b0420fd28046525d150fcd9802931a9
F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
F src/ctime.c 51553a859994d01d8bf3500747f66a890c459774 F src/ctime.c 51553a859994d01d8bf3500747f66a890c459774
F src/date.c 485a4409a384310e6d93fd1104a9d0a8658becd9 F src/date.c 8a389e9529418b6333190a418034e2e8723a2fac
F src/delete.c 610dc008e88a9599f905f5cbe9577ac9c36e0581 F src/delete.c 610dc008e88a9599f905f5cbe9577ac9c36e0581
F src/expr.c 286f62b24217ade1c14ba56de413ffdd607b6a41 F src/expr.c 286f62b24217ade1c14ba56de413ffdd607b6a41
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
@@ -149,11 +149,11 @@ F src/mutex_os2.c 20477db50cf3817c2f1cd3eb61e5c177e50231db
F src/mutex_unix.c 04a25238abce7e3d06b358dcf706e26624270809 F src/mutex_unix.c 04a25238abce7e3d06b358dcf706e26624270809
F src/mutex_w32.c 4cc201c1bfd11d1562810554ff5500e735559d7e F src/mutex_w32.c 4cc201c1bfd11d1562810554ff5500e735559d7e
F src/notify.c cbfa66a836da3a51567209636e6a94059c137930 F src/notify.c cbfa66a836da3a51567209636e6a94059c137930
F src/os.c 8bc63cf91e9802e2b807198e54e50227fa889306 F src/os.c aec6922553585a25d5655666defc125a7e217674
F src/os.h 534b082c3cb349ad05fa6fa0b06087e022af282c F src/os.h b389844e5469a2918e8a45fe6ae52b4c28dfb2b2
F src/os_common.h 0d6ee583b6ee3185eb9d951f890c6dd03021a08d F src/os_common.h 0d6ee583b6ee3185eb9d951f890c6dd03021a08d
F src/os_os2.c 8ad77a418630d7dee91d1bb04f79c2096301d3a0 F src/os_os2.c 8ad77a418630d7dee91d1bb04f79c2096301d3a0
F src/os_unix.c 5c821e4eb04093102d901c22f40341bc1d30aef0 F src/os_unix.c f3c0faad1c6de4f06f5ec30d586a4e62a980dc6f
F src/os_win.c a8fc01d8483be472e495793c01064fd87e56a5c1 F src/os_win.c a8fc01d8483be472e495793c01064fd87e56a5c1
F src/pager.c e9c7fe979b32a3c5bf4216d8fbe1cf8beff8a1b8 F src/pager.c e9c7fe979b32a3c5bf4216d8fbe1cf8beff8a1b8
F src/pager.h 934b598583a9d936bb13c37d62a2fe68ac48781c F src/pager.h 934b598583a9d936bb13c37d62a2fe68ac48781c
@@ -191,13 +191,13 @@ F src/test_backup.c c129c91127e9b46e335715ae2e75756e25ba27de
F src/test_btree.c 47cd771250f09cdc6e12dda5bc71bc0b3abc96e2 F src/test_btree.c 47cd771250f09cdc6e12dda5bc71bc0b3abc96e2
F src/test_config.c 6210f501d358bde619ae761f06f123529c6ba24f F src/test_config.c 6210f501d358bde619ae761f06f123529c6ba24f
F src/test_demovfs.c da81a5f7785bb352bda7911c332a983ec4f17f27 F src/test_demovfs.c da81a5f7785bb352bda7911c332a983ec4f17f27
F src/test_devsym.c 3d324248b80f31b3b29ab9bca39c4d856a2c9160 F src/test_devsym.c 2160798b2dbd7bfa6225a70c31283ef9a097660a
F src/test_func.c 13b582345fb1185a93e46c53310fae8547dcce20 F src/test_func.c 13b582345fb1185a93e46c53310fae8547dcce20
F src/test_hexio.c 1237f000ec7a491009b1233f5c626ea71bce1ea2 F src/test_hexio.c 1237f000ec7a491009b1233f5c626ea71bce1ea2
F src/test_init.c 5d624ffd0409d424cf9adbfe1f056b200270077c F src/test_init.c 5d624ffd0409d424cf9adbfe1f056b200270077c
F src/test_intarray.c d879bbf8e4ce085ab966d1f3c896a7c8b4f5fc99 F src/test_intarray.c d879bbf8e4ce085ab966d1f3c896a7c8b4f5fc99
F src/test_intarray.h 489edb9068bb926583445cb02589344961054207 F src/test_intarray.h 489edb9068bb926583445cb02589344961054207
F src/test_journal.c 0537fcf9d4ecb394ec8b27d887a004ecaab85f16 F src/test_journal.c 51da4dd6118ee843349592fde29429fab84a6243
F src/test_loadext.c df586c27176e3c2cb2e099c78da67bf14379a56e F src/test_loadext.c df586c27176e3c2cb2e099c78da67bf14379a56e
F src/test_malloc.c 2842c922b8e8d992aba722214952204ca025b411 F src/test_malloc.c 2842c922b8e8d992aba722214952204ca025b411
F src/test_mutex.c ce06b59aca168cd8c520b77159a24352a7469bd3 F src/test_mutex.c ce06b59aca168cd8c520b77159a24352a7469bd3
@@ -218,7 +218,7 @@ F src/vacuum.c 8e7d9a6fd076774bb6e211cad335c7337948a164
F src/vdbe.c 8be37a1b18786b5c026adcb2e9edc93e3a940885 F src/vdbe.c 8be37a1b18786b5c026adcb2e9edc93e3a940885
F src/vdbe.h 471f6a3dcec4817ca33596fe7f6654d56c0e75f3 F src/vdbe.h 471f6a3dcec4817ca33596fe7f6654d56c0e75f3
F src/vdbeInt.h 19ebc8c2a2e938340051ee65af3f377fb99102d1 F src/vdbeInt.h 19ebc8c2a2e938340051ee65af3f377fb99102d1
F src/vdbeapi.c cf1ff7cbcbd44d2082af71b98762407ae01ce009 F src/vdbeapi.c f2da22e5dcb1943ce6605614636e6bf32158640d
F src/vdbeaux.c 395d21a1617553ea9b9f4abe0d302449d8549e1d F src/vdbeaux.c 395d21a1617553ea9b9f4abe0d302449d8549e1d
F src/vdbeblob.c 5327132a42a91e8b7acfb60b9d2c3b1c5c863e0e F src/vdbeblob.c 5327132a42a91e8b7acfb60b9d2c3b1c5c863e0e
F src/vdbemem.c 2a82f455f6ca6f78b59fb312f96054c04ae0ead1 F src/vdbemem.c 2a82f455f6ca6f78b59fb312f96054c04ae0ead1
@@ -811,14 +811,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P 946e06cd2a2cc209b0786b7e9d28c0746320d646 27a5c09ce8a35039d844d08cfe5698e8b438abfe P de9ae443cc8eebfb0692dcdac93bde9e4c54199a
R 496e930fc5a775a552ace6c40959352e R e2427a6bed16c13592f9c9205631cbf2
U drh U drh
Z 6de75408ba1e125bd7e7fd0306efd7dd Z 44856fc90c606c86cc9a47a6ae746757
-----BEGIN PGP SIGNATURE----- -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux) Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFL3tjgoxKgR168RlERAn8zAJ4myOF3FCYW6KNideNeI9JIkyQm6ACfbPiT iD8DBQFL3t6BoxKgR168RlERAmG1AJ9O0XG5Km2CNUBGaWq0PnJbrMhSsgCeJiI9
qZo9Et3fACK9ap0KUhaVVwE= DrNwLLIIqnopSV7zMILP0LA=
=UJ+t =3EtO
-----END PGP SIGNATURE----- -----END PGP SIGNATURE-----

View File

@@ -1 +1 @@
de9ae443cc8eebfb0692dcdac93bde9e4c54199a ab77b3ae6da3370d8bc3b2c9c0edc723b69f5a95

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 ** Set the time to the current time reported by the VFS
*/ */
static void setDateTimeToCurrent(sqlite3_context *context, DateTime *p){ static void setDateTimeToCurrent(sqlite3_context *context, DateTime *p){
double r;
sqlite3 *db = sqlite3_context_db_handle(context); sqlite3 *db = sqlite3_context_db_handle(context);
sqlite3OsCurrentTime(db->pVfs, &r); sqlite3OsCurrentTimeInt64(db->pVfs, &p->iJD);
p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);
p->validJD = 1; p->validJD = 1;
} }
@@ -1038,22 +1036,15 @@ static void currentTimeFunc(
time_t t; time_t t;
char *zFormat = (char *)sqlite3_user_data(context); char *zFormat = (char *)sqlite3_user_data(context);
sqlite3 *db; sqlite3 *db;
double rT; sqlite3_int64 iT;
char zBuf[20]; char zBuf[20];
UNUSED_PARAMETER(argc); UNUSED_PARAMETER(argc);
UNUSED_PARAMETER(argv); UNUSED_PARAMETER(argv);
db = sqlite3_context_db_handle(context); db = sqlite3_context_db_handle(context);
sqlite3OsCurrentTime(db->pVfs, &rT); sqlite3OsCurrentTimeInt64(db->pVfs, &iT);
#ifndef SQLITE_OMIT_FLOATING_POINT t = (iT - 100*(sqlite3_int64)244058755)/1000;
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
#ifdef HAVE_GMTIME_R #ifdef HAVE_GMTIME_R
{ {
struct tm sNow; struct tm sNow;

View File

@@ -161,8 +161,16 @@ int sqlite3OsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
int sqlite3OsSleep(sqlite3_vfs *pVfs, int nMicro){ int sqlite3OsSleep(sqlite3_vfs *pVfs, int nMicro){
return pVfs->xSleep(pVfs, nMicro); return pVfs->xSleep(pVfs, nMicro);
} }
int sqlite3OsCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){ int sqlite3OsCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *pTimeOut){
return pVfs->xCurrentTime(pVfs, 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( int sqlite3OsOpenMalloc(

View File

@@ -259,7 +259,7 @@ void sqlite3OsDlClose(sqlite3_vfs *, void *);
#endif /* SQLITE_OMIT_LOAD_EXTENSION */ #endif /* SQLITE_OMIT_LOAD_EXTENSION */
int sqlite3OsRandomness(sqlite3_vfs *, int, char *); int sqlite3OsRandomness(sqlite3_vfs *, int, char *);
int sqlite3OsSleep(sqlite3_vfs *, int); int sqlite3OsSleep(sqlite3_vfs *, int);
int sqlite3OsCurrentTime(sqlite3_vfs *, double*); int sqlite3OsCurrentTimeInt64(sqlite3_vfs *, sqlite3_int64*);
/* /*
** Convenience functions for opening and closing files using ** Convenience functions for opening and closing files using

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. */ int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */
#endif #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 ** Find the current time (in Universal Coordinated Time). Write the
** current time and date as a Julian Day number into *prNow and ** current time and date as a Julian Day number into *prNow and
** return 0. Return 1 if the time and date cannot be found. ** return 0. Return 1 if the time and date cannot be found.
*/ */
static int unixCurrentTime(sqlite3_vfs *NotUsed, double *prNow){ static int unixCurrentTime(sqlite3_vfs *NotUsed, double *prNow){
#if defined(SQLITE_OMIT_FLOATING_POINT) sqlite3_int64 i;
time_t t; unixCurrentTimeInt64(0, &i);
time(&t); *prNow = i*86400000.0;
*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);
return 0; return 0;
} }
@@ -6601,7 +6614,7 @@ int sqlite3_os_init(void){
unixShmLock, /* xShmLock */ \ unixShmLock, /* xShmLock */ \
unixShmClose, /* xShmClose */ \ unixShmClose, /* xShmClose */ \
0, /* xRename */ \ 0, /* xRename */ \
0, /* xCurrentTimeInt64 */ \ unixCurrentTimeInt64, /* xCurrentTimeInt64 */ \
} }
/* /*

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. ** Return the current time as a Julian Day number in *pTimeOut.
*/ */
static int devsymCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){ static int devsymCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
return sqlite3OsCurrentTime(g.pVfs, pTimeOut); return g.pVfs->xCurrentTime(g.pVfs, pTimeOut);
} }

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. ** Return the current time as a Julian Day number in *pTimeOut.
*/ */
static int jtCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){ static int jtCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
return sqlite3OsCurrentTime(g.pVfs, pTimeOut); return g.pVfs->xCurrentTime(g.pVfs, pTimeOut);
} }
/************************************************************************** /**************************************************************************

View File

@@ -377,9 +377,7 @@ static int sqlite3Step(Vdbe *p){
#ifndef SQLITE_OMIT_TRACE #ifndef SQLITE_OMIT_TRACE
if( db->xProfile && !db->init.busy ){ if( db->xProfile && !db->init.busy ){
double rNow; sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
sqlite3OsCurrentTime(db->pVfs, &rNow);
p->startTime = (u64)((rNow - (int)rNow)*3600.0*24.0*1000000000.0);
} }
#endif #endif
@@ -400,13 +398,9 @@ static int sqlite3Step(Vdbe *p){
/* Invoke the profile callback if there is one /* Invoke the profile callback if there is one
*/ */
if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy && p->zSql ){ if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy && p->zSql ){
double rNow; sqlite3_int64 iNow;
u64 elapseTime; sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
db->xProfile(db->pProfileArg, p->zSql, iNow - p->startTime);
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);
} }
#endif #endif