]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Make selecting the asynchronous IO file-locking mode a runtime operation. Still untes...
authordanielk1977 <danielk1977@noemail.net>
Fri, 24 Apr 2009 10:13:05 +0000 (10:13 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Fri, 24 Apr 2009 10:13:05 +0000 (10:13 +0000)
FossilOrigin-Name: 577277e84a05707b8c21aa08bc5fc314c1ac38ac

ext/async/sqlite3async.c
manifest
manifest.uuid
src/test_async.c

index f1fdb8d87f78c4cc201330b49448dda9a89d6df3..586a749c8b2c0234f8fd0e93c5a1e37366ab7d01 100644 (file)
@@ -10,7 +10,7 @@
 **
 *************************************************************************
 **
-** $Id: sqlite3async.c,v 1.2 2009/04/24 09:27:16 danielk1977 Exp $
+** $Id: sqlite3async.c,v 1.3 2009/04/24 10:13:06 danielk1977 Exp $
 **
 ** This file contains the implementation of an asynchronous IO backend 
 ** for SQLite.
 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ASYNCIO)
 
 #include "sqlite3async.h"
-
-#define ENABLE_FILE_LOCKING
+#include "sqlite3.h"
+#include <stdarg.h>
+#include <string.h>
+#include <assert.h>
 
 /* Useful macros used in several places */
 #define MIN(x,y) ((x)<(y)?(x):(y))
@@ -34,6 +36,8 @@ typedef struct AsyncFileLock AsyncFileLock;
 typedef struct AsyncLock AsyncLock;
 
 /* Enable for debugging */
+#ifndef NDEBUG
+#include <stdio.h>
 static int sqlite3async_trace = 0;
 # define ASYNC_TRACE(X) if( sqlite3async_trace ) asyncTrace X
 static void asyncTrace(const char *zFormat, ...){
@@ -45,6 +49,7 @@ static void asyncTrace(const char *zFormat, ...){
   fprintf(stderr, "[%d] %s", 0 /* (int)pthread_self() */, z);
   sqlite3_free(z);
 }
+#endif
 
 /*
 ** THREAD SAFETY NOTES
@@ -374,9 +379,10 @@ static struct TestAsyncStaticData {
   AsyncLock *pLock;            /* Linked list of all AsyncLock structures */
   volatile int ioDelay;        /* Extra delay between write operations */
   volatile int eHalt;          /* One of the SQLITEASYNC_HALT_XXX values */
+  volatile int bLockFiles;     /* Current value of "lockfiles" parameter */
   int ioError;                 /* True if an IO error has occurred */
   int nFile;                   /* Number of open files (from sqlite pov) */
-} async = { 0,0,0,0,0,0,0 };
+} async = { 0,0,0,0,0,1,0,0 };
 
 /* Possible values of AsyncWrite.op */
 #define ASYNC_NOOP          0
@@ -456,11 +462,11 @@ struct AsyncWrite {
 ** structures, one for each handle currently open on the file.
 **
 ** If the opened file is not a main-database (the SQLITE_OPEN_MAIN_DB is
-** not passed to the sqlite3OsOpen() call), or if ENABLE_FILE_LOCKING is 
-** not defined at compile time, variables AsyncLock.pFile and 
-** AsyncLock.eLock are never used. Otherwise, pFile is a file handle
-** opened on the file in question and used to obtain the file-system 
-** locks required by database connections within this process.
+** not passed to the sqlite3OsOpen() call), or if async.bLockFiles is 
+** false, variables AsyncLock.pFile and AsyncLock.eLock are never used. 
+** Otherwise, pFile is a file handle opened on the file in question and 
+** used to obtain the file-system locks required by database connections 
+** within this process.
 **
 ** See comments above the asyncLock() function for more details on 
 ** the implementation of database locking used by this backend.
