mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-05 15:55:57 +03:00
A better fix for ticket #530 - one that is likely to work on unix
implementations in addition to linux. Also more tests for multi-thread locking added. (CVS 1138) FossilOrigin-Name: 7dddbeb586504de30c64a1e61614da447f18c8ba
This commit is contained in:
21
src/os.c
21
src/os.c
@@ -168,14 +168,15 @@ static unsigned int elapse;
|
||||
|
||||
/*
|
||||
** An instance of the following structure serves as the key used
|
||||
** to locate a particular lockInfo structure given its inode.
|
||||
** to locate a particular lockInfo structure given its inode. Note
|
||||
** that we have to include the process ID as part of the key. On some
|
||||
** threading implementations (ex: linux), each thread has a separate
|
||||
** process ID.
|
||||
*/
|
||||
struct inodeKey {
|
||||
struct lockKey {
|
||||
dev_t dev; /* Device number */
|
||||
ino_t ino; /* Inode number */
|
||||
#ifdef SQLITE_UNIX_THREADS
|
||||
pthread_t thread_id; /* Which thread are we */
|
||||
#endif
|
||||
pid_t pid; /* Process ID */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -185,13 +186,13 @@ struct inodeKey {
|
||||
** object keeps a count of the number of OsFiles pointing to it.
|
||||
*/
|
||||
struct lockInfo {
|
||||
struct inodeKey key; /* The lookup key */
|
||||
struct lockKey key; /* The lookup key */
|
||||
int cnt; /* 0: unlocked. -1: write lock. 1...: read lock. */
|
||||
int nRef; /* Number of pointers to this structure */
|
||||
};
|
||||
|
||||
/*
|
||||
** This hash table maps inodes (in the form of inodeKey structures) into
|
||||
** This hash table maps inodes (in the form of lockKey structures) into
|
||||
** pointers to lockInfo structures.
|
||||
*/
|
||||
static Hash lockHash = { SQLITE_HASH_BINARY, 0, 0, 0, 0, 0 };
|
||||
@@ -203,7 +204,7 @@ static Hash lockHash = { SQLITE_HASH_BINARY, 0, 0, 0, 0, 0 };
|
||||
*/
|
||||
static struct lockInfo *findLockInfo(int fd){
|
||||
int rc;
|
||||
struct inodeKey key;
|
||||
struct lockKey key;
|
||||
struct stat statbuf;
|
||||
struct lockInfo *pInfo;
|
||||
rc = fstat(fd, &statbuf);
|
||||
@@ -211,9 +212,7 @@ static struct lockInfo *findLockInfo(int fd){
|
||||
memset(&key, 0, sizeof(key));
|
||||
key.dev = statbuf.st_dev;
|
||||
key.ino = statbuf.st_ino;
|
||||
#ifdef SQLITE_UNIX_THREADS
|
||||
key.thread_id = pthread_self();
|
||||
#endif
|
||||
key.pid = getpid();
|
||||
pInfo = (struct lockInfo*)sqliteHashFind(&lockHash, &key, sizeof(key));
|
||||
if( pInfo==0 ){
|
||||
struct lockInfo *pOld;
|
||||
|
Reference in New Issue
Block a user