From 16aaf451b75d5237be071d9e656d3863a7f490a2 Mon Sep 17 00:00:00 2001 From: mike Date: Thu, 17 Oct 2002 09:01:31 +0000 Subject: [PATCH] Minor coding fix in getting the windows platform version, when multithreading (CVS 761) FossilOrigin-Name: b53ab71d074ada47ce22bd161f6aee24587302af --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/os.c | 45 +++++++++++++++++++++++++-------------------- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/manifest b/manifest index 1ab61d3fde..3e37875125 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C fix\sfor\slocking\sin\sWindows\s(CVS\s760) -D 2002-10-17T00:38:54 +C Minor\scoding\sfix\sin\sgetting\sthe\swindows\splatform\sversion,\swhen\smultithreading\s(CVS\s761) +D 2002-10-17T09:01:32 F Makefile.in d6c9a85c2a5e696843201d090dcf8bf2f8716f2a F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -30,7 +30,7 @@ F src/hash.h cd0433998bc1a3759d244e1637fe5a3c13b53bf8 F src/insert.c 764300a0bd8074a2174946c0bf8a550bd833397a F src/main.c ff7c05ef88fa1374e5540ce20173ae8e1836f8a4 F src/md5.c fe4f9c9c6f71dfc26af8da63e4d04489b1430565 -F src/os.c 2c26f354c4bbe94ba4d6e1f04289c63bc1fdb87c +F src/os.c c045297aae5a99710222baf939985498c5bb76d4 F src/os.h 3009379b06941e7796a9812d1b6cbc59b26248c8 F src/pager.c 592e5931fdc65e952a6c3e152bc822580856532a F src/pager.h 6991c9c2dc5e4c7f2df4d4ba47d1c6458f763a32 @@ -149,7 +149,7 @@ F www/speed.tcl a20a792738475b68756ea7a19321600f23d1d803 F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218 -P d87a886d8f63f54466848151e2b0e8565b338593 -R bf058781dafbb0c6ad71e236c2683985 +P 83add34f64895a4b465881213eba82f3b1f5c964 +R b18c7ccdbae2c5e8036c38df73751405 U mike -Z 02abffa2bb18c0118ab5f6d1ca430ce7 +Z c44f29d11b8dd47ea375422490d2c34d diff --git a/manifest.uuid b/manifest.uuid index fe6ca9e26b..9903bc000b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -83add34f64895a4b465881213eba82f3b1f5c964 \ No newline at end of file +b53ab71d074ada47ce22bd161f6aee24587302af \ No newline at end of file diff --git a/src/os.c b/src/os.c index 43374f9f86..ae29b37b6d 100644 --- a/src/os.c +++ b/src/os.c @@ -90,14 +90,14 @@ static int last_page = 0; ** 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 +** 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. +** to locate a particular lockInfo structure given its inode. */ struct inodeKey { dev_t dev; /* Device number */ @@ -116,7 +116,7 @@ struct lockInfo { int nRef; /* Number of pointers to this structure */ }; -/* +/* ** This hash table maps inodes (in the form of inodeKey structures) into ** pointers to lockInfo structures. */ @@ -236,7 +236,7 @@ int sqliteOsOpenReadWrite( if( id->fd<0 ){ id->fd = open(zFilename, O_RDONLY); if( id->fd<0 ){ - return SQLITE_CANTOPEN; + return SQLITE_CANTOPEN; } *pReadonly = 1; }else{ @@ -328,7 +328,7 @@ int sqliteOsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){ HANDLE h; int fileflags; if( delFlag ){ - fileflags = FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_RANDOM_ACCESS + fileflags = FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_RANDOM_ACCESS | FILE_FLAG_DELETE_ON_CLOSE; }else{ fileflags = FILE_FLAG_RANDOM_ACCESS; @@ -448,7 +448,7 @@ int sqliteOsTempFileName(char *zBuf){ if( !sqliteOsFileExists(zBuf) ) break; } #endif - return SQLITE_OK; + return SQLITE_OK; } /* @@ -642,19 +642,24 @@ int sqliteOsFileSize(OsFile *id, int *pSize){ // get the platform id to decide how to calculate the lock offset int mkPlatformId(void){ - + static long init=0; + static long lock=0; + static int pid=VER_PLATFORM_WIN32_WINDOWS; - OSVERSIONINFOA info; - - if (!init) { - if (InterlockedIncrement(&init)==1) + OSVERSIONINFOA info; + + while (!init) { + if (InterlockedIncrement(&lock)==1) { info.dwOSVersionInfoSize=sizeof(info); - if (GetVersionEx(&info)) pid=info.dwPlatformId; + if (GetVersionEx(&info)) pid=info.dwPlatformId; + init=1; } - } - return pid; + else + Sleep(1); + } + return pid; } // locks and unlocks beyond eof. uses platformid to move the lock as far as possible. @@ -676,11 +681,11 @@ int mkunlock(HANDLE h, WORD base, WORD size) //obtain the sync lock on a handle -void synclock(HANDLE h){ +void synclock(HANDLE h){ while (!mklock(h,0,1)) Sleep(1); } -void syncunlock(HANDLE h){ +void syncunlock(HANDLE h){ mkunlock(h,0,1); } @@ -729,12 +734,12 @@ int sqliteOsReadLock(OsFile *id){ }else{ int lk = (sqliteRandomInteger() & 0x7ffffff)%MX_LOCKBYTE + 1; int res; - + synclock(id->h); if (id->locked<0) mkunlock(id->h,1,MX_LOCKBYTE); // release write lock if we have it res=mklock(id->h,lk,1); syncunlock(id->h); - + if( res ){ id->locked = lk; rc = SQLITE_OK; @@ -778,12 +783,12 @@ int sqliteOsWriteLock(OsFile *id){ rc = SQLITE_OK; }else{ int res; - + synclock(id->h); if (id->locked>0) mkunlock(id->h,id->locked,1); // release read lock res=mklock(id->h,1,MX_LOCKBYTE); syncunlock(id->h); - + if(res){ id->locked = -1; rc = SQLITE_OK;