Rename the unused MEM2 static mutex to OPEN and reuse it to serialize access

to the sqlite3BtreeOpen() routine to prevent a race condition on detection
of sharable caches.  Ticket #3735. (CVS 6363)

FossilOrigin-Name: 19fa5a29b97f017a9e176e48c848100299ba6920
This commit is contained in:
drh 2009-03-20 13:15:30 +00:00
parent df0f3c06b6
commit 7555d8ec40
6 changed files with 35 additions and 25 deletions

View File

@ -1,5 +1,5 @@
C Fix\sa\sproblem\sin\sthread005.test\scause\serrors\son\sosx.\s(CVS\s6362)
D 2009-03-20T10:24:04
C Rename\sthe\sunused\sMEM2\sstatic\smutex\sto\sOPEN\sand\sreuse\sit\sto\sserialize\saccess\nto\sthe\ssqlite3BtreeOpen()\sroutine\sto\sprevent\sa\srace\scondition\son\sdetection\nof\ssharable\scaches.\s\sTicket\s#3735.\s(CVS\s6363)
D 2009-03-20T13:15:30
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 583e87706abc3026960ed759aff6371faf84c211
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -103,7 +103,7 @@ F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
F src/backup.c 0082d0e5a63f04e88faee0dff0a7d63d3e92a78d
F src/bitvec.c 44f7059ac1f874d364b34af31b9617e52223ba75
F src/btmutex.c 341502bc496dc0840dcb00cde65680fb0e85c3ab
F src/btree.c 081e1aac3ce4c79c5ed628a1fec533857d175eea
F src/btree.c 4fbb5f26f450bee7356ec63cb664c8d733e28d89
F src/btree.h e302c5747494067cd4f5763000fbe7bca767d816
F src/btreeInt.h 17697718bb5281b12da5c65ecb0bffc45f2c0125
F src/build.c c816377c118047418fda81edb8866b9c7a4e4031
@ -157,7 +157,7 @@ F src/resolve.c 094e44450371fb27869eb8bf679aacbe51fdc56d
F src/rowset.c ba9375f37053d422dd76965a9c370a13b6e1aac4
F src/select.c 4d0b77fd76ff80f09a798ee98953e344c9de8fbb
F src/shell.c 0a11f831603f17fea20ca97133c0f64e716af4a7
F src/sqlite.h.in 0f756e9e8db9d491d0f17ea9c07952974975e43d
F src/sqlite.h.in 0db1e59d89aeacb8fe64a19fd14c13a796060ccb
F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17
F src/sqliteInt.h 250be86c98646e0d48436d6455b6fe916742bffa
F src/sqliteLimit.h ffe93f5a0c4e7bd13e70cd7bf84cfb5c3465f45d
@ -185,7 +185,7 @@ F src/test_journal.c 632011e420a581614343e78bc2fe77bd409a1706
F src/test_loadext.c 97dc8800e46a46ed002c2968572656f37e9c0dd9
F src/test_malloc.c d23050c7631ec9ee0369c7ca905e6c9233968e11
F src/test_md5.c 032ae2bb6f81da350d2404e81fa8d560c8268026
F src/test_mutex.c 87d99bdad7fb5d9aa4b5c7cf42423cfbf56eba2c
F src/test_mutex.c 482d9d987c1c678199691efc23c8cd3464e01ff5
F src/test_onefile.c 1efd91e63ce3d92e8331bfed83854e2b4dcd2e72
F src/test_osinst.c 9a70a61e127f9e72bcfca000b20368b1c5367873
F src/test_pcache.c 29464896d9c67832e4eef916c0682b98d7283d00
@ -475,7 +475,7 @@ F test/misc5.test 6a5c1e3217a95b0db05ff9a0f1ecb5ce9043ffef
F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91
F test/misc7.test debcd7dbfd847ae97b16ceb7fec6f567902874a6
F test/misuse.test 30b3a458e5a70c31e74c291937b6c82204c59f33
F test/mutex1.test 1e5c196d5170bbe3a7d8370b1b905e8c86a9e07c
F test/mutex1.test ace3ba551ef0cd864df2b820b5dbe18d28b4db6c
F test/mutex2.test bfeaeac2e73095b2ac32285d2756e3a65e681660
F test/nan.test c627d79b3d36ea892563fd67584b3e8a18f0618a
F test/notify1.test 9a985a94f34de1b24daf25fd86b6d5033ba532d0
@ -709,7 +709,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
P 18680989b5365b0e35fadca5919dfced22433ff4
R 84c3a02fa54e49a7eceb26ef6ca40a97
U danielk1977
Z 7df2e0e297e433d337cbcfc3fa681e86
P 56e6fca1a9da69c3a0fe43b00db9a6d9d93f03ba
R e2b2822c930e07999a7faadbecce8455
U drh
Z 94771809e81ff193bb7785b130c75e1e

