Skip to content

Commit b7e8ea2

Browse files
author
drh
committed
Use VFS method xCurrentTimeInt64 instead of xCurrentTime when it is available.
Provide an implementation of xCurrentTimeInt64 for os_unix.c. FossilOrigin-Name: ab77b3ae6da3370d8bc3b2c9c0edc723b69f5a95
1 parent e8e1c9d commit b7e8ea2

9 files changed

Lines changed: 64 additions & 58 deletions

File tree

‎manifest‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
-----BEGIN PGP SIGNED MESSAGE-----
22
Hash: SHA1
33

4-
C Merge\sthe\swrite-ahead-logging\schanges\sinto\sthe\strunk.
5-
D 2010-05-03T14:08:28
4+
C Use\sVFS\smethod\sxCurrentTimeInt64\sinstead\sof\sxCurrentTime\swhen\sit\sis\savailable.\nProvide\san\simplementation\sof\sxCurrentTimeInt64\sfor\sos_unix.c.
5+
D 2010-05-03T14:32:30
66
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
77
F Makefile.in d83a0ffef3dcbfb08b410a6c6dd6c009ec9167fb
88
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -119,7 +119,7 @@ F src/build.c 11100b66fb97638d2d874c1d34d8db90650bb1d7
119119
F src/callback.c 01843bdf4b0420fd28046525d150fcd9802931a9
120120
F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
121121
F src/ctime.c 51553a859994d01d8bf3500747f66a890c459774
122-
F src/date.c 485a4409a384310e6d93fd1104a9d0a8658becd9
122+
F src/date.c 8a389e9529418b6333190a418034e2e8723a2fac
123123
F src/delete.c 610dc008e88a9599f905f5cbe9577ac9c36e0581
124124
F src/expr.c 286f62b24217ade1c14ba56de413ffdd607b6a41
125125
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
@@ -149,11 +149,11 @@ F src/mutex_os2.c 20477db50cf3817c2f1cd3eb61e5c177e50231db
149149
F src/mutex_unix.c 04a25238abce7e3d06b358dcf706e26624270809
150150
F src/mutex_w32.c 4cc201c1bfd11d1562810554ff5500e735559d7e
151151
F src/notify.c cbfa66a836da3a51567209636e6a94059c137930
152-
F src/os.c 8bc63cf91e9802e2b807198e54e50227fa889306
153-
F src/os.h 534b082c3cb349ad05fa6fa0b06087e022af282c
152+
F src/os.c aec6922553585a25d5655666defc125a7e217674
153+
F src/os.h b389844e5469a2918e8a45fe6ae52b4c28dfb2b2
154154
F src/os_common.h 0d6ee583b6ee3185eb9d951f890c6dd03021a08d
155155
F src/os_os2.c 8ad77a418630d7dee91d1bb04f79c2096301d3a0
156-
F src/os_unix.c 5c821e4eb04093102d901c22f40341bc1d30aef0
156+
F src/os_unix.c f3c0faad1c6de4f06f5ec30d586a4e62a980dc6f
157157
F src/os_win.c a8fc01d8483be472e495793c01064fd87e56a5c1
158158
F src/pager.c e9c7fe979b32a3c5bf4216d8fbe1cf8beff8a1b8
159159
F src/pager.h 934b598583a9d936bb13c37d62a2fe68ac48781c
@@ -191,13 +191,13 @@ F src/test_backup.c c129c91127e9b46e335715ae2e75756e25ba27de
191191
F src/test_btree.c 47cd771250f09cdc6e12dda5bc71bc0b3abc96e2
192192
F src/test_config.c 6210f501d358bde619ae761f06f123529c6ba24f
193193
F src/test_demovfs.c da81a5f7785bb352bda7911c332a983ec4f17f27
194-
F src/test_devsym.c 3d324248b80f31b3b29ab9bca39c4d856a2c9160
194+
F src/test_devsym.c 2160798b2dbd7bfa6225a70c31283ef9a097660a
195195
F src/test_func.c 13b582345fb1185a93e46c53310fae8547dcce20
196196
F src/test_hexio.c 1237f000ec7a491009b1233f5c626ea71bce1ea2
197197
F src/test_init.c 5d624ffd0409d424cf9adbfe1f056b200270077c
198198
F src/test_intarray.c d879bbf8e4ce085ab966d1f3c896a7c8b4f5fc99
199199
F src/test_intarray.h 489edb9068bb926583445cb02589344961054207
200-
F src/test_journal.c 0537fcf9d4ecb394ec8b27d887a004ecaab85f16
200+
F src/test_journal.c 51da4dd6118ee843349592fde29429fab84a6243
201201
F src/test_loadext.c df586c27176e3c2cb2e099c78da67bf14379a56e
202202
F src/test_malloc.c 2842c922b8e8d992aba722214952204ca025b411
203203
F src/test_mutex.c ce06b59aca168cd8c520b77159a24352a7469bd3
@@ -218,7 +218,7 @@ F src/vacuum.c 8e7d9a6fd076774bb6e211cad335c7337948a164
218218
F src/vdbe.c 8be37a1b18786b5c026adcb2e9edc93e3a940885
219219
F src/vdbe.h 471f6a3dcec4817ca33596fe7f6654d56c0e75f3
220220
F src/vdbeInt.h 19ebc8c2a2e938340051ee65af3f377fb99102d1
221-
F src/vdbeapi.c cf1ff7cbcbd44d2082af71b98762407ae01ce009
221+
F src/vdbeapi.c f2da22e5dcb1943ce6605614636e6bf32158640d
222222
F src/vdbeaux.c 395d21a1617553ea9b9f4abe0d302449d8549e1d
223223
F src/vdbeblob.c 5327132a42a91e8b7acfb60b9d2c3b1c5c863e0e
224224
F src/vdbemem.c 2a82f455f6ca6f78b59fb312f96054c04ae0ead1
@@ -811,14 +811,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
811811
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
812812
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
813813
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
814-
P 946e06cd2a2cc209b0786b7e9d28c0746320d646 27a5c09ce8a35039d844d08cfe5698e8b438abfe
815-
R 496e930fc5a775a552ace6c40959352e
814+
P de9ae443cc8eebfb0692dcdac93bde9e4c54199a
815+
R e2427a6bed16c13592f9c9205631cbf2
816816
U drh
817-
Z 6de75408ba1e125bd7e7fd0306efd7dd
817+
Z 44856fc90c606c86cc9a47a6ae746757
818818
-----BEGIN PGP SIGNATURE-----
819819
Version: GnuPG v1.4.6 (GNU/Linux)
820820

