**
*************************************************************************
**
-** $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))
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, ...){
fprintf(stderr, "[%d] %s", 0 /* (int)pthread_self() */, z);
sqlite3_free(z);
}
+#endif
/*
** THREAD SAFETY NOTES
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
** 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.
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 ){
pLock = 0;
}
}
-#endif
if( pLock ){
pLock->nFile = pData->nName;
pLock->zFile = &((char *)(&pLock[1]))[pVfs->szOsFile];
&& eWhen!=SQLITEASYNC_HALT_NOW
&& eWhen!=SQLITEASYNC_HALT_IDLE
){
- return SQLITE_ERROR;
+ return SQLITE_MISUSE;
}
async.eHalt = eWhen;
async_mutex_enter(ASYNC_MUTEX_QUEUE);
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 *);
*piDelay = async.ioDelay;
break;
}
+ case SQLITEASYNC_GET_LOCKFILES: {
+ int *piDelay = va_arg(ap, int *);
+ *piDelay = async.bLockFiles;
+ break;
+ }
default:
return SQLITE_ERROR;
-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
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
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
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