Cherry-pick [555fc07]:
Changes to the thread routines to disable them when threading is turned off using sqlite3_config(). Also merge all recent trunk changes. FossilOrigin-Name: c92b0fe1371e7c20a5fbdf5fa96e30da14c40880
This commit is contained in:
+2
-2
@@ -1461,7 +1461,7 @@ static int btreeInitPage(MemPage *pPage){
|
||||
size = get2byte(&data[pc+2]);
|
||||
if( (next>0 && next<=pc+size+3) || pc+size>usableSize ){
|
||||
/* Free blocks must be in ascending order. And the last byte of
|
||||
** the free-block must lie on the database page. */
|
||||
** the free-block must lie on the database page. */
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
nFree = nFree + size;
|
||||
@@ -2635,7 +2635,7 @@ int sqlite3BtreeBeginTrans(Btree *p, int wrflag){
|
||||
pBt->nTransaction++;
|
||||
#ifndef SQLITE_OMIT_SHARED_CACHE
|
||||
if( p->sharable ){
|
||||
assert( p->lock.pBtree==p && p->lock.iTable==1 );
|
||||
assert( p->lock.pBtree==p && p->lock.iTable==1 );
|
||||
p->lock.eLock = READ_LOCK;
|
||||
p->lock.pNext = pBt->pLock;
|
||||
pBt->pLock = &p->lock;
|
||||
|
||||
+1
-1
@@ -534,7 +534,7 @@ void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
|
||||
if( !db || db->pnBytesFreed==0 ){
|
||||
char *zName = pIndex->zName;
|
||||
TESTONLY ( Index *pOld = ) sqlite3HashInsert(
|
||||
&pIndex->pSchema->idxHash, zName, sqlite3Strlen30(zName), 0
|
||||
&pIndex->pSchema->idxHash, zName, sqlite3Strlen30(zName), 0
|
||||
);
|
||||
assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
|
||||
assert( pOld==pIndex || pOld==0 );
|
||||
|
||||
+2
-2
@@ -231,14 +231,14 @@ static int sqlite3MemInit(void *NotUsed){
|
||||
}else{
|
||||
/* only 1 core, use our own zone to contention over global locks,
|
||||
** e.g. we have our own dedicated locks */
|
||||
bool success;
|
||||
bool success;
|
||||
malloc_zone_t* newzone = malloc_create_zone(4096, 0);
|
||||
malloc_set_zone_name(newzone, "Sqlite_Heap");
|
||||
do{
|
||||
success = OSAtomicCompareAndSwapPtrBarrier(NULL, newzone,
|
||||
(void * volatile *)&_sqliteZone_);
|
||||
}while(!_sqliteZone_);
|
||||
if( !success ){
|
||||
if( !success ){
|
||||
/* somebody registered a zone first */
|
||||
malloc_destroy_zone(newzone);
|
||||
}
|
||||
|
||||
+10
-10
@@ -715,9 +715,9 @@ static int sqliteErrorFromPosixError(int posixError, int sqliteIOErr) {
|
||||
case EACCES:
|
||||
/* EACCES is like EAGAIN during locking operations, but not any other time*/
|
||||
if( (sqliteIOErr == SQLITE_IOERR_LOCK) ||
|
||||
(sqliteIOErr == SQLITE_IOERR_UNLOCK) ||
|
||||
(sqliteIOErr == SQLITE_IOERR_RDLOCK) ||
|
||||
(sqliteIOErr == SQLITE_IOERR_CHECKRESERVEDLOCK) ){
|
||||
(sqliteIOErr == SQLITE_IOERR_UNLOCK) ||
|
||||
(sqliteIOErr == SQLITE_IOERR_RDLOCK) ||
|
||||
(sqliteIOErr == SQLITE_IOERR_CHECKRESERVEDLOCK) ){
|
||||
return SQLITE_BUSY;
|
||||
}
|
||||
/* else fall through */
|
||||
@@ -1764,7 +1764,7 @@ static int posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){
|
||||
pInode->eFileLock = NO_LOCK;
|
||||
}else{
|
||||
rc = SQLITE_IOERR_UNLOCK;
|
||||
pFile->lastErrno = errno;
|
||||
pFile->lastErrno = errno;
|
||||
pInode->eFileLock = NO_LOCK;
|
||||
pFile->eFileLock = NO_LOCK;
|
||||
}
|
||||
@@ -1780,7 +1780,7 @@ static int posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){
|
||||
closePendingFds(pFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
end_unlock:
|
||||
unixLeaveMutex();
|
||||
if( rc==SQLITE_OK ) pFile->eFileLock = eFileLock;
|
||||
@@ -2047,7 +2047,7 @@ static int dotlockUnlock(sqlite3_file *id, int eFileLock) {
|
||||
|
||||
assert( pFile );
|
||||
OSTRACE(("UNLOCK %d %d was %d pid=%d (dotlock)\n", pFile->h, eFileLock,
|
||||
pFile->eFileLock, getpid()));
|
||||
pFile->eFileLock, getpid()));
|
||||
assert( eFileLock<=SHARED_LOCK );
|
||||
|
||||
/* no-op if possible */
|
||||
@@ -2434,7 +2434,7 @@ static int semUnlock(sqlite3_file *id, int eFileLock) {
|
||||
assert( pFile );
|
||||
assert( pSem );
|
||||
OSTRACE(("UNLOCK %d %d was %d pid=%d (sem)\n", pFile->h, eFileLock,
|
||||
pFile->eFileLock, getpid()));
|
||||
pFile->eFileLock, getpid()));
|
||||
assert( eFileLock<=SHARED_LOCK );
|
||||
|
||||
/* no-op if possible */
|
||||
@@ -3024,7 +3024,7 @@ static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){
|
||||
if( newOffset == -1 ){
|
||||
((unixFile*)id)->lastErrno = errno;
|
||||
}else{
|
||||
((unixFile*)id)->lastErrno = 0;
|
||||
((unixFile*)id)->lastErrno = 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -3112,7 +3112,7 @@ static int seekAndWrite(unixFile *id, i64 offset, const void *pBuf, int cnt){
|
||||
if( newOffset == -1 ){
|
||||
((unixFile*)id)->lastErrno = errno;
|
||||
}else{
|
||||
((unixFile*)id)->lastErrno = 0;
|
||||
((unixFile*)id)->lastErrno = 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -5626,7 +5626,7 @@ static int unixGetLastError(sqlite3_vfs *NotUsed, int NotUsed2, char *NotUsed3){
|
||||
** address in the shared range is taken for a SHARED lock, the entire
|
||||
** shared range is taken for an EXCLUSIVE lock):
|
||||
**
|
||||
** PENDING_BYTE 0x40000000
|
||||
** PENDING_BYTE 0x40000000
|
||||
** RESERVED_BYTE 0x40000001
|
||||
** SHARED_RANGE 0x40000002 -> 0x40000200
|
||||
**
|
||||
|
||||
@@ -46,9 +46,11 @@
|
||||
# define FILE_ATTRIBUTE_MASK (0x0003FFF7)
|
||||
#endif
|
||||
|
||||
#ifndef SQLITE_OMIT_WAL
|
||||
/* Forward references */
|
||||
typedef struct winShm winShm; /* A connection to shared-memory */
|
||||
typedef struct winShmNode winShmNode; /* A region of shared-memory */
|
||||
#endif
|
||||
|
||||
/*
|
||||
** WinCE lacks native support for file locking so we have to fake it
|
||||
@@ -76,7 +78,9 @@ struct winFile {
|
||||
short sharedLockByte; /* Randomly chosen byte used as a shared lock */
|
||||
u8 ctrlFlags; /* Flags. See WINFILE_* below */
|
||||
DWORD lastErrno; /* The Windows errno from the last I/O error */
|
||||
#ifndef SQLITE_OMIT_WAL
|
||||
winShm *pShm; /* Instance of shared memory on this file */
|
||||
#endif
|
||||
const char *zPath; /* Full pathname of this file */
|
||||
int szChunk; /* Chunk size configured by FCNTL_CHUNK_SIZE */
|
||||
#if SQLITE_OS_WINCE
|
||||
@@ -1937,7 +1941,9 @@ static int winClose(sqlite3_file *id){
|
||||
winFile *pFile = (winFile*)id;
|
||||
|
||||
assert( id!=0 );
|
||||
#ifndef SQLITE_OMIT_WAL
|
||||
assert( pFile->pShm==0 );
|
||||
#endif
|
||||
OSTRACE(("CLOSE %d\n", pFile->h));
|
||||
do{
|
||||
rc = osCloseHandle(pFile->h);
|
||||
@@ -3687,7 +3693,9 @@ static int winOpen(
|
||||
pFile->h = h;
|
||||
pFile->lastErrno = NO_ERROR;
|
||||
pFile->pVfs = pVfs;
|
||||
#ifndef SQLITE_OMIT_WAL
|
||||
pFile->pShm = 0;
|
||||
#endif
|
||||
pFile->zPath = zName;
|
||||
if( sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE) ){
|
||||
pFile->ctrlFlags |= WINFILE_PSOW;
|
||||
|
||||
+4
-1
@@ -3154,8 +3154,11 @@ typedef struct sqlite3_context sqlite3_context;
|
||||
** ^(In those routines that have a fourth argument, its value is the
|
||||
** number of bytes in the parameter. To be clear: the value is the
|
||||
** number of <u>bytes</u> in the value, not the number of characters.)^
|
||||
** ^If the fourth parameter is negative, the length of the string is
|
||||
** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
|
||||
** is negative, then the length of the string is
|
||||
** the number of bytes up to the first zero terminator.
|
||||
** If the fourth parameter to sqlite3_bind_blob() is negative, then
|
||||
** the behavior is undefined.
|
||||
** If a non-negative fourth parameter is provided to sqlite3_bind_text()
|
||||
** or sqlite3_bind_text16() then that parameter must be the byte offset
|
||||
** where the NUL terminator would occur assuming the string were NUL
|
||||
|
||||
+1
-1
@@ -5928,7 +5928,7 @@ static int optimization_control(
|
||||
sqlite3 *db;
|
||||
const char *zOpt;
|
||||
int onoff;
|
||||
int mask;
|
||||
int mask = 0;
|
||||
static const struct {
|
||||
const char *zOptName;
|
||||
int mask;
|
||||
|
||||
@@ -319,6 +319,12 @@ static void set_options(Tcl_Interp *interp){
|
||||
Tcl_SetVar2(interp, "sqlite_options", "fts3_unicode", "0", TCL_GLOBAL_ONLY);
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_DISABLE_FTS4_DEFERRED
|
||||
Tcl_SetVar2(interp, "sqlite_options", "fts4_deferred", "0", TCL_GLOBAL_ONLY);
|
||||
#else
|
||||
Tcl_SetVar2(interp, "sqlite_options", "fts4_deferred", "1", TCL_GLOBAL_ONLY);
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_OMIT_GET_TABLE
|
||||
Tcl_SetVar2(interp, "sqlite_options", "gettable", "0", TCL_GLOBAL_ONLY);
|
||||
#else
|
||||
|
||||
@@ -502,11 +502,11 @@ static int multiplexOpen(
|
||||
){
|
||||
int rc = SQLITE_OK; /* Result code */
|
||||
multiplexConn *pMultiplexOpen; /* The new multiplex file descriptor */
|
||||
multiplexGroup *pGroup; /* Corresponding multiplexGroup object */
|
||||
multiplexGroup *pGroup = 0; /* Corresponding multiplexGroup object */
|
||||
sqlite3_file *pSubOpen = 0; /* Real file descriptor */
|
||||
sqlite3_vfs *pOrigVfs = gMultiplex.pOrigVfs; /* Real VFS */
|
||||
int nName;
|
||||
int sz;
|
||||
int nName = 0;
|
||||
int sz = 0;
|
||||
char *zToFree = 0;
|
||||
|
||||
UNUSED_PARAMETER(pVfs);
|
||||
|
||||
+26
-14
@@ -659,7 +659,7 @@ static int editDist3ConfigLoad(
|
||||
int rc, rc2;
|
||||
char *zSql;
|
||||
int iLangPrev = -9999;
|
||||
EditDist3Lang *pLang;
|
||||
EditDist3Lang *pLang = 0;
|
||||
|
||||
zSql = sqlite3_mprintf("SELECT iLang, cFrom, cTo, iCost"
|
||||
" FROM \"%w\" WHERE iLang>=0 ORDER BY iLang", zTable);
|
||||
@@ -680,7 +680,7 @@ static int editDist3ConfigLoad(
|
||||
assert( zTo!=0 || nTo==0 );
|
||||
if( nFrom>100 || nTo>100 ) continue;
|
||||
if( iCost<0 ) continue;
|
||||
if( iLang!=iLangPrev ){
|
||||
if( pLang==0 || iLang!=iLangPrev ){
|
||||
EditDist3Lang *pNew;
|
||||
pNew = sqlite3_realloc(p->a, (p->nLang+1)*sizeof(p->a[0]));
|
||||
if( pNew==0 ){ rc = SQLITE_NOMEM; break; }
|
||||
@@ -863,9 +863,9 @@ static void updateCost(
|
||||
int j,
|
||||
int iCost
|
||||
){
|
||||
int b;
|
||||
assert( iCost>=0 );
|
||||
if( iCost<10000 ){
|
||||
b = m[j] + iCost;
|
||||
unsigned int b = m[j] + iCost;
|
||||
if( b<m[i] ) m[i] = b;
|
||||
}
|
||||
}
|
||||
@@ -2508,15 +2508,17 @@ static int spellfix1Filter(
|
||||
*/
|
||||
static int spellfix1Next(sqlite3_vtab_cursor *cur){
|
||||
spellfix1_cursor *pCur = (spellfix1_cursor *)cur;
|
||||
int rc = SQLITE_OK;
|
||||
if( pCur->iRow < pCur->nRow ){
|
||||
if( pCur->pFullScan ){
|
||||
int rc = sqlite3_step(pCur->pFullScan);
|
||||
rc = sqlite3_step(pCur->pFullScan);
|
||||
if( rc!=SQLITE_ROW ) pCur->iRow = pCur->nRow;
|
||||
if( rc==SQLITE_ROW || rc==SQLITE_DONE ) rc = SQLITE_OK;
|
||||
}else{
|
||||
pCur->iRow++;
|
||||
}
|
||||
}
|
||||
return SQLITE_OK;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2773,25 +2775,35 @@ static sqlite3_module spellfix1Module = {
|
||||
** Register the various functions and the virtual table.
|
||||
*/
|
||||
static int spellfix1Register(sqlite3 *db){
|
||||
int nErr = 0;
|
||||
int rc = SQLITE_OK;
|
||||
int i;
|
||||
nErr += sqlite3_create_function(db, "spellfix1_translit", 1, SQLITE_UTF8, 0,
|
||||
rc = sqlite3_create_function(db, "spellfix1_translit", 1, SQLITE_UTF8, 0,
|
||||
transliterateSqlFunc, 0, 0);
|
||||
nErr += sqlite3_create_function(db, "spellfix1_editdist", 2, SQLITE_UTF8, 0,
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3_create_function(db, "spellfix1_editdist", 2, SQLITE_UTF8, 0,
|
||||
editdistSqlFunc, 0, 0);
|
||||
nErr += sqlite3_create_function(db, "spellfix1_phonehash", 1, SQLITE_UTF8, 0,
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3_create_function(db, "spellfix1_phonehash", 1, SQLITE_UTF8, 0,
|
||||
phoneticHashSqlFunc, 0, 0);
|
||||
nErr += sqlite3_create_function(db, "spellfix1_scriptcode", 1, SQLITE_UTF8, 0,
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3_create_function(db, "spellfix1_scriptcode", 1, SQLITE_UTF8, 0,
|
||||
scriptCodeSqlFunc, 0, 0);
|
||||
nErr += sqlite3_create_module(db, "spellfix1", &spellfix1Module, 0);
|
||||
nErr += editDist3Install(db);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3_create_module(db, "spellfix1", &spellfix1Module, 0);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = editDist3Install(db);
|
||||
}
|
||||
|
||||
/* Verify sanity of the translit[] table */
|
||||
for(i=0; i<sizeof(translit)/sizeof(translit[0])-1; i++){
|
||||
assert( translit[i].cFrom<translit[i+1].cFrom );
|
||||
}
|
||||
|
||||
return nErr ? SQLITE_ERROR : SQLITE_OK;
|
||||
return rc;
|
||||
}
|
||||
|
||||
#if SQLITE_CORE || defined(SQLITE_TEST)
|
||||
|
||||
+32
-12
@@ -36,6 +36,8 @@
|
||||
/* A running thread */
|
||||
struct SQLiteThread {
|
||||
pthread_t tid;
|
||||
int done;
|
||||
void *pOut;
|
||||
};
|
||||
|
||||
/* Create a new thread */
|
||||
@@ -52,10 +54,12 @@ int sqlite3ThreadCreate(
|
||||
*ppThread = 0;
|
||||
p = sqlite3Malloc(sizeof(*p));
|
||||
if( p==0 ) return SQLITE_NOMEM;
|
||||
rc = pthread_create(&p->tid, 0, xTask, pIn);
|
||||
if( rc ){
|
||||
sqlite3_free(p);
|
||||
return SQLITE_ERROR;
|
||||
memset(p, 0, sizeof(*p));
|
||||
if( sqlite3GlobalConfig.bCoreMutex==0
|
||||
|| pthread_create(&p->tid, 0, xTask, pIn)!=0
|
||||
){
|
||||
p->done = 1;
|
||||
p->pOut = xTask(pIn);
|
||||
}
|
||||
*ppThread = p;
|
||||
return SQLITE_OK;
|
||||
@@ -67,7 +71,12 @@ int sqlite3ThreadJoin(SQLiteThread *p, void **ppOut){
|
||||
|
||||
assert( ppOut!=0 );
|
||||
if( p==0 ) return SQLITE_NOMEM;
|
||||
rc = pthread_join(p->tid, ppOut);
|
||||
if( p->done ){
|
||||
*ppOut = p->pOut;
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
rc = pthread_join(p->tid, ppOut);
|
||||
}
|
||||
sqlite3_free(p);
|
||||
return rc ? SQLITE_ERROR : SQLITE_OK;
|
||||
}
|
||||
@@ -115,11 +124,18 @@ int sqlite3ThreadCreate(
|
||||
*ppThread = 0;
|
||||
p = sqlite3Malloc(sizeof(*p));
|
||||
if( p==0 ) return SQLITE_NOMEM;
|
||||
p->xTask = xTask; p->pIn = pIn;
|
||||
p->tid = _beginthread(sqlite3ThreadProc, 0, p);
|
||||
if( p->tid==(uintptr_t)-1 ){
|
||||
sqlite3_free(p);
|
||||
return SQLITE_ERROR;
|
||||
if( sqlite3GlobalConfig.bCoreMutex==0 ){
|
||||
memset(p, 0, sizeof(*p));
|
||||
}else{
|
||||
p->xTask = xTask;
|
||||
p->pIn = pIn;
|
||||
p->tid = _beginthread(sqlite3ThreadProc, 0, p);
|
||||
if( p->tid==(uintptr_t)-1 ){
|
||||
memset(p, 0, sizeof(*p));
|
||||
}
|
||||
}
|
||||
if( p->xTask==0 ){
|
||||
p->pResult = xTask(pIn);
|
||||
}
|
||||
*ppThread = p;
|
||||
return SQLITE_OK;
|
||||
@@ -131,8 +147,12 @@ int sqlite3ThreadJoin(SQLiteThread *p, void **ppOut){
|
||||
|
||||
assert( ppOut!=0 );
|
||||
if( p==0 ) return SQLITE_NOMEM;
|
||||
rc = sqlite3Win32Wait((HANDLE)p->tid);
|
||||
assert( rc!=WAIT_IO_COMPLETION );
|
||||
if( p->xTask==0 ){
|
||||
rc = WAIT_OBJECT_O;
|
||||
}else{
|
||||
rc = sqlite3Win32Wait((HANDLE)p->tid);
|
||||
assert( rc!=WAIT_IO_COMPLETION );
|
||||
}
|
||||
if( rc==WAIT_OBJECT_0 ) *ppOut = p->pResult;
|
||||
sqlite3_free(p);
|
||||
return (rc==WAIT_OBJECT_0) ? SQLITE_OK : SQLITE_ERROR;
|
||||
|
||||
Reference in New Issue
Block a user