-C Version\s2.0.2\s(CVS\s281)
-D 2001-10-09T04:21:51
+C More\schanges\sprior\sto\srelease\s2.0.2.\s\sMostly\scomment\schanges.\s\sBut\sthere\nwas\salso\sa\sminor\schange\sto\stemptable.test\sso\sthat\sit\swould\swork\sunder\nWindows.\s(CVS\s282)
+D 2001-10-09T12:39:24
F Makefile.in 98d4627cb364537e4c3a29ee806171f3abf5211a
F Makefile.template 1e54087c0390c4ce0bb5be43e14ba028283751e6
F README 93d2977cc5c6595c448de16bdefc312b9d401533
F src/insert.c a48ba850461b203fb8dbc7add83fc6b6a9cf47f3
F src/main.c 87b2fca50cbe8b400e1443b2c73693e18d9911cb
F src/md5.c 52f677bfc590e09f71d07d7e327bd59da738d07c
-F src/os.c 64d0015bfc9edcb6380ce6fc75b31c73490f4c7b
+F src/os.c a83f4cb85e4d3b98c1659a799f9e318fcaf1c76c
F src/os.h bed702c9e3b768bc3cb1b12c90b83d099c1546be
F src/pager.c 3445bd7c18cbfdffd8d6d1077f0b2bdf788da4fe
F src/pager.h a0d4c5ae271914aa07b62aee0707997d6932b6ca
F test/table.test 3ef4254d62ece31a3872ab11cdaec846f6fa8fd1
F test/tableapi.test 162840153191a91a7dce6395f2334f9aef713b37
F test/tclsqlite.test a57bb478d7e9f0b2c927f92e161f391e2896631a
-F test/temptable.test 9576d30a6809a3233310163fee9ae8d4b9d27f54
+F test/temptable.test 37acd9e39781c2ff7cff2ba741b6b27ce020a44a
F test/tester.tcl c7ddeebc14cc841abb37134cd5d40c1e3ad367c1
F test/trans.test 855337b8a178c73c433fcf8ee88e4b2f5efff0d9
F test/unique.test ef1f67607a7109e9c0842cd8557550fb121d7ec6
F www/arch.png 82ef36db1143828a7abc88b1e308a5f55d4336f4
F www/arch.tcl 03b521d252575f93b9c52f7c8b0007011512fcfb
F www/c_interface.tcl 8e8d9e66e8467c5751116c3427296bde77f474a6
-F www/changes.tcl 6c25c0098cddde028e04d8ce7b59f58359a0fa1f
+F www/changes.tcl 2b416b49a136312678317f509821cf9359e421b5
F www/crosscompile.tcl c99efacb3aefaa550c6e80d91b240f55eb9fd33e
F www/download.tcl 3e51c9ff1326b0a182846134987301310dff7d60
F www/dynload.tcl 02eb8273aa78cfa9070dd4501dca937fb22b466c
F www/sqlite.tcl 6a21242a272e9c0939a04419a51c3d50cae33e3e
F www/tclsqlite.tcl 13d50723f583888fc80ae1a38247c0ab415066fa
F www/vdbe.tcl bb7d620995f0a987293e9d4fb6185a3b077e9b44
-P 484b82d8a1c84f3d9725a509de93276b9fa9b294
-R e0211f7ef81f1015b59b3a33ae8ec9df
+P 765359c77ebae22e42b78636e70a57b010aaa18e
+R 00a3f33de80cb8fb5006abe2246012c5
U drh
-Z 085c67f80b7bd57b2ee9d6e92b91d085
+Z 8201536b58eae125c25ac9ac5ab95d7d
#if OS_UNIX
+/*
+** Here is the dirt on POSIX advisory locks: ANSI STD 1003.1 (1996)
+** section 6.5.2.2 lines 483 through 490 specify that when a process
+** sets or clears a lock, that operation overrides any prior locks set
+** by the same process. It does not explicitly say so, but this implies
+** that it overrides locks set by the same process using a different
+** file descriptor. Consider this test case:
+**
+** int fd1 = open("./file1", O_RDWR|O_CREAT, 0644);
+** int fd2 = open("./file2", O_RDWR|O_CREAT, 0644);
+**
+** Suppose ./file1 and ./file2 are really be the same file (because
+** one is a hard or symbolic link to the other) then if you set
+** an exclusive lock on fd1, then try to get an exclusive lock
+** on fd2, it works. I would have expected the second lock to
+** fail since there was already a lock on the file due to fd1.
+** But not so. Since both locks came from the same process, the
+** second overrides the first, even though they were on different
+** file descriptors opened on different file names.
+**
+** Bummer. If you ask me, this is broken. Badly broken. It means
+** that we cannot use POSIX locks to synchronize file access among
+** competing threads of the same process. POSIX locks will work fine
+** to synchronize access for threads in separate processes, but not
+** threads within the same process.
+**
+** To work around the problem, SQLite has to manage file locks internally
+** on its own. Whenever a new database is opened, we have to find the
+** specific inode of the database file (the inode is determined by the
+** st_dev and st_ino fields of the stat structure the stat() fills in)
+** and check for locks already existing on that inode. When locks are
+** created or removed, we have to look at our own internal record of the
+** locks to see if another thread has previously set a lock on that same
+** inode.
+**
+** The OsFile structure for POSIX is no longer just an integer file
+** descriptor. It is now a structure that holds the integer file
+** descriptor and a pointer to a structure that describes the internal
+** locks on the corresponding inode. There is one locking structure
+** per inode, so if the same inode is opened twice, both OsFile structures
+** point to the same locking structure. The locking structure keeps
+** a reference count (so we will know when to delete it) and a "cnt"
+** field that tells us its internal lock status. cnt==0 means the
+** file is unlocked. cnt==-1 means the file has an exclusive lock.
+** cnt>0 means there are cnt shared locks on the file.
+**
+** Any attempt to lock or unlock a file first checks the locking
+** structure. The fcntl() system call is only invoked to set a
+** POSIX lock if the internal lock structure transitions between
+** a locked and an unlocked state.
+*/
+
/*
** An instance of the following structure serves as the key used
** to locate a particular lockInfo structure given its inode.
/*
** An instance of the following structure is allocated for each inode.
-** A single inode can have multiple file descriptors, so each OsFile structure
-** contains a pointer to an instance of this object.
+** A single inode can have multiple file descriptors, so each OsFile
+** structure contains a pointer to an instance of this object and this
+** object keeps a count of the number of OsFiles pointing to it.
*/
struct lockInfo {
struct inodeKey key; /* The lookup key */
/*
** Given a file descriptor, locate a lockInfo structure that describes
-** that file descriptor. Create a new one if necessary.
+** that file descriptor. Create a new one if necessary. NULL might
+** be returned if malloc() fails.
*/
static struct lockInfo *findLockInfo(int fd){
int rc;
pInfo = (struct lockInfo*)sqliteHashFind(&lockHash, &key, sizeof(key));
if( pInfo==0 ){
pInfo = sqliteMalloc( sizeof(*pInfo) );
+ if( pInfo==0 ) return 0;
pInfo->key = key;
pInfo->nRef = 1;
pInfo->cnt = 0;
sqliteFree(pInfo);
}
}
-#endif
+#endif /** POSIX advisory lock work-around **/
/*