aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielk1977 <danielk1977@noemail.net>2009-04-24 10:13:05 +0000
committerdanielk1977 <danielk1977@noemail.net>2009-04-24 10:13:05 +0000
commit4598b8e4a102f2d38e90483758681a1f3379878a (patch)
tree81c8dc18341fe2ef228197b2a1f2998ffb0512b0
parentdebcfd2dcb2f2f628dde7b1ae0a1c5359e7df610 (diff)
downloadsqlite-4598b8e4a102f2d38e90483758681a1f3379878a.tar.gz
sqlite-4598b8e4a102f2d38e90483758681a1f3379878a.zip
Make selecting the asynchronous IO file-locking mode a runtime operation. Still untested. (CVS 6544)
FossilOrigin-Name: 577277e84a05707b8c21aa08bc5fc314c1ac38ac
-rw-r--r--ext/async/sqlite3async.c50
-rw-r--r--manifest14
-rw-r--r--manifest.uuid2
-rw-r--r--src/test_async.c10
4 files changed, 49 insertions, 27 deletions
diff --git a/ext/async/sqlite3async.c b/ext/async/sqlite3async.c
index f1fdb8d87..586a749c8 100644
--- a/ext/async/sqlite3async.c
+++ b/ext/async/sqlite3async.c
@@ -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.
@@ -19,8 +19,10 @@
#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;
diff --git a/manifest b/manifest
index a39099d4b..6f5988138 100644
--- 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
diff --git a/manifest.uuid b/manifest.uuid
index d55070034..d20afd500 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-92bc6be2a86f8a68ceded2bc08fe7d6ff23b56fb \ No newline at end of file
+577277e84a05707b8c21aa08bc5fc314c1ac38ac \ No newline at end of file
diff --git a/src/test_async.c b/src/test_async.c
index 7e0107a7a..8787d4c22 100644
--- a/src/test_async.c
+++ b/src/test_async.c
@@ -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;
}