821-
iD8DBQFL3tjgoxKgR168RlERAn8zAJ4myOF3FCYW6KNideNeI9JIkyQm6ACfbPiT
822-
qZo9Et3fACK9ap0KUhaVVwE=
823-
=UJ+t
821+
iD8DBQFL3t6BoxKgR168RlERAmG1AJ9O0XG5Km2CNUBGaWq0PnJbrMhSsgCeJiI9
822+
DrNwLLIIqnopSV7zMILP0LA=
823+
=3EtO
824824
-----END PGP SIGNATURE-----

‎manifest.uuid‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
de9ae443cc8eebfb0692dcdac93bde9e4c54199a
1+
ab77b3ae6da3370d8bc3b2c9c0edc723b69f5a95

‎src/date.c‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,8 @@ static int parseYyyyMmDd(const char *zDate, DateTime *p){
314314
** Set the time to the current time reported by the VFS
315315
*/
316316
static void setDateTimeToCurrent(sqlite3_context *context, DateTime *p){
317-
double r;
318317
sqlite3 *db = sqlite3_context_db_handle(context);
319-
sqlite3OsCurrentTime(db->pVfs, &r);
320-
p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);
318+
sqlite3OsCurrentTimeInt64(db->pVfs, &p->iJD);
321319
p->validJD = 1;
322320
}
323321

