Remove the xShmOpen method from the VFS. Shared-memory is opened automatically

by a call to xShmMap.  Rename the xShmClose method to xShmUnmap.

FossilOrigin-Name: 2b68e50268412599576c86ae70b830d0388cb35c
This commit is contained in:
drh 2010-07-14 00:22:36 +00:00
commit 54e0536275
17 changed files with 296 additions and 314 deletions

View File

@ -1,5 +1,8 @@
C Fixes\sto\sthe\spcache10\sand\spcache90\spermutations.
D 2010-07-13T14:22:40
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
C Remove\sthe\sxShmOpen\smethod\sfrom\sthe\sVFS.\s\sShared-memory\sis\sopened\sautomatically\nby\sa\scall\sto\sxShmMap.\s\sRename\sthe\sxShmClose\smethod\sto\sxShmUnmap.
D 2010-07-14T00:22:36
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in ec08dc838fd8110fe24c92e5130bcd91cbb1ff2e
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -131,7 +134,7 @@ F src/hash.c 458488dcc159c301b8e7686280ab209f1fb915af
F src/hash.h 2894c932d84d9f892d4b4023a75e501f83050970
F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08
F src/insert.c d9476f23f85a20eea3cc25a4b9f9cbae77a33bf2
F src/journal.c cb9f12b6734a0b25aa60d3e093a27bccf46b4bc6
F src/journal.c 552839e54d1bf76fb8f7abe51868b66acacf6a0e
F src/legacy.c a199d7683d60cef73089e892409113e69c23a99f
F src/lempar.c 7f026423f4d71d989e719a743f98a1cbd4e6d99e
F src/loadext.c 1c7a61ce1281041f437333f366a96aa0d29bb581
@ -142,7 +145,7 @@ F src/mem1.c 89d4ea8d5cdd55635cbaa48ad53132af6294cbb2
F src/mem2.c 2ee7bdacda8299b5a91cff9f7ee3e46573195c38
F src/mem3.c 9b237d911ba9904142a804be727cc6664873f8a3
F src/mem5.c eb7a5cb98915dd7a086fa415ce3a5a0f20d0acff
F src/memjournal.c 6a81669d6fbf14813992f48a1a0e2bfe57ec66c6
F src/memjournal.c 4a93a25ad9f76c40afa070ffd7187eb3a5fd7aee
F src/mutex.c 6949180803ff05a7d0e2b9334a95b4fb5a00e23f
F src/mutex.h 6fde601e55fa6c3fae768783c439797ab84c87c6
F src/mutex_noop.c d5cfbca87168c661a0b118cd8e329a908e453151
@ -150,13 +153,13 @@ F src/mutex_os2.c 6a62583e374ba3ac1a3fcc0da2bfdac7d3942689
F src/mutex_unix.c cf84466b4fdd2baa0d5a10bb19f08b2abc1ce42e
F src/mutex_w32.c 1fe0e735897be20e09dd6f53c3fb516c6b48c0eb
F src/notify.c cbfa66a836da3a51567209636e6a94059c137930
F src/os.c c34882169b2f8ee0942c4f6aff9ee705e6110cdf
F src/os.h d7775504a51e6e0d40315aa427b3e229ff9ff9ca
F src/os.c a0ecbd198b92e60a3e3b8887a668df3f80b4f62f
F src/os.h 9dbed8c2b9c1f2f2ebabc09e49829d4777c26bf9
F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f
F src/os_os2.c 665876d5eec7585226b0a1cf5e18098de2b2da19
F src/os_unix.c c6112f0ae34f23ae5ca0189a685e084befbdcf26
F src/os_win.c 04c8828e4c5c2e7d5abcb9ce170ae6bfb02aa98d
F src/pager.c 1d42e2cdaa9b1765f7df8e350509318917cd651d
F src/os_unix.c 7845a3c91b5e5e1ed3c5e7f5430ff8af7e9d6c02
F src/os_win.c 61734aad7f50b28f3c76eb4b19b63472f6d825d9
F src/pager.c 78ca1e1f3315c8227431c403c04d791dccf242fb
F src/pager.h 879fdde5a102d2f21a3135d6f647530b21c2796c
F src/parse.y ace5c7a125d9f2a410e431ee3209034105045f7e
F src/pcache.c 1e9aa2dbc0845b52e1b51cc39753b6d1e041cb07
@ -170,7 +173,7 @@ F src/resolve.c 1c0f32b64f8e3f555fe1f732f9d6f501a7f05706
F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697
F src/select.c 4903ff1bbd08b55cbce00ea43c645530de41b362
F src/shell.c fd4ccdb37c3b68de0623eb938a649e0990710714
F src/sqlite.h.in 26bcfc3084a2e4b4debba311c59ae434820c8e98
F src/sqlite.h.in 1bcca411e266054977ed2b149a242c5a71092904
F src/sqlite3ext.h 69dfb8116af51b84a029cddb3b35062354270c89
F src/sqliteInt.h 8eb5d1c63fff70ed30f4b861aeaf8485e663129c
F src/sqliteLimit.h 196e2f83c3b444c4548fc1874f52f84fdbda40f3
@ -182,7 +185,7 @@ F src/test2.c e3f564ab1e9fd0b47b0c9e23e7054e38bf0836cf
F src/test3.c 4c21700c73a890a47fc685c1097bfb661346ac94
F src/test4.c ad03bb987ddedce928f4258c1e7fa4109a73497d
F src/test5.c cc55900118fa4add8ec9cf69fc4225a4662f76b1
F src/test6.c a1217a210fd6e2bcd11ddff4ad2484ec65998043
F src/test6.c c7256cc21d2409486d094277d5b017e8eced44ba
F src/test7.c 3f2d63e4ccf97f8c2cf1a7fa0a3c8e2e2a354e6e
F src/test8.c f959db9a22d882013b64c92753fa793b2ce3bdea
F src/test9.c bea1e8cf52aa93695487badedd6e1886c321ea60
@ -192,7 +195,7 @@ F src/test_backup.c c129c91127e9b46e335715ae2e75756e25ba27de
F src/test_btree.c 47cd771250f09cdc6e12dda5bc71bc0b3abc96e2
F src/test_config.c 5a11c51af2156e2d07186930b36f2b8239a4393f
F src/test_demovfs.c da81a5f7785bb352bda7911c332a983ec4f17f27
F src/test_devsym.c 5a99203fb7ff43047d7e493d1b159585983d4ea6
F src/test_devsym.c e7498904e72ba7491d142d5c83b476c4e76993bc
F src/test_func.c 13b582345fb1185a93e46c53310fae8547dcce20
F src/test_hexio.c 1237f000ec7a491009b1233f5c626ea71bce1ea2
F src/test_init.c 5d624ffd0409d424cf9adbfe1f056b200270077c
@ -202,15 +205,15 @@ F src/test_journal.c 424a334cdfdc8a6f975abe3641440147bded3185
F src/test_loadext.c df586c27176e3c2cb2e099c78da67bf14379a56e
F src/test_malloc.c 4ab85f2b8ae3a237f4e6557b0a641181a19ffab1
F src/test_mutex.c ce06b59aca168cd8c520b77159a24352a7469bd3
F src/test_onefile.c 701553cecc466c13fbebdb27cc7022839512f7bd
F src/test_osinst.c 700a39f4b7d3959fb65b1a97a5503a9b6d952c6b
F src/test_onefile.c 40cf9e212a377a6511469384a64b01e6e34b2eec
F src/test_osinst.c f408c6a181f2fb04c56273afd5c3e1e82f60392c
F src/test_pcache.c 7bf828972ac0d2403f5cfa4cd14da41f8ebe73d8
F src/test_schema.c 8c06ef9ddb240c7a0fcd31bc221a6a2aade58bf0
F src/test_server.c bbba05c144b5fc4b52ff650a4328027b3fa5fcc6
F src/test_stat.c 6ebaf2a86d01ccda24e49c148f1d33e8badda06e
F src/test_tclvar.c f4dc67d5f780707210d6bb0eb6016a431c04c7fa
F src/test_thread.c bedd05cad673dba53326f3aa468cc803038896c0
F src/test_vfs.c bea0f0bdee9b033a62d057bf3451c25760b0414d
F src/test_vfs.c 7e291f85256516ebde6633bc381ff7eedfa30234
F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9
F src/tokenize.c 25ceb0f0a746ea1d0f9553787f3f0a56853cfaeb
F src/trigger.c 67e95c76d625b92d43409ace771c8e0d02a09ac2
@ -218,7 +221,7 @@ F src/update.c 19c899c23cd29fd102c9068e0b0ff5b087204beb
F src/utf.c 1baeeac91707a4df97ccc6141ec0f808278af685
F src/util.c 32aebf04c10e51ad3977a928b7416bed671b620b
F src/vacuum.c 241a8386727c1497eba4955933356dfba6ff8c9f
F src/vdbe.c 14d3e04d13e1c79ab62674e06b0d0a8ed70f9e75
F src/vdbe.c 6294de3327e09d14e9c06ecfd10e57c2d8e85307
F src/vdbe.h 471f6a3dcec4817ca33596fe7f6654d56c0e75f3
F src/vdbeInt.h 19ebc8c2a2e938340051ee65af3f377fb99102d1
F src/vdbeapi.c dc3138f10afbc95ed3c21dd25abb154504b1db9d
@ -227,7 +230,7 @@ F src/vdbeblob.c 258a6010ba7a82b72b327fb24c55790655689256
F src/vdbemem.c 5e579abf6532001dfbee0e640dc34eae897a9807
F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2
F src/vtab.c a0f8a40274e4261696ef57aa806de2776ab72cda
F src/wal.c c1783e405f0ac19923fd1743ff7a3b29cb27709c
F src/wal.c 7dce9040d5ba6c575f337b298fce1a9c04eb2296
F src/wal.h 906c85760598b18584921fe08008435aa4eeeeb2
F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
F src/where.c 926c83c6394e132a1c62b6b12ceeba7d55a34c19
@ -834,7 +837,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P 05ac2548652f3c9aa358289700b0b4c7fc22486d
R d7ea8bae5d34f266c6513da1f61674ff
U dan
Z a4fee7d380a1fd69eda8299369e35825
P 597d40fa529073123a50ae6afc762c59404f8f5f c2d27cf51d33e6f38bab37008d39074051f75274
R ed9e8ba444308d86203809c921582295
U drh
Z 76541e7ad3808e0604906bf1fc532690
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFMPQNPoxKgR168RlERAioBAJ9xlZcJfJlK34lIspobQYDe842CLQCdFqz0
PexiupCstye/oPNnjaqjdbY=
=AS0q
-----END PGP SIGNATURE-----