@@ -1064,8 +1070,7 @@ static int asyncOpen(
       pLock = (AsyncLock *)sqlite3_malloc(nByte);
       if( pLock ){
         memset(pLock, 0, nByte);
-#ifdef ENABLE_FILE_LOCKING
-        if( flags&SQLITE_OPEN_MAIN_DB ){
+        if( async.bLockFiles && (flags&SQLITE_OPEN_MAIN_DB) ){
           pLock->pFile = (sqlite3_file *)&pLock[1];
           rc = pVfs->xOpen(pVfs, pData->zName, pLock->pFile, flags, 0);
           if( rc!=SQLITE_OK ){
@@ -1073,7 +1078,6 @@ static int asyncOpen(
             pLock = 0;
           }
         }
-#endif
         if( pLock ){
           pLock->nFile = pData->nName;
           pLock->zFile = &((char *)(&pLock[1]))[pVfs->szOsFile];
@@ -1607,7 +1611,7 @@ int sqlite3async_control(int op, ...){
        && eWhen!=SQLITEASYNC_HALT_NOW
        && eWhen!=SQLITEASYNC_HALT_IDLE
       ){
-        return SQLITE_ERROR;
+        return SQLITE_MISUSE;
       }
       async.eHalt = eWhen;
       async_mutex_enter(ASYNC_MUTEX_QUEUE);
@@ -1618,9 +1622,24 @@ int sqlite3async_control(int op, ...){
 
     case SQLITEASYNC_DELAY: {
       int iDelay = va_arg(ap, int);
+      if( iDelay<0 ){
+        return SQLITE_MISUSE;
+      }
       async.ioDelay = iDelay;
       break;
     }
+
+    case SQLITEASYNC_LOCKFILES: {
+      int bLock = va_arg(ap, int);
+      async_mutex_enter(ASYNC_MUTEX_QUEUE);
+      if( async.nFile || async.pQueueFirst ){
+        async_mutex_leave(ASYNC_MUTEX_QUEUE);
+        return SQLITE_MISUSE;
+      }
+      async.bLockFiles = bLock;
+      async_mutex_leave(ASYNC_MUTEX_QUEUE);
+      break;
+    }
       
     case SQLITEASYNC_GET_HALT: {
       int *peWhen = va_arg(ap, int *);
@@ -1632,6 +1651,11 @@ int sqlite3async_control(int op, ...){
       *piDelay = async.ioDelay;
       break;
     }
+    case SQLITEASYNC_GET_LOCKFILES: {
+      int *piDelay = va_arg(ap, int *);
+      *piDelay = async.bLockFiles;
+      break;
+    }
 
     default:
       return SQLITE_ERROR;
index a39099d4bd7a1c9f89f8977a017dbc18410cc06a..6f59881380d38f87417695ef73176da5658fe0f1 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Improve\scomments\sand\sdocumentation\sof\sthe\sasynchronous\sIO\sVFS\smodule.\s(CVS\s6543)
-D 2009-04-24T09:27:16
+C Make\sselecting\sthe\sasynchronous\sIO\sfile-locking\smode\sa\sruntime\soperation.\sStill\suntested.\s(CVS\s6544)
+D 2009-04-24T10:13:06
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in 583e87706abc3026960ed759aff6371faf84c211
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -25,7 +25,7 @@ F doc/lemon.html f0f682f50210928c07e562621c3b7e8ab912a538
 F doc/report1.txt a031aaf37b185e4fa540223cb516d3bccec7eeac
 F ext/README.txt 913a7bd3f4837ab14d7e063304181787658b14e1
 F ext/async/README.txt 0c541f418b14b415212264cbaaf51c924ec62e5b
-F ext/async/sqlite3async.c 2975386c0422dc44e8beebbb85988524141ef8b9
+F ext/async/sqlite3async.c 35eddf1c696c7ab9c92934dec9ff251896d93439
 F ext/async/sqlite3async.h b6d74dbf9aa5a0ac4e79aa15a4d987f3552a0f75
 F ext/fts1/README.txt 20ac73b006a70bcfd80069bdaf59214b6cf1db5e
 F ext/fts1/ft_hash.c 3927bd880e65329bdc6f506555b228b28924921b
@@ -176,7 +176,7 @@ F src/test6.c 1a0a7a1f179469044b065b4a88aab9faee114101
 F src/test7.c b94e68c2236de76889d82b8d7d8e00ad6a4d80b1
 F src/test8.c b1061548f7ce3aeedea3cc4d649ee1487c2b4eaf
 F src/test9.c 963d380922f25c1c323712d05db01b19197ee6f7
-F src/test_async.c 95c15d9085ea9a837a5c4332a9ae3a8df1afd2cd
+F src/test_async.c d17e8c21461474d807ca1ee6a51f21210df7cf64
 F src/test_autoext.c f53b0cdf7bf5f08100009572a5d65cdb540bd0ad
 F src/test_backup.c 1384a18985a5a2d275c2662e48473bf1542ebd08
 F src/test_btree.c d7b8716544611c323860370ee364e897c861f1b0
@@ -723,7 +723,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P 18fef3fcf61c137a89a83352f6769ed06845434a
-R 848783e3f0d8b2c2ee5a000cbb3565d6
+P 92bc6be2a86f8a68ceded2bc08fe7d6ff23b56fb
+R d1fe56ed7757cac24f050d623f1a6f33
 U danielk1977
-Z a232dc6b75d11d81cd6e819ebf60dfe9
+Z 741711df9244c68ea2afca1186c054bc
index d5507003450403562cd57bdc532b7467cb6b4bba..d20afd5002f061b57cd6aad0e2f241156fc540d5 100644 (file)
@@ -1 +1 @@
-92bc6be2a86f8a68ceded2bc08fe7d6ff23b56fb
\ No newline at end of file
+577277e84a05707b8c21aa08bc5fc314c1ac38ac
\ No newline at end of file
index 7e0107a7a83800501b47172ac2bd26261375c7e7..8787d4c22c19cc2ee964f4c8bf8a9b970712b9c6 100644 (file)
@@ -10,7 +10,7 @@
 **
 *************************************************************************
 **
-** $Id: test_async.c,v 1.59 2009/04/23 14:58:40 danielk1977 Exp $
+** $Id: test_async.c,v 1.60 2009/04/24 10:13:06 danielk1977 Exp $
 **
 ** This file contains a binding of the asynchronous IO extension interface
 ** (defined in ext/async/sqlite3async.h) to Tcl.
@@ -160,13 +160,11 @@ static int testAsyncStart(
 
   rc = Tcl_CreateThread(&x, tclWriterThread, threadData, nStack, flags);
   if( rc!=TCL_OK ){
+    Tcl_AppendResult(interp, "Tcl_CreateThread() failed", 0);
     return TCL_ERROR;
   }
-  while( isStarted==0 ){
-#if 0
-    sched_yield();
-#endif
-  }
+
+  while( isStarted==0 ) { /* Busy loop */ }
   return TCL_OK;
 }