@@ -1038,22 +1036,15 @@ static void currentTimeFunc(
10381036
time_t t;
10391037
char *zFormat = (char *)sqlite3_user_data(context);
10401038
sqlite3 *db;
1041-
double rT;
1039+
sqlite3_int64 iT;
10421040
char zBuf[20];
10431041

10441042
UNUSED_PARAMETER(argc);
10451043
UNUSED_PARAMETER(argv);
10461044

10471045
db = sqlite3_context_db_handle(context);
1048-
sqlite3OsCurrentTime(db->pVfs, &rT);
1049-
#ifndef SQLITE_OMIT_FLOATING_POINT
1050-
t = 86400.0*(rT - 2440587.5) + 0.5;
1051-
#else
1052-
/* without floating point support, rT will have
1053-
** already lost fractional day precision.
1054-
*/
1055-
t = 86400 * (rT - 2440587) - 43200;
1056-
#endif
1046+
sqlite3OsCurrentTimeInt64(db->pVfs, &iT);
1047+
t = (iT - 100*(sqlite3_int64)244058755)/1000;
10571048
#ifdef HAVE_GMTIME_R
10581049
{
10591050
struct tm sNow;

‎src/os.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,16 @@ int sqlite3OsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
161161
int sqlite3OsSleep(sqlite3_vfs *pVfs, int nMicro){
162162
return pVfs->xSleep(pVfs, nMicro);
163163
}
164-
int sqlite3OsCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
165-
return pVfs->xCurrentTime(pVfs, pTimeOut);
164+
int sqlite3OsCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *pTimeOut){
165+
int rc;
166+
if( pVfs->iVersion>=2 && pVfs->xCurrentTimeInt64 ){
167+
rc = pVfs->xCurrentTimeInt64(pVfs, pTimeOut);
168+
}else{
169+
double r;
170+
rc = pVfs->xCurrentTime(pVfs, &r);
171+
*pTimeOut = (sqlite3_int64)(r*86400000.0);
172+
}
173+
return rc;
166174
}
167175

168176
int sqlite3OsOpenMalloc(

‎src/os.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ void sqlite3OsDlClose(sqlite3_vfs *, void *);
259259
#endif /* SQLITE_OMIT_LOAD_EXTENSION */
260260
int sqlite3OsRandomness(sqlite3_vfs *, int, char *);
261261
int sqlite3OsSleep(sqlite3_vfs *, int);
262-
int sqlite3OsCurrentTime(sqlite3_vfs *, double*);
262+
int sqlite3OsCurrentTimeInt64(sqlite3_vfs *, sqlite3_int64*);
263263

264264
/*
265265
** Convenience functions for opening and closing files using

‎src/os_unix.c‎

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4516,38 +4516,51 @@ int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */
45164516
#endif
45174517

45184518
/*
4519-
** Find the current time (in Universal Coordinated Time). Write the
4520-
** current time and date as a Julian Day number into *prNow and
4521-
** return 0. Return 1 if the time and date cannot be found.
4519+
** Find the current time (in Universal Coordinated Time). Write into *piNow
4520+
** the current time and date as a Julian Day number times 86_400_000. In
4521+
** other words, write into *piNow the number of milliseconds since the Julian
4522+
** epoch of noon in Greenwich on November 24, 4714 B.C according to the
4523+
** proleptic Gregorian calendar.
4524+
**
4525+
** On success, return 0. Return 1 if the time and date cannot be found.
45224526
*/
4523-
static int unixCurrentTime(sqlite3_vfs *NotUsed, double *prNow){
4524-
#if defined(SQLITE_OMIT_FLOATING_POINT)
4525-
time_t t;
4526-
time(&t);
4527-
*prNow = (((sqlite3_int64)t)/8640 + 24405875)/10;
4528-
#elif defined(NO_GETTOD)
4527+
static int unixCurrentTimeInt64(sqlite3_vfs *NotUsed, sqlite3_int64 *piNow){
4528+
static const sqlite3_int64 unixEpoch = 24405875*(sqlite3_int64)8640000;
4529+
#if defined(NO_GETTOD)
45294530
time_t t;
45304531
time(&t);
4531-
*prNow = t/86400.0 + 2440587.5;
4532+
*piNow = ((sqlite3_int64)i)*1000 + unixEpoch;
45324533
#elif OS_VXWORKS
45334534
struct timespec sNow;
45344535
clock_gettime(CLOCK_REALTIME, &sNow);
4535-
*prNow = 2440587.5 + sNow.tv_sec/86400.0 + sNow.tv_nsec/86400000000000.0;
4536+
*piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_nsec/1000000;
45364537
#else
45374538
struct timeval sNow;
45384539
gettimeofday(&sNow, 0);
4539-
*prNow = 2440587.5 + sNow.tv_sec/86400.0 + sNow.tv_usec/86400000000.0;
4540+
*piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_usec/1000;
45404541
#endif
45414542

45424543
#ifdef SQLITE_TEST
45434544
if( sqlite3_current_time ){
4544-
*prNow = sqlite3_current_time/86400.0 + 2440587.5;
4545+
*piNow = 1000*(sqlite3_int64)sqlite3_current_time + unixEpoch;
45454546
}
45464547
#endif
45474548
UNUSED_PARAMETER(NotUsed);
45484549
return 0;
45494550
}
45504551

4552+
/*
4553+
** Find the current time (in Universal Coordinated Time). Write the
4554+
** current time and date as a Julian Day number into *prNow and
4555+
** return 0. Return 1 if the time and date cannot be found.
4556+
*/
4557+
static int unixCurrentTime(sqlite3_vfs *NotUsed, double *prNow){
4558+
sqlite3_int64 i;
4559+
unixCurrentTimeInt64(0, &i);
4560+
*prNow = i*86400000.0;
4561+
return 0;
4562+
}
4563+
45514564
/*
45524565
** We added the xGetLastError() method with the intention of providing
45534566
** better low-level error messages when operating-system problems come up
@@ -6601,7 +6614,7 @@ int sqlite3_os_init(void){
66016614
unixShmLock, /* xShmLock */ \
66026615
unixShmClose, /* xShmClose */ \
66036616
0, /* xRename */ \
6604-
0, /* xCurrentTimeInt64 */ \
6617+
unixCurrentTimeInt64, /* xCurrentTimeInt64 */ \
66056618
}
66066619

66076620
/*

‎src/test_devsym.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ static int devsymSleep(sqlite3_vfs *pVfs, int nMicro){
346346
** Return the current time as a Julian Day number in *pTimeOut.
347347
*/
348348
static int devsymCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
349-
return sqlite3OsCurrentTime(g.pVfs, pTimeOut);
349+
return g.pVfs->xCurrentTime(g.pVfs, pTimeOut);
350350
}
351351

352352

‎src/test_journal.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ static int jtSleep(sqlite3_vfs *pVfs, int nMicro){
801801
** Return the current time as a Julian Day number in *pTimeOut.
802802
*/
803803
static int jtCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
804-
return sqlite3OsCurrentTime(g.pVfs, pTimeOut);
804+
return g.pVfs->xCurrentTime(g.pVfs, pTimeOut);
805805
}
806806

807807
/**************************************************************************

‎src/vdbeapi.c‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,7 @@ static int sqlite3Step(Vdbe *p){
377377

378378
#ifndef SQLITE_OMIT_TRACE
379379
if( db->xProfile && !db->init.busy ){
380-
double rNow;
381-
sqlite3OsCurrentTime(db->pVfs, &rNow);
382-
p->startTime = (u64)((rNow - (int)rNow)*3600.0*24.0*1000000000.0);
380+
sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
383381
}
384382
#endif
385383

@@ -400,13 +398,9 @@ static int sqlite3Step(Vdbe *p){
400398
/* Invoke the profile callback if there is one
401399
*/
402400
if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy && p->zSql ){
403-
double rNow;
404-
u64 elapseTime;
405-
406-
sqlite3OsCurrentTime(db->pVfs, &rNow);
407-
elapseTime = (u64)((rNow - (int)rNow)*3600.0*24.0*1000000000.0);
408-
elapseTime -= p->startTime;
409-
db->xProfile(db->pProfileArg, p->zSql, elapseTime);
401+
sqlite3_int64 iNow;
402+
sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
403+
db->xProfile(db->pProfileArg, p->zSql, iNow - p->startTime);
410404
}
411405
#endif
412406

0 commit comments

Comments
 (0)