View File

@ -1 +1 @@
597d40fa529073123a50ae6afc762c59404f8f5f
2b68e50268412599576c86ae70b830d0388cb35c

View File

@ -183,11 +183,10 @@ static struct sqlite3_io_methods JournalFileMethods = {
0, /* xFileControl */
0, /* xSectorSize */
0, /* xDeviceCharacteristics */
0, /* xShmOpen */
0, /* xShmLock */
0, /* xShmMap */
0, /* xShmLock */
0, /* xShmBarrier */
0 /* xShmClose */
0 /* xShmUnmap */
};
/*

View File

@ -227,11 +227,10 @@ static const struct sqlite3_io_methods MemJournalMethods = {
0, /* xFileControl */
0, /* xSectorSize */
0, /* xDeviceCharacteristics */
0, /* xShmOpen */
0, /* xShmLock */
0, /* xShmMap */
0, /* xShmLock */
0, /* xShmBarrier */
0 /* xShmClose */
0 /* xShmUnlock */
};
/*

View File

@ -100,26 +100,23 @@ int sqlite3OsSectorSize(sqlite3_file *id){
int sqlite3OsDeviceCharacteristics(sqlite3_file *id){
return id->pMethods->xDeviceCharacteristics(id);
}
int sqlite3OsShmOpen(sqlite3_file *id){
return id->pMethods->xShmOpen(id);
}
int sqlite3OsShmLock(sqlite3_file *id, int offset, int n, int flags){
return id->pMethods->xShmLock(id, offset, n, flags);
}
void sqlite3OsShmBarrier(sqlite3_file *id){
id->pMethods->xShmBarrier(id);
}
int sqlite3OsShmClose(sqlite3_file *id, int deleteFlag){
return id->pMethods->xShmClose(id, deleteFlag);
int sqlite3OsShmUnmap(sqlite3_file *id, int deleteFlag){
return id->pMethods->xShmUnmap(id, deleteFlag);
}
int sqlite3OsShmMap(
sqlite3_file *id,
int iPage,
int pgsz,
int isWrite,
void volatile **pp
sqlite3_file *id, /* Database file handle */
int iPage,
int pgsz,
int bExtend, /* True to extend file if necessary */
void volatile **pp /* OUT: Pointer to mapping */
){
return id->pMethods->xShmMap(id, iPage, pgsz, isWrite, pp);
return id->pMethods->xShmMap(id, iPage, pgsz, bExtend, pp);
}
/*

View File

@ -247,11 +247,10 @@ int sqlite3OsFileControl(sqlite3_file*,int,void*);
#define SQLITE_FCNTL_DB_UNCHANGED 0xca093fa0
int sqlite3OsSectorSize(sqlite3_file *id);
int sqlite3OsDeviceCharacteristics(sqlite3_file *id);
int sqlite3OsShmOpen(sqlite3_file *id);
int sqlite3OsShmMap(sqlite3_file *,int,int,int,void volatile **);
int sqlite3OsShmLock(sqlite3_file *id, int, int, int);
void sqlite3OsShmBarrier(sqlite3_file *id);
int sqlite3OsShmClose(sqlite3_file *id, int);
int sqlite3OsShmMap(sqlite3_file *,int,int,int,void volatile **);
int sqlite3OsShmUnmap(sqlite3_file *id, int);
/*
** Functions for accessing sqlite3_vfs methods

View File

@ -3275,7 +3275,7 @@ static void unixShmPurge(unixFile *pFd){
}
/*
** Open a shared-memory area associated with open database file fd.
** Open a shared-memory area associated with open database file pDbFd.
** This particular implementation uses mmapped files.
**
** The file used to implement shared-memory is in the same directory
@ -3294,27 +3294,22 @@ static void unixShmPurge(unixFile *pFd){
** file are currently open, in this process or in other processes, then
** the file must be truncated to zero length or have its header cleared.
*/
static int unixShmOpen(
sqlite3_file *fd /* The file descriptor of the associated database */
){
struct unixShm *p = 0; /* The connection to be opened */
struct unixShmNode *pShmNode = 0; /* The underlying mmapped file */
int rc; /* Result code */
struct unixFile *pDbFd; /* Underlying database file */
unixInodeInfo *pInode; /* The inode of fd */
char *zShmFilename; /* Name of the file used for SHM */
int nShmFilename; /* Size of the SHM filename in bytes */
static int unixOpenSharedMemory(unixFile *pDbFd){
struct unixShm *p = 0; /* The connection to be opened */
struct unixShmNode *pShmNode; /* The underlying mmapped file */
int rc; /* Result code */
unixInodeInfo *pInode; /* The inode of fd */
char *zShmFilename; /* Name of the file used for SHM */
int nShmFilename; /* Size of the SHM filename in bytes */
/* Allocate space for the new sqlite3_shm object.
*/
/* Allocate space for the new unixShm object. */
p = sqlite3_malloc( sizeof(*p) );
if( p==0 ) return SQLITE_NOMEM;
memset(p, 0, sizeof(*p));
pDbFd = (struct unixFile*)fd;
assert( pDbFd->pShm==0 );
/* Check to see if a unixShmNode object already exists. Reuse an existing
** one if present. Create a new one if necessary.
/* Check to see if a unixShmNode object already exists. Reuse an existing
** one if present. Create a new one if necessary.
*/
unixEnterMutex();
pInode = pDbFd->pInode;
@ -3380,49 +3375,107 @@ shm_open_err:
}
/*
** Close a connection to shared-memory. Delete the underlying
** storage if deleteFlag is true.
** This function is called to obtain a pointer to region iRegion of the
** shared-memory associated with the database file fd. Shared-memory regions
** are numbered starting from zero. Each shared-memory region is szRegion
** bytes in size.
**
** If an error occurs, an error code is returned and *pp is set to NULL.
**
** Otherwise, if the bExtend parameter is 0 and the requested shared-memory
** region has not been allocated (by any client, including one running in a
** separate process), then *pp is set to NULL and SQLITE_OK returned. If
** bExtend is non-zero and the requested shared-memory region has not yet
** been allocated, it is allocated by this function.
**
** If the shared-memory region has already been allocated or is allocated by
** this call as described above, then it is mapped into this processes
** address space (if it is not already), *pp is set to point to the mapped
** memory and SQLITE_OK returned.
*/
static int unixShmClose(
sqlite3_file *fd, /* The underlying database file */
int deleteFlag /* Delete shared-memory if true */
static int unixShmMap(
sqlite3_file *fd, /* Handle open on database file */
int iRegion, /* Region to retrieve */
int szRegion, /* Size of regions */
int bExtend, /* True to extend file if necessary */
void volatile **pp /* OUT: Mapped memory */
){
unixShm *p; /* The connection to be closed */
unixShmNode *pShmNode; /* The underlying shared-memory file */
unixShm **pp; /* For looping over sibling connections */
unixFile *pDbFd; /* The underlying database file */
unixFile *pDbFd = (unixFile*)fd;
unixShm *p;
unixShmNode *pShmNode;
int rc = SQLITE_OK;
pDbFd = (unixFile*)fd;
p = pDbFd->pShm;
if( p==0 ) return SQLITE_OK;
pShmNode = p->pShmNode;
assert( pShmNode==pDbFd->pInode->pShmNode );
assert( pShmNode->pInode==pDbFd->pInode );
/* Remove connection p from the set of connections associated
** with pShmNode */
sqlite3_mutex_enter(pShmNode->mutex);
for(pp=&pShmNode->pFirst; (*pp)!=p; pp = &(*pp)->pNext){}
*pp = p->pNext;
/* Free the connection p */
sqlite3_free(p);
pDbFd->pShm = 0;
sqlite3_mutex_leave(pShmNode->mutex);
/* If pShmNode->nRef has reached 0, then close the underlying
** shared-memory file, too */
unixEnterMutex();
assert( pShmNode->nRef>0 );
pShmNode->nRef--;
if( pShmNode->nRef==0 ){
if( deleteFlag ) unlink(pShmNode->zFilename);
unixShmPurge(pDbFd);
/* If the shared-memory file has not yet been opened, open it now. */
if( pDbFd->pShm==0 ){
rc = unixOpenSharedMemory(pDbFd);
if( rc!=SQLITE_OK ) return rc;
}
unixLeaveMutex();
return SQLITE_OK;
p = pDbFd->pShm;
pShmNode = p->pShmNode;
sqlite3_mutex_enter(pShmNode->mutex);
assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 );
if( pShmNode->nRegion<=iRegion ){
char **apNew; /* New apRegion[] array */
int nByte = (iRegion+1)*szRegion; /* Minimum required file size */
struct stat sStat; /* Used by fstat() */
pShmNode->szRegion = szRegion;
/* The requested region is not mapped into this processes address space.
** Check to see if it has been allocated (i.e. if the wal-index file is
** large enough to contain the requested region).
*/
if( fstat(pShmNode->h, &sStat) ){
rc = SQLITE_IOERR_SHMSIZE;
goto shmpage_out;
}
if( sStat.st_size<nByte ){
/* The requested memory region does not exist. If bExtend is set to
** false, exit early. *pp will be set to NULL and SQLITE_OK returned.
**
** Alternatively, if bExtend is true, use ftruncate() to allocate
** the requested memory region.
*/
if( !bExtend ) goto shmpage_out;
if( ftruncate(pShmNode->h, nByte) ){
rc = SQLITE_IOERR_SHMSIZE;
goto shmpage_out;
}
}
/* Map the requested memory region into this processes address space. */
apNew = (char **)sqlite3_realloc(
pShmNode->apRegion, (iRegion+1)*sizeof(char *)
);
if( !apNew ){
rc = SQLITE_IOERR_NOMEM;
goto shmpage_out;
}
pShmNode->apRegion = apNew;
while(pShmNode->nRegion<=iRegion){
void *pMem = mmap(0, szRegion, PROT_READ|PROT_WRITE,
MAP_SHARED, pShmNode->h, iRegion*szRegion
);
if( pMem==MAP_FAILED ){
rc = SQLITE_IOERR;
goto shmpage_out;
}
pShmNode->apRegion[pShmNode->nRegion] = pMem;
pShmNode->nRegion++;
}
}
shmpage_out:
if( pShmNode->nRegion>iRegion ){
*pp = pShmNode->apRegion[iRegion];
}else{
*pp = 0;
}
sqlite3_mutex_leave(pShmNode->mutex);
return rc;
}
/*
@ -3552,107 +3605,60 @@ static void unixShmBarrier(
}
/*
** This function is called to obtain a pointer to region iRegion of the
** shared-memory associated with the database file fd. Shared-memory regions
** are numbered starting from zero. Each shared-memory region is szRegion
** bytes in size.
** Close a connection to shared-memory. Delete the underlying
** storage if deleteFlag is true.
**
** If an error occurs, an error code is returned and *pp is set to NULL.
**
** Otherwise, if the isWrite parameter is 0 and the requested shared-memory
** region has not been allocated (by any client, including one running in a
** separate process), then *pp is set to NULL and SQLITE_OK returned. If
** isWrite is non-zero and the requested shared-memory region has not yet
** been allocated, it is allocated by this function.
**
** If the shared-memory region has already been allocated or is allocated by
** this call as described above, then it is mapped into this processes
** address space (if it is not already), *pp is set to point to the mapped
** memory and SQLITE_OK returned.
** If there is no shared memory associated with the connection then this
** routine is a harmless no-op.
*/
static int unixShmMap(
sqlite3_file *fd, /* Handle open on database file */
int iRegion, /* Region to retrieve */
int szRegion, /* Size of regions */
int isWrite, /* True to extend file if necessary */
void volatile **pp /* OUT: Mapped memory */
static int unixShmUnmap(
sqlite3_file *fd, /* The underlying database file */
int deleteFlag /* Delete shared-memory if true */
){
unixFile *pDbFd = (unixFile*)fd;
unixShm *p = pDbFd->pShm;
unixShmNode *pShmNode = p->pShmNode;
int rc = SQLITE_OK;
unixShm *p; /* The connection to be closed */
unixShmNode *pShmNode; /* The underlying shared-memory file */
unixShm **pp; /* For looping over sibling connections */
unixFile *pDbFd; /* The underlying database file */
pDbFd = (unixFile*)fd;
p = pDbFd->pShm;
if( p==0 ) return SQLITE_OK;
pShmNode = p->pShmNode;
assert( pShmNode==pDbFd->pInode->pShmNode );
assert( pShmNode->pInode==pDbFd->pInode );
/* Remove connection p from the set of connections associated
** with pShmNode */
sqlite3_mutex_enter(pShmNode->mutex);
assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 );
for(pp=&pShmNode->pFirst; (*pp)!=p; pp = &(*pp)->pNext){}
*pp = p->pNext;
if( pShmNode->nRegion<=iRegion ){
char **apNew; /* New apRegion[] array */
int nByte = (iRegion+1)*szRegion; /* Minimum required file size */
struct stat sStat; /* Used by fstat() */
pShmNode->szRegion = szRegion;
/* The requested region is not mapped into this processes address space.
** Check to see if it has been allocated (i.e. if the wal-index file is
** large enough to contain the requested region).
*/
if( fstat(pShmNode->h, &sStat) ){
rc = SQLITE_IOERR_SHMSIZE;
goto shmpage_out;
}
if( sStat.st_size<nByte ){
/* The requested memory region does not exist. If isWrite is set to
** zero, exit early. *pp will be set to NULL and SQLITE_OK returned.
**
** Alternatively, if isWrite is non-zero, use ftruncate() to allocate
** the requested memory region.
*/
if( !isWrite ) goto shmpage_out;
if( ftruncate(pShmNode->h, nByte) ){
rc = SQLITE_IOERR_SHMSIZE;
goto shmpage_out;
}
}
/* Map the requested memory region into this processes address space. */
apNew = (char **)sqlite3_realloc(
pShmNode->apRegion, (iRegion+1)*sizeof(char *)
);
if( !apNew ){
rc = SQLITE_IOERR_NOMEM;
goto shmpage_out;
}
pShmNode->apRegion = apNew;
while(pShmNode->nRegion<=iRegion){
void *pMem = mmap(0, szRegion, PROT_READ|PROT_WRITE,
MAP_SHARED, pShmNode->h, iRegion*szRegion
);
if( pMem==MAP_FAILED ){
rc = SQLITE_IOERR;
goto shmpage_out;
}
pShmNode->apRegion[pShmNode->nRegion] = pMem;
pShmNode->nRegion++;
}
}
shmpage_out:
if( pShmNode->nRegion>iRegion ){
*pp = pShmNode->apRegion[iRegion];
}else{
*pp = 0;
}
/* Free the connection p */
sqlite3_free(p);
pDbFd->pShm = 0;
sqlite3_mutex_leave(pShmNode->mutex);
return rc;
/* If pShmNode->nRef has reached 0, then close the underlying
** shared-memory file, too */
unixEnterMutex();
assert( pShmNode->nRef>0 );
pShmNode->nRef--;
if( pShmNode->nRef==0 ){
if( deleteFlag ) unlink(pShmNode->zFilename);
unixShmPurge(pDbFd);
}
unixLeaveMutex();
return SQLITE_OK;
}
#else
# define unixShmOpen 0
# define unixShmLock 0
# define unixShmMap 0
# define unixShmLock 0
# define unixShmBarrier 0
# define unixShmClose 0
# define unixShmUnmap 0
#endif /* #ifndef SQLITE_OMIT_WAL */
/*
@ -3710,11 +3716,10 @@ static const sqlite3_io_methods METHOD = { \
unixFileControl, /* xFileControl */ \
unixSectorSize, /* xSectorSize */ \
unixDeviceCharacteristics, /* xDeviceCapabilities */ \
unixShmOpen, /* xShmOpen */ \
unixShmLock, /* xShmLock */ \
unixShmMap, /* xShmMap */ \
unixShmLock, /* xShmLock */ \
unixShmBarrier, /* xShmBarrier */ \
unixShmClose /* xShmClose */ \
unixShmUnmap /* xShmUnmap */ \
}; \
static const sqlite3_io_methods *FINDER##Impl(const char *z, unixFile *p){ \
UNUSED_PARAMETER(z); UNUSED_PARAMETER(p); \
@ -3731,7 +3736,7 @@ static const sqlite3_io_methods *(*const FINDER)(const char*,unixFile *p) \
IOMETHODS(
posixIoFinder, /* Finder function name */
posixIoMethods, /* sqlite3_io_methods object name */
2, /* ShmOpen is enabled */
2, /* shared memory is enabled */
unixClose, /* xClose method */
unixLock, /* xLock method */
unixUnlock, /* xUnlock method */
@ -3740,7 +3745,7 @@ IOMETHODS(
IOMETHODS(
nolockIoFinder, /* Finder function name */
nolockIoMethods, /* sqlite3_io_methods object name */
1, /* ShmOpen is disabled */
1, /* shared memory is disabled */
nolockClose, /* xClose method */
nolockLock, /* xLock method */
nolockUnlock, /* xUnlock method */
@ -3749,7 +3754,7 @@ IOMETHODS(
IOMETHODS(
dotlockIoFinder, /* Finder function name */
dotlockIoMethods, /* sqlite3_io_methods object name */
1, /* ShmOpen is disabled */
1, /* shared memory is disabled */
dotlockClose, /* xClose method */
dotlockLock, /* xLock method */
dotlockUnlock, /* xUnlock method */
@ -3760,7 +3765,7 @@ IOMETHODS(
IOMETHODS(
flockIoFinder, /* Finder function name */
flockIoMethods, /* sqlite3_io_methods object name */
1, /* ShmOpen is disabled */
1, /* shared memory is disabled */
flockClose, /* xClose method */
flockLock, /* xLock method */
flockUnlock, /* xUnlock method */
@ -3772,7 +3777,7 @@ IOMETHODS(
IOMETHODS(
semIoFinder, /* Finder function name */
semIoMethods, /* sqlite3_io_methods object name */
1, /* ShmOpen is disabled */
1, /* shared memory is disabled */
semClose, /* xClose method */
semLock, /* xLock method */
semUnlock, /* xUnlock method */
@ -3784,7 +3789,7 @@ IOMETHODS(
IOMETHODS(
afpIoFinder, /* Finder function name */
afpIoMethods, /* sqlite3_io_methods object name */
1, /* ShmOpen is disabled */
1, /* shared memory is disabled */
afpClose, /* xClose method */
afpLock, /* xLock method */
afpUnlock, /* xUnlock method */
@ -3809,7 +3814,7 @@ static int proxyCheckReservedLock(sqlite3_file*, int*);
IOMETHODS(
proxyIoFinder, /* Finder function name */
proxyIoMethods, /* sqlite3_io_methods object name */
1, /* ShmOpen is disabled */
1, /* shared memory is disabled */
proxyClose, /* xClose method */
proxyLock, /* xLock method */
proxyUnlock, /* xUnlock method */
@ -3822,7 +3827,7 @@ IOMETHODS(
IOMETHODS(
nfsIoFinder, /* Finder function name */
nfsIoMethods, /* sqlite3_io_methods object name */
1, /* ShmOpen is disabled */
1, /* shared memory is disabled */
unixClose, /* xClose method */
unixLock, /* xLock method */
nfsUnlock, /* xUnlock method */

View File

@ -1374,31 +1374,19 @@ static void winShmPurge(sqlite3_vfs *pVfs, int deleteFlag){
}
/*
** Open a shared-memory area. This particular implementation uses
** mmapped files.
**
** zName is a filename used to identify the shared-memory area. The
** implementation does not (and perhaps should not) use this name
** directly, but rather use it as a template for finding an appropriate
** name for the shared-memory storage. In this implementation, the
** string "-index" is appended to zName and used as the name of the
** mmapped file.
** Open the shared-memory area associated with database file pDbFd.
**
** When opening a new shared-memory file, if no other instances of that
** file are currently open, in this process or in other processes, then
** the file must be truncated to zero length or have its header cleared.
*/
static int winShmOpen(
sqlite3_file *fd /* The file to which to attach shared memory */
){
struct winFile *pDbFd; /* Database to which to attach SHM */
static int winOpenSharedMemory(winFile *pDbFd){
struct winShm *p; /* The connection to be opened */
struct winShmNode *pShmNode = 0; /* The underlying mmapped file */
int rc; /* Result code */
struct winShmNode *pNew; /* Newly allocated winShmNode */
int nName; /* Size of zName in bytes */
pDbFd = (winFile*)fd;
assert( pDbFd->pShm==0 ); /* Not previously opened */
/* Allocate space for the new sqlite3_shm object. Also speculatively
@ -1493,7 +1481,7 @@ shm_open_err:
** Close a connection to shared-memory. Delete the underlying
** storage if deleteFlag is true.
*/
static int winShmClose(
static int winShmUnmap(
sqlite3_file *fd, /* Database holding shared memory */
int deleteFlag /* Delete after closing if true */
){
@ -1680,9 +1668,16 @@ static int winShmMap(
){
winFile *pDbFd = (winFile*)fd;
winShm *p = pDbFd->pShm;
winShmNode *pShmNode = p->pShmNode;
winShmNode *pShmNode;
int rc = SQLITE_OK;
if( !p ){
rc = winOpenSharedMemory(pDbFd);
if( rc!=SQLITE_OK ) return rc;
p = pDbFd->pShm;
}
pShmNode = p->pShmNode;
sqlite3_mutex_enter(pShmNode->mutex);
assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 );
@ -1765,11 +1760,10 @@ shmpage_out:
}
#else
# define winShmOpen 0
# define winShmLock 0
# define winShmMap 0
# define winShmLock 0
# define winShmBarrier 0
# define winShmClose 0
# define winShmUnmap 0
#endif /* #ifndef SQLITE_OMIT_WAL */
/*
@ -1783,24 +1777,23 @@ shmpage_out:
** sqlite3_file for win32.
*/
static const sqlite3_io_methods winIoMethod = {
2, /* iVersion */
winClose,
winRead,
winWrite,
winTruncate,
winSync,
winFileSize,
winLock,
winUnlock,
winCheckReservedLock,
winFileControl,
winSectorSize,
winDeviceCharacteristics,
winShmOpen, /* xShmOpen */
winShmLock, /* xShmLock */
winShmMap, /* xShmMap */
winShmBarrier, /* xShmBarrier */
winShmClose /* xShmClose */
2, /* iVersion */
winClose, /* xClose */
winRead, /* xRead */
winWrite, /* xWrite */
winTruncate, /* xTruncate */
winSync, /* xSync */
winFileSize, /* xFileSize */
winLock, /* xLock */
winUnlock, /* xUnlock */
winCheckReservedLock, /* xCheckReservedLock */
winFileControl, /* xFileControl */
winSectorSize, /* xSectorSize */
winDeviceCharacteristics, /* xDeviceCharacteristics */
winShmMap, /* xShmMap */
winShmLock, /* xShmLock */
winShmBarrier, /* xShmBarrier */
winShmUnmap /* xShmUnmap */
};
/****************************************************************************

View File

@ -6023,7 +6023,7 @@ int sqlite3PagerWalCallback(Pager *pPager){
*/
int sqlite3PagerWalSupported(Pager *pPager){
const sqlite3_io_methods *pMethods = pPager->fd->pMethods;
return pMethods->iVersion>=2 && pMethods->xShmOpen!=0;
return pMethods->iVersion>=2 && pMethods->xShmMap!=0;
}
/*

View File

@ -480,7 +480,7 @@ int sqlite3_exec(
/*
** CAPI3REF: Device Characteristics
**
** The xDeviceCapabilities method of the [sqlite3_io_methods]
** The xDeviceCharacteristics method of the [sqlite3_io_methods]
** object returns an integer which is a vector of the these
** bit values expressing I/O characteristics of the mass storage
** device that holds the file that the [sqlite3_io_methods]
@ -660,11 +660,10 @@ struct sqlite3_io_methods {
int (*xSectorSize)(sqlite3_file*);
int (*xDeviceCharacteristics)(sqlite3_file*);
/* Methods above are valid for version 1 */
int (*xShmOpen)(sqlite3_file*);
int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
int (*xShmLock)(sqlite3_file*, int offset, int n, int flags);
int (*xShmMap)(sqlite3_file*, int iPage, int pgsz, int, void volatile**);
void (*xShmBarrier)(sqlite3_file*);
int (*xShmClose)(sqlite3_file*, int deleteFlag);
int (*xShmUnmap)(sqlite3_file*, int deleteFlag);
/* Methods above are valid for version 2 */
/* Additional methods may be added in future releases */
};
@ -887,13 +886,20 @@ struct sqlite3_vfs {
** With SQLITE_ACCESS_EXISTS, the xAccess method
** simply checks whether the file exists.
** With SQLITE_ACCESS_READWRITE, the xAccess method
** checks whether the file is both readable and writable.
** checks whether the named directory is both readable and writable
** (in other words, if files can be added, removed, and renamed within
** the directory).
** The SQLITE_ACCESS_READWRITE constant is currently used only by the
** [temp_store_directory pragma], though this could change in a future
** release of SQLite.
** With SQLITE_ACCESS_READ, the xAccess method
** checks whether the file is readable.
** checks whether the file is readable. The SQLITE_ACCESS_READ constant is
** currently unused, though it might be used in a future release of
** SQLite.
*/
#define SQLITE_ACCESS_EXISTS 0
#define SQLITE_ACCESS_READWRITE 1
#define SQLITE_ACCESS_READ 2
#define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */
#define SQLITE_ACCESS_READ 2 /* Unused */
/*
** CAPI3REF: Flags for the xShmLock VFS method

View File

@ -523,17 +523,14 @@ static int cfDeviceCharacteristics(sqlite3_file *pFile){
/*
** Pass-throughs for WAL support.
*/
static int cfShmOpen(sqlite3_file *pFile){
return sqlite3OsShmOpen(((CrashFile*)pFile)->pRealFile);
}
static int cfShmLock(sqlite3_file *pFile, int ofst, int n, int flags){
return sqlite3OsShmLock(((CrashFile*)pFile)->pRealFile, ofst, n, flags);
}
static void cfShmBarrier(sqlite3_file *pFile){
sqlite3OsShmBarrier(((CrashFile*)pFile)->pRealFile);
}
static int cfShmClose(sqlite3_file *pFile, int delFlag){
return sqlite3OsShmClose(((CrashFile*)pFile)->pRealFile, delFlag);
static int cfShmUnmap(sqlite3_file *pFile, int delFlag){
return sqlite3OsShmUnmap(((CrashFile*)pFile)->pRealFile, delFlag);
}
static int cfShmMap(
sqlite3_file *pFile, /* Handle open on database file */
@ -559,11 +556,10 @@ static const sqlite3_io_methods CrashFileVtab = {
cfFileControl, /* xFileControl */
cfSectorSize, /* xSectorSize */
cfDeviceCharacteristics, /* xDeviceCharacteristics */
cfShmOpen, /* xShmOpen */
cfShmLock, /* xShmLock */
cfShmMap, /* xShmMap */
cfShmLock, /* xShmLock */
cfShmBarrier, /* xShmBarrier */
cfShmClose /* xShmClose */
cfShmUnmap /* xShmUnmap */
};
/*

View File

@ -50,11 +50,10 @@ static int devsymCheckReservedLock(sqlite3_file*, int *);
static int devsymFileControl(sqlite3_file*, int op, void *pArg);
static int devsymSectorSize(sqlite3_file*);
static int devsymDeviceCharacteristics(sqlite3_file*);
static int devsymShmOpen(sqlite3_file*);
static int devsymShmLock(sqlite3_file*,int,int,int);
static int devsymShmMap(sqlite3_file*,int,int,int, void volatile **);
static void devsymShmBarrier(sqlite3_file*);
static int devsymShmClose(sqlite3_file*,int);
static int devsymShmUnmap(sqlite3_file*,int);
/*
** Method declarations for devsym_vfs.
@ -116,11 +115,10 @@ static sqlite3_io_methods devsym_io_methods = {
devsymFileControl, /* xFileControl */
devsymSectorSize, /* xSectorSize */
devsymDeviceCharacteristics, /* xDeviceCharacteristics */
devsymShmOpen, /* xShmOpen */
devsymShmLock, /* xShmLock */
devsymShmMap, /* xShmMap */
devsymShmLock, /* xShmLock */
devsymShmBarrier, /* xShmBarrier */
devsymShmClose /* xShmClose */
devsymShmUnmap /* xShmUnmap */
};
struct DevsymGlobal {
@ -237,10 +235,6 @@ static int devsymDeviceCharacteristics(sqlite3_file *pFile){
/*
** Shared-memory methods are all pass-thrus.
*/
static int devsymShmOpen(sqlite3_file *pFile){
devsym_file *p = (devsym_file *)pFile;
return sqlite3OsShmOpen(p->pReal);
}
static int devsymShmLock(sqlite3_file *pFile, int ofst, int n, int flags){
devsym_file *p = (devsym_file *)pFile;
return sqlite3OsShmLock(p->pReal, ofst, n, flags);
@ -259,9 +253,9 @@ static void devsymShmBarrier(sqlite3_file *pFile){
devsym_file *p = (devsym_file *)pFile;
sqlite3OsShmBarrier(p->pReal);
}
static int devsymShmClose(sqlite3_file *pFile, int delFlag){
static int devsymShmUnmap(sqlite3_file *pFile, int delFlag){
devsym_file *p = (devsym_file *)pFile;
return sqlite3OsShmClose(p->pReal, delFlag);
return sqlite3OsShmUnmap(p->pReal, delFlag);
}

View File

@ -219,11 +219,10 @@ static sqlite3_io_methods fs_io_methods = {
fsFileControl, /* xFileControl */
fsSectorSize, /* xSectorSize */
fsDeviceCharacteristics, /* xDeviceCharacteristics */
0, /* xShmOpen */
0, /* xShmLock */
0, /* xShmMap */
0, /* xShmLock */
0, /* xShmBarrier */
0 /* xShmClose */
0 /* xShmUnmap */
};
@ -241,11 +240,10 @@ static sqlite3_io_methods tmp_io_methods = {
tmpFileControl, /* xFileControl */
tmpSectorSize, /* xSectorSize */
tmpDeviceCharacteristics, /* xDeviceCharacteristics */
0, /* xShmOpen */
0, /* xShmLock */
0, /* xShmMap */
0, /* xShmLock */
0, /* xShmBarrier */
0 /* xShmClose */
0 /* xShmUnmap */
};
/* Useful macros used in several places */

View File

@ -98,8 +98,7 @@
#define OS_TRUNCATE 18
#define OS_UNLOCK 19
#define OS_WRITE 20
#define OS_SHMOPEN 21
#define OS_SHMCLOSE 22
#define OS_SHMUNMAP 22
#define OS_SHMMAP 23
#define OS_SHMLOCK 25
#define OS_SHMBARRIER 26
@ -149,11 +148,10 @@ static int vfslogFileControl(sqlite3_file*, int op, void *pArg);
static int vfslogSectorSize(sqlite3_file*);
static int vfslogDeviceCharacteristics(sqlite3_file*);
static int vfslogShmOpen(sqlite3_file *pFile);
static int vfslogShmLock(sqlite3_file *pFile, int ofst, int n, int flags);
static int vfslogShmMap(sqlite3_file *pFile,int,int,int,volatile void **);
static void vfslogShmBarrier(sqlite3_file*);
static int vfslogShmClose(sqlite3_file *pFile, int deleteFlag);
static int vfslogShmUnmap(sqlite3_file *pFile, int deleteFlag);
/*
** Method declarations for vfslog_vfs.
@ -209,11 +207,10 @@ static sqlite3_io_methods vfslog_io_methods = {
vfslogFileControl, /* xFileControl */
vfslogSectorSize, /* xSectorSize */
vfslogDeviceCharacteristics, /* xDeviceCharacteristics */
vfslogShmOpen, /* xShmOpen */
vfslogShmLock, /* xShmLock */
vfslogShmMap, /* xShmMap */
vfslogShmLock, /* xShmLock */
vfslogShmBarrier, /* xShmBarrier */
vfslogShmClose /* xShmClose */
vfslogShmUnmap /* xShmUnmap */
};
#if defined(SQLITE_OS_UNIX) && !defined(NO_GETTOD)
@ -423,16 +420,6 @@ static int vfslogDeviceCharacteristics(sqlite3_file *pFile){
return rc;
}
static int vfslogShmOpen(sqlite3_file *pFile){
int rc;
sqlite3_uint64 t;
VfslogFile *p = (VfslogFile *)pFile;
t = vfslog_time();
rc = p->pReal->pMethods->xShmOpen(p->pReal);
t = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_SHMOPEN, p->iFileId, t, rc, 0, 0);
return rc;
}
static int vfslogShmLock(sqlite3_file *pFile, int ofst, int n, int flags){
int rc;
sqlite3_uint64 t;
@ -467,14 +454,14 @@ static void vfslogShmBarrier(sqlite3_file *pFile){
t = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_SHMBARRIER, p->iFileId, t, SQLITE_OK, 0, 0);
}
static int vfslogShmClose(sqlite3_file *pFile, int deleteFlag){
static int vfslogShmUnmap(sqlite3_file *pFile, int deleteFlag){
int rc;
sqlite3_uint64 t;
VfslogFile *p = (VfslogFile *)pFile;
t = vfslog_time();
rc = p->pReal->pMethods->xShmClose(p->pReal, deleteFlag);
rc = p->pReal->pMethods->xShmUnmap(p->pReal, deleteFlag);
t = vfslog_time() - t;
vfslog_call(p->pVfslog, OS_SHMCLOSE, p->iFileId, t, rc, 0, 0);
vfslog_call(p->pVfslog, OS_SHMUNMAP, p->iFileId, t, rc, 0, 0);
return rc;
}
@ -794,8 +781,7 @@ static const char *vfslog_eventname(int eEvent){
case OS_SLEEP: zEvent = "xSleep"; break;
case OS_CURRENTTIME: zEvent = "xCurrentTime"; break;
case OS_SHMCLOSE: zEvent = "xShmClose"; break;
case OS_SHMOPEN: zEvent = "xShmOpen"; break;
case OS_SHMUNMAP: zEvent = "xShmUnmap"; break;
case OS_SHMLOCK: zEvent = "xShmLock"; break;
case OS_SHMBARRIER: zEvent = "xShmBarrier"; break;
case OS_SHMMAP: zEvent = "xShmMap"; break;

View File

@ -187,7 +187,7 @@ static int tvfsShmOpen(sqlite3_file*);
static int tvfsShmLock(sqlite3_file*, int , int, int);
static int tvfsShmMap(sqlite3_file*,int,int,int, void volatile **);
static void tvfsShmBarrier(sqlite3_file*);
static int tvfsShmClose(sqlite3_file*, int);
static int tvfsShmUnmap(sqlite3_file*, int);
static sqlite3_io_methods tvfs_io_methods = {
2, /* iVersion */
@ -203,11 +203,10 @@ static sqlite3_io_methods tvfs_io_methods = {
tvfsFileControl, /* xFileControl */
tvfsSectorSize, /* xSectorSize */
tvfsDeviceCharacteristics, /* xDeviceCharacteristics */
tvfsShmOpen, /* xShmOpen */
tvfsShmLock, /* xShmLock */
tvfsShmMap, /* xShmMap */
tvfsShmLock, /* xShmLock */
tvfsShmBarrier, /* xShmBarrier */
tvfsShmClose /* xShmClose */
tvfsShmUnmap /* xShmUnmap */
};
static int tvfsResultCode(Testvfs *p, int *pRc){
@ -580,15 +579,14 @@ static int tvfsOpen(
if( pVfs->iVersion>1 ){
nByte = sizeof(sqlite3_io_methods);
}else{
nByte = offsetof(sqlite3_io_methods, xShmOpen);
nByte = offsetof(sqlite3_io_methods, xShmMap);
}
pMethods = (sqlite3_io_methods *)ckalloc(nByte);
memcpy(pMethods, &tvfs_io_methods, nByte);
pMethods->iVersion = pVfs->iVersion;
if( pVfs->iVersion>1 && ((Testvfs *)pVfs->pAppData)->isNoshm ){
pMethods->xShmOpen = 0;
pMethods->xShmClose = 0;
pMethods->xShmUnmap = 0;
pMethods->xShmLock = 0;
pMethods->xShmBarrier = 0;
pMethods->xShmMap = 0;
@ -789,6 +787,13 @@ static int tvfsShmMap(
TestvfsFd *pFd = tvfsGetFd(pFile);
Testvfs *p = (Testvfs *)(pFd->pVfs->pAppData);
if( 0==pFd->pShm ){
rc = tvfsShmOpen(pFile);
if( rc!=SQLITE_OK ){
return rc;
}
}
if( p->pScript && p->mask&TESTVFS_SHMMAP_MASK ){
Tcl_Obj *pArg = Tcl_NewObj();
Tcl_IncrRefCount(pArg);
@ -888,7 +893,7 @@ static void tvfsShmBarrier(sqlite3_file *pFile){
}
}
static int tvfsShmClose(
static int tvfsShmUnmap(
sqlite3_file *pFile,
int deleteFlag
){
@ -898,10 +903,11 @@ static int tvfsShmClose(
TestvfsBuffer *pBuffer = pFd->pShm;
TestvfsFd **ppFd;
if( !pBuffer ) return SQLITE_OK;
assert( pFd->pShmId && pFd->pShm );
if( p->pScript && p->mask&TESTVFS_SHMCLOSE_MASK ){
tvfsExecTcl(p, "xShmClose",
tvfsExecTcl(p, "xShmUnmap",
Tcl_NewStringObj(pFd->pShm->zFile, -1), pFd->pShmId, 0
);
tvfsResultCode(p, &rc);
@ -1023,7 +1029,7 @@ static int testvfs_obj_cmd(
{ "xShmOpen", TESTVFS_SHMOPEN_MASK },
{ "xShmLock", TESTVFS_SHMLOCK_MASK },
{ "xShmBarrier", TESTVFS_SHMBARRIER_MASK },
{ "xShmClose", TESTVFS_SHMCLOSE_MASK },
{ "xShmUnmap", TESTVFS_SHMCLOSE_MASK },
{ "xShmMap", TESTVFS_SHMMAP_MASK },
{ "xSync", TESTVFS_SYNC_MASK },
{ "xDelete", TESTVFS_DELETE_MASK },

View File

@ -5213,11 +5213,11 @@ case OP_JournalMode: { /* out2-prerelease */
zFilename = sqlite3PagerFilename(pPager);
/* Do not allow a transition to journal_mode=WAL for a database
** in temporary storage or if the VFS does not support xShmOpen.
** in temporary storage or if the VFS does not support shared memory
*/
if( eNew==PAGER_JOURNALMODE_WAL
&& (zFilename[0]==0 /* Temp file */
|| !sqlite3PagerWalSupported(pPager)) /* No xShmOpen support */
|| !sqlite3PagerWalSupported(pPager)) /* No shared-memory support */
){
eNew = eOld;
}

View File

@ -413,7 +413,6 @@ struct Wal {
u16 szPage; /* Database page size */
i16 readLock; /* Which read lock is being held. -1 for none */
u8 exclusiveMode; /* Non-zero if connection is in exclusive mode */
u8 isWIndexOpen; /* True if ShmOpen() called on pDbFd */
u8 writeLock; /* True if in a write transaction */
u8 ckptLock; /* True if holding a checkpoint lock */
WalIndexHdr hdr; /* Wal-index header for current transaction */
@ -1168,10 +1167,7 @@ recovery_error:
** Close an open wal-index.
*/
static void walIndexClose(Wal *pWal, int isDelete){
if( pWal->isWIndexOpen ){
sqlite3OsShmClose(pWal->pDbFd, isDelete);
pWal->isWIndexOpen = 0;
}
sqlite3OsShmUnmap(pWal->pDbFd, isDelete);
}
/*
@ -1226,14 +1222,10 @@ int sqlite3WalOpen(
pRet->pDbFd = pDbFd;
pRet->readLock = -1;
pRet->zWalName = zWalName;
rc = sqlite3OsShmOpen(pDbFd);
/* Open file handle on the write-ahead log file. */
if( rc==SQLITE_OK ){
pRet->isWIndexOpen = 1;
flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_MAIN_JOURNAL);
rc = sqlite3OsOpen(pVfs, zWalName, pRet->pWalFd, flags, &flags);
}
flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_MAIN_JOURNAL);
rc = sqlite3OsOpen(pVfs, zWalName, pRet->pWalFd, flags, &flags);
if( rc!=SQLITE_OK ){
walIndexClose(pRet, 0);
@ -2204,8 +2196,10 @@ int sqlite3WalBeginWriteTransaction(Wal *pWal){
** routine merely releases the lock.
*/
int sqlite3WalEndWriteTransaction(Wal *pWal){
walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1);
pWal->writeLock = 0;
if( pWal->writeLock ){
walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1);
pWal->writeLock = 0;
}
return SQLITE_OK;
}