View File

@ -1 +1 @@
56e6fca1a9da69c3a0fe43b00db9a6d9d93f03ba
19fa5a29b97f017a9e176e48c848100299ba6920

View File

@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: btree.c,v 1.575 2009/03/18 10:33:01 danielk1977 Exp $
** $Id: btree.c,v 1.576 2009/03/20 13:15:30 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information.
@ -42,6 +42,8 @@ int sqlite3BtreeTrace=0; /* True to enable tracing */
** in shared cache. This variable has file scope during normal builds,
** but the test harness needs to access it so we make it global for
** test builds.
**
** Access to this variable is protected by SQLITE_MUTEX_STATIC_MASTER.
*/
#ifdef SQLITE_TEST
BtShared *SQLITE_WSD sqlite3SharedCacheList = 0;
@ -1334,12 +1336,13 @@ int sqlite3BtreeOpen(
int flags, /* Options */
int vfsFlags /* Flags passed through to sqlite3_vfs.xOpen() */
){
sqlite3_vfs *pVfs; /* The VFS to use for this btree */
BtShared *pBt = 0; /* Shared part of btree structure */
Btree *p; /* Handle to return */
int rc = SQLITE_OK;
u8 nReserve;
unsigned char zDbHeader[100];
sqlite3_vfs *pVfs; /* The VFS to use for this btree */
BtShared *pBt = 0; /* Shared part of btree structure */
Btree *p; /* Handle to return */
sqlite3_mutex *mutexOpen = 0; /* Prevents a race condition. Ticket #3537 */
int rc = SQLITE_OK; /* Result code from this function */
u8 nReserve; /* Byte of unused space on each page */
unsigned char zDbHeader[100]; /* Database header content */
/* Set the variable isMemdb to true for an in-memory database, or
** false for a file-based database. This symbol is only required if
@ -1385,6 +1388,8 @@ int sqlite3BtreeOpen(
return SQLITE_NOMEM;
}
sqlite3OsFullPathname(pVfs, zFilename, nFullPathname, zFullPathname);
mutexOpen = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_OPEN);
sqlite3_mutex_enter(mutexOpen);
mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
sqlite3_mutex_enter(mutexShared);
for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
@ -1538,6 +1543,10 @@ btree_open_out:
sqlite3_free(p);
*ppBtree = 0;
}
if( mutexOpen ){
assert( sqlite3_mutex_held(mutexOpen) );
sqlite3_mutex_leave(mutexOpen);
}
return rc;
}

View File

@ -30,7 +30,7 @@
** the version number) and changes its name to "sqlite3.h" as
** part of the build process.
**
** @(#) $Id: sqlite.h.in,v 1.435 2009/03/16 13:37:02 drh Exp $
** @(#) $Id: sqlite.h.in,v 1.436 2009/03/20 13:15:30 drh Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
@ -4726,7 +4726,8 @@ int sqlite3_mutex_notheld(sqlite3_mutex*);
#define SQLITE_MUTEX_RECURSIVE 1
#define SQLITE_MUTEX_STATIC_MASTER 2
#define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */
#define SQLITE_MUTEX_STATIC_MEM2 4 /* sqlite3_release_memory() */
#define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */
#define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */
#define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_random() */
#define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
#define SQLITE_MUTEX_STATIC_LRU2 7 /* lru page list */

View File

@ -10,7 +10,7 @@
**
*************************************************************************
**
** $Id: test_mutex.c,v 1.14 2009/02/11 05:18:07 danielk1977 Exp $
** $Id: test_mutex.c,v 1.15 2009/03/20 13:15:30 drh Exp $
*/
#include "tcl.h"
@ -248,7 +248,7 @@ static int test_read_mutex_counters(
int ii;
char *aName[8] = {
"fast", "recursive", "static_master", "static_mem",
"static_mem2", "static_prng", "static_lru", "static_lru2"
"static_open", "static_prng", "static_lru", "static_lru2"
};
if( objc!=1 ){

View File

@ -9,7 +9,7 @@
#
#***********************************************************************
#
# $Id: mutex1.test,v 1.17 2009/01/09 14:29:35 drh Exp $
# $Id: mutex1.test,v 1.18 2009/03/20 13:15:31 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -101,8 +101,8 @@ set enable_shared_cache [sqlite3_enable_shared_cache 1]
ifcapable threadsafe {
foreach {mode mutexes} {
singlethread {}
multithread {fast static_lru static_master static_mem static_prng }
serialized {fast recursive static_lru static_master static_mem static_prng}
multithread {fast static_lru static_master static_mem static_open static_prng }
serialized {fast recursive static_lru static_master static_mem static_open static_prng}
} {
do_test mutex1.2.$mode.1 {