diff options
-rw-r--r-- | manifest | 18 | ||||
-rw-r--r-- | manifest.uuid | 2 | ||||
-rw-r--r-- | src/os_unix.c | 37 | ||||
-rw-r--r-- | src/os_win.c | 3 | ||||
-rw-r--r-- | test/attach2.test | 9 |
5 files changed, 40 insertions, 29 deletions
@@ -1,5 +1,5 @@ -C Change\sprototype\sfor\sbusy\scallbacks\sto\s"int\sxBusy(void\s*,\sint);"\s(CVS\s1573) -D 2004-06-12T01:43:26 +C Bug\sfix\sin\sthe\sunix\slocking\scode.\s(CVS\s1574) +D 2004-06-12T02:17:15 F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -44,9 +44,9 @@ F src/os.h 23c69c5084e71b5fe199ff1c4e35a4aded0f1380 F src/os_common.h 6393ac67a3a7b4aea19ff17529980ecf77eb2348 F src/os_mac.c b823874690615ace0dd520d3ad1fe8bfd864b7e0 F src/os_mac.h 51d2445f47e182ed32d3bd6937f81070c6fd9bd4 -F src/os_unix.c 1d6f3d1a87d4aa0e4490bcc47b3f0ff9b2e37e7a +F src/os_unix.c 7ece785e36c4ecb57c73db8d374b56912d742c4a F src/os_unix.h 1cd6133cf66dea704b8646b70b2dfdcbdd9b3738 -F src/os_win.c 6b8f9fcc683bb888e07fc485372803baa68faadb +F src/os_win.c d4009586dfd0543ca8956ff0be30f9d23e2cbbdd F src/os_win.h 004eec47b1780fcaf07420ddc2072294b698d48c F src/pager.c 4a2d3c871169385f7fe65c37919ced82cb3d34ed F src/pager.h ca8f293e1d623a7c628a1c5e0c6cf43d5bbb80bf @@ -80,7 +80,7 @@ F src/vdbemem.c 26cd5419a9c9e7a8959618376f04afdb433b77a3 F src/where.c dda77afaa593cd54e5955ec433076de18faf62f6 F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242 F test/attach.test aed659e52635662bcd5069599aaca823533edf5a -F test/attach2.test 01f55202c7984f9835b9195a5bff4b5c5f0316ee +F test/attach2.test e6b5f0d735cf8f6c14acfa2ce69b925dbe316b3e F test/attach3.test 8259ab833b5dcdf4acd75d9653f42f703ce2e013 F test/auth.test 95809b8f6a9bec18b94d28cafd03fe27d2f8a9e9 F test/bigfile.test ea904b853ce2d703b16c5ce90e2b54951bc1ae81 @@ -223,7 +223,7 @@ F www/support.tcl 1801397edd271cc39a2aadd54e701184b5181248 F www/tclsqlite.tcl 19191cf2a1010eaeff74c51d83fd5f5a4d899075 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4 -P 9b84f2f488e1d37ba1a4c4cf31490bcbba0f6edd -R 9710f09de77faaee2416768df891dc21 -U danielk1977 -Z f9730ca2955947853f997709fb7895ea +P 4f1cfca5ca703d0068cf8d6222dc8e0cfb7e24b6 +R 5ae96fc36d6708ebd2e3e17bdca09c44 +U drh +Z 179ef88834f751e9c7fc73c1211cbbf2 diff --git a/manifest.uuid b/manifest.uuid index 13bfa8eb7..c63ce0546 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4f1cfca5ca703d0068cf8d6222dc8e0cfb7e24b6
\ No newline at end of file +dcad244f58453d23f2bcb749dcea077434bbd08c
\ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index d62cfdd08..37a04f38b 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -733,7 +733,6 @@ int sqlite3OsLock(OsFile *id, int locktype){ */ if( (id->locktype!=pLock->locktype && (pLock->locktype>=PENDING_LOCK || locktype>SHARED_LOCK)) - || (locktype==EXCLUSIVE_LOCK && pLock->cnt>1) ){ rc = SQLITE_BUSY; goto end_lock; @@ -757,16 +756,13 @@ int sqlite3OsLock(OsFile *id, int locktype){ lock.l_len = 1L; lock.l_whence = SEEK_SET; - /* If control gets to this point, then actually go ahead and make - ** operating system calls for the specified lock. + /* A PENDING lock is needed before acquiring a SHARED lock and before + ** acquiring an EXCLUSIVE lock. For the SHARED lock, the PENDING will + ** be released. */ - if( locktype==SHARED_LOCK ){ - assert( pLock->cnt==0 ); - assert( pLock->locktype==0 ); - - /* Temporarily grab a PENDING lock. This prevents new SHARED locks from - ** being formed if a PENDING lock is already held. - */ + if( locktype==SHARED_LOCK + || (locktype==EXCLUSIVE_LOCK && id->locktype<PENDING_LOCK) + ){ lock.l_type = F_RDLCK; lock.l_start = PENDING_BYTE; s = fcntl(id->h, F_SETLK, &lock); @@ -774,6 +770,15 @@ int sqlite3OsLock(OsFile *id, int locktype){ rc = (errno==EINVAL) ? SQLITE_NOLFS : SQLITE_BUSY; goto end_lock; } + } + + + /* If control gets to this point, then actually go ahead and make + ** operating system calls for the specified lock. + */ + if( locktype==SHARED_LOCK ){ + assert( pLock->cnt==0 ); + assert( pLock->locktype==0 ); /* Now get the read-lock */ lock.l_start = SHARED_FIRST; @@ -792,8 +797,12 @@ int sqlite3OsLock(OsFile *id, int locktype){ id->pOpen->nLock++; pLock->cnt = 1; } + }else if( locktype==EXCLUSIVE_LOCK && pLock->cnt>1 ){ + /* We are trying for an exclusive lock but another thread in this + ** same process is still holding a shared lock. */ + rc = SQLITE_BUSY; }else{ - /* The request was for a RESERVED, PENDING or EXCLUSIVE lock. It is + /* The request was for a RESERVED or EXCLUSIVE lock. It is ** assumed that there is a SHARED or greater lock on the file ** already. */ @@ -803,9 +812,6 @@ int sqlite3OsLock(OsFile *id, int locktype){ case RESERVED_LOCK: lock.l_start = RESERVED_BYTE; break; - case PENDING_LOCK: - lock.l_start = PENDING_BYTE; - break; case EXCLUSIVE_LOCK: lock.l_start = SHARED_FIRST; lock.l_len = SHARED_SIZE; @@ -822,6 +828,9 @@ int sqlite3OsLock(OsFile *id, int locktype){ if( rc==SQLITE_OK ){ id->locktype = locktype; pLock->locktype = locktype; + }else if( locktype==EXCLUSIVE_LOCK ){ + id->locktype = PENDING_LOCK; + pLock->locktype = PENDING_LOCK; } end_lock: diff --git a/src/os_win.c b/src/os_win.c index 217a61cbb..b729c0f68 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -420,6 +420,7 @@ int sqlite3OsLock(OsFile *id, int locktype){ ** a SHARED lock. If we are acquiring a SHARED lock, the acquisition of ** the PENDING_LOCK byte is temporary. */ + newLocktype = id->locktype; if( id->locktype==NO_LOCK || (locktype==EXCLUSIVE_LOCK && id->locktype==RESERVED_LOCK) ){ @@ -536,7 +537,7 @@ int sqlite3OsCheckReservedLock(OsFile *id){ int sqlite3OsUnlock(OsFile *id, int locktype){ int rc, type; assert( locktype<=SHARED_LOCK ); - TRACE4("UNLOCK %d to %d was %d(%d)\n", id->h, locktype, + TRACE5("UNLOCK %d to %d was %d(%d)\n", id->h, locktype, id->locktype, id->sharedLockByte); type = id->locktype; if( type>=EXCLUSIVE_LOCK ){ diff --git a/test/attach2.test b/test/attach2.test index 2008dbbc6..4a8b9c034 100644 --- a/test/attach2.test +++ b/test/attach2.test @@ -12,7 +12,7 @@ # focus of this script is testing the ATTACH and DETACH commands # and related functionality. # -# $Id: attach2.test,v 1.15 2004/06/09 21:01:12 drh Exp $ +# $Id: attach2.test,v 1.16 2004/06/12 02:17:15 drh Exp $ # set testdir [file dirname $argv0] @@ -263,7 +263,6 @@ do_test attach2-4.9 { lock_status 4.9.1 db {main shared temp reserved file2 shared} lock_status 4.9.2 db2 {main reserved temp reserved file2 reserved} -set sqlite_os_trace 0 btree_breakpoint do_test attach2-4.10 { # We cannot commit db2 while db is holding a read-lock @@ -271,15 +270,17 @@ do_test attach2-4.10 { } {1 {database is locked}} lock_status 4.10.1 db {main shared temp reserved file2 shared} -lock_status 4.10.2 db2 {main reserved temp reserved file2 reserved} +lock_status 4.10.2 db2 {main pending temp reserved file2 reserved} +set sqlite_os_trace 0 +btree_breakpoint do_test attach2-4.11 { # db is able to commit. catchsql {COMMIT} } {0 {}} lock_status 4.11.1 db {main unlocked temp unlocked file2 unlocked} -lock_status 4.11.2 db2 {main reserved temp reserved file2 reserved} +lock_status 4.11.2 db2 {main pending temp reserved file2 reserved} do_test attach2-4.12 { # Now we can commit db2 |