From: drh Date: Mon, 3 May 2010 14:32:30 +0000 (+0000) Subject: Use VFS method xCurrentTimeInt64 instead of xCurrentTime when it is available. X-Git-Tag: version-3.7.2~454 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b7e8ea201518d52b01ac7b5b40df7e05fe9dd6be;p=thirdparty%2Fsqlite.git Use VFS method xCurrentTimeInt64 instead of xCurrentTime when it is available. Provide an implementation of xCurrentTimeInt64 for os_unix.c. FossilOrigin-Name: ab77b3ae6da3370d8bc3b2c9c0edc723b69f5a95 --- diff --git a/manifest b/manifest index bfddf21179..53442bd4d4 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 -C Merge\sthe\swrite-ahead-logging\schanges\sinto\sthe\strunk. -D 2010-05-03T14:08:28 +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:32:30 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in d83a0ffef3dcbfb08b410a6c6dd6c009ec9167fb F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -119,7 +119,7 @@ F src/build.c 11100b66fb97638d2d874c1d34d8db90650bb1d7 F src/callback.c 01843bdf4b0420fd28046525d150fcd9802931a9 F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac F src/ctime.c 51553a859994d01d8bf3500747f66a890c459774 -F src/date.c 485a4409a384310e6d93fd1104a9d0a8658becd9 +F src/date.c 8a389e9529418b6333190a418034e2e8723a2fac F src/delete.c 610dc008e88a9599f905f5cbe9577ac9c36e0581 F src/expr.c 286f62b24217ade1c14ba56de413ffdd607b6a41 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb @@ -149,11 +149,11 @@ F src/mutex_os2.c 20477db50cf3817c2f1cd3eb61e5c177e50231db F src/mutex_unix.c 04a25238abce7e3d06b358dcf706e26624270809 F src/mutex_w32.c 4cc201c1bfd11d1562810554ff5500e735559d7e F src/notify.c cbfa66a836da3a51567209636e6a94059c137930 -F src/os.c 8bc63cf91e9802e2b807198e54e50227fa889306 -F src/os.h 534b082c3cb349ad05fa6fa0b06087e022af282c +F src/os.c aec6922553585a25d5655666defc125a7e217674 +F src/os.h b389844e5469a2918e8a45fe6ae52b4c28dfb2b2 F src/os_common.h 0d6ee583b6ee3185eb9d951f890c6dd03021a08d 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/pager.c e9c7fe979b32a3c5bf4216d8fbe1cf8beff8a1b8 F src/pager.h 934b598583a9d936bb13c37d62a2fe68ac48781c @@ -191,13 +191,13 @@ F src/test_backup.c c129c91127e9b46e335715ae2e75756e25ba27de F src/test_btree.c 47cd771250f09cdc6e12dda5bc71bc0b3abc96e2 F src/test_config.c 6210f501d358bde619ae761f06f123529c6ba24f 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_hexio.c 1237f000ec7a491009b1233f5c626ea71bce1ea2 F src/test_init.c 5d624ffd0409d424cf9adbfe1f056b200270077c F src/test_intarray.c d879bbf8e4ce085ab966d1f3c896a7c8b4f5fc99 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_malloc.c 2842c922b8e8d992aba722214952204ca025b411 F src/test_mutex.c ce06b59aca168cd8c520b77159a24352a7469bd3 @@ -218,7 +218,7 @@ F src/vacuum.c 8e7d9a6fd076774bb6e211cad335c7337948a164 F src/vdbe.c 8be37a1b18786b5c026adcb2e9edc93e3a940885 F src/vdbe.h 471f6a3dcec4817ca33596fe7f6654d56c0e75f3 F src/vdbeInt.h 19ebc8c2a2e938340051ee65af3f377fb99102d1 -F src/vdbeapi.c cf1ff7cbcbd44d2082af71b98762407ae01ce009 +F src/vdbeapi.c f2da22e5dcb1943ce6605614636e6bf32158640d F src/vdbeaux.c 395d21a1617553ea9b9f4abe0d302449d8549e1d F src/vdbeblob.c 5327132a42a91e8b7acfb60b9d2c3b1c5c863e0e F src/vdbemem.c 2a82f455f6ca6f78b59fb312f96054c04ae0ead1 @@ -811,14 +811,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 946e06cd2a2cc209b0786b7e9d28c0746320d646 27a5c09ce8a35039d844d08cfe5698e8b438abfe -R 496e930fc5a775a552ace6c40959352e +P de9ae443cc8eebfb0692dcdac93bde9e4c54199a +R e2427a6bed16c13592f9c9205631cbf2 U drh -Z 6de75408ba1e125bd7e7fd0306efd7dd +Z 44856fc90c606c86cc9a47a6ae746757 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) -iD8DBQFL3tjgoxKgR168RlERAn8zAJ4myOF3FCYW6KNideNeI9JIkyQm6ACfbPiT -qZo9Et3fACK9ap0KUhaVVwE= -=UJ+t +iD8DBQFL3t6BoxKgR168RlERAmG1AJ9O0XG5Km2CNUBGaWq0PnJbrMhSsgCeJiI9 +DrNwLLIIqnopSV7zMILP0LA= +=3EtO -----END PGP SIGNATURE----- diff --git a/manifest.uuid b/manifest.uuid index c412be269d..7eea3a9cfb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -de9ae443cc8eebfb0692dcdac93bde9e4c54199a \ No newline at end of file +ab77b3ae6da3370d8bc3b2c9c0edc723b69f5a95 \ No newline at end of file diff --git a/src/date.c b/src/date.c index 2c39a0a0d0..cae0a270df 100644 --- a/src/date.c +++ b/src/date.c @@ -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; diff --git a/src/os.c b/src/os.c index f3600cb0e2..b3e870034f 100644 --- a/src/os.c +++ b/src/os.c @@ -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( diff --git a/src/os.h b/src/os.h index 089901e0f6..7b2bff0dc6 100644 --- a/src/os.h +++ b/src/os.h @@ -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 diff --git a/src/os_unix.c b/src/os_unix.c index 986963a184..cb3e19009a 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -4516,38 +4516,51 @@ int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */ #endif /* -** 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. +** 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 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) +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); - *prNow = t/86400.0 + 2440587.5; + *piNow = ((sqlite3_int64)i)*1000 + unixEpoch; #elif OS_VXWORKS struct timespec sNow; clock_gettime(CLOCK_REALTIME, &sNow); - *prNow = 2440587.5 + sNow.tv_sec/86400.0 + sNow.tv_nsec/86400000000000.0; + *piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_nsec/1000000; #else struct timeval sNow; gettimeofday(&sNow, 0); - *prNow = 2440587.5 + sNow.tv_sec/86400.0 + sNow.tv_usec/86400000000.0; + *piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_usec/1000; #endif #ifdef SQLITE_TEST if( sqlite3_current_time ){ - *prNow = sqlite3_current_time/86400.0 + 2440587.5; + *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){ + sqlite3_int64 i; + unixCurrentTimeInt64(0, &i); + *prNow = i*86400000.0; + return 0; +} + /* ** We added the xGetLastError() method with the intention of providing ** better low-level error messages when operating-system problems come up @@ -6601,7 +6614,7 @@ int sqlite3_os_init(void){ unixShmLock, /* xShmLock */ \ unixShmClose, /* xShmClose */ \ 0, /* xRename */ \ - 0, /* xCurrentTimeInt64 */ \ + unixCurrentTimeInt64, /* xCurrentTimeInt64 */ \ } /* diff --git a/src/test_devsym.c b/src/test_devsym.c index 69d716246d..118af8b08f 100644 --- a/src/test_devsym.c +++ b/src/test_devsym.c @@ -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); } diff --git a/src/test_journal.c b/src/test_journal.c index 020b41575d..c4bc5d094c 100644 --- a/src/test_journal.c +++ b/src/test_journal.c @@ -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); } /************************************************************************** diff --git a/src/vdbeapi.c b/src/vdbeapi.c index f16cc1be08..2a8c1dd18f 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -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