mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-21 09:00:59 +03:00
Add SQLITE_LIMIT_WORKER_THREADS for controlling the maximum number of
worker threads. FossilOrigin-Name: 1b598c68f32db635d1cea1373bedc434aa60cf08
This commit is contained in:
@@ -2078,6 +2078,7 @@ static const int aHardLimit[] = {
|
||||
SQLITE_MAX_LIKE_PATTERN_LENGTH,
|
||||
SQLITE_MAX_VARIABLE_NUMBER, /* IMP: R-38091-32352 */
|
||||
SQLITE_MAX_TRIGGER_DEPTH,
|
||||
SQLITE_MAX_WORKER_THREADS,
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -2113,6 +2114,9 @@ static const int aHardLimit[] = {
|
||||
#if SQLITE_MAX_TRIGGER_DEPTH<1
|
||||
# error SQLITE_MAX_TRIGGER_DEPTH must be at least 1
|
||||
#endif
|
||||
#if SQLITE_MAX_WORKER_THREADS<0 || SQLITE_MAX_WORKER_THREADS>50
|
||||
# error SQLITE_MAX_WORKER_THREADS must be between 0 and 50
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
@@ -2146,7 +2150,8 @@ int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
|
||||
SQLITE_MAX_LIKE_PATTERN_LENGTH );
|
||||
assert( aHardLimit[SQLITE_LIMIT_VARIABLE_NUMBER]==SQLITE_MAX_VARIABLE_NUMBER);
|
||||
assert( aHardLimit[SQLITE_LIMIT_TRIGGER_DEPTH]==SQLITE_MAX_TRIGGER_DEPTH );
|
||||
assert( SQLITE_LIMIT_TRIGGER_DEPTH==(SQLITE_N_LIMIT-1) );
|
||||
assert( aHardLimit[SQLITE_LIMIT_WORKER_THREADS]==SQLITE_MAX_WORKER_THREADS );
|
||||
assert( SQLITE_LIMIT_WORKER_THREADS==(SQLITE_N_LIMIT-1) );
|
||||
|
||||
|
||||
if( limitId<0 || limitId>=SQLITE_N_LIMIT ){
|
||||
@@ -2493,6 +2498,7 @@ static int openDatabase(
|
||||
|
||||
assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
|
||||
memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
|
||||
db->aLimit[SQLITE_LIMIT_WORKER_THREADS] = 0;
|
||||
db->autoCommit = 1;
|
||||
db->nextAutovac = -1;
|
||||
db->szMmap = sqlite3GlobalConfig.szMmap;
|
||||
|
||||
@@ -2287,15 +2287,14 @@ void sqlite3Pragma(
|
||||
*/
|
||||
case PragTyp_THREADS: {
|
||||
sqlite3_int64 N;
|
||||
if( sqlite3GlobalConfig.bCoreMutex
|
||||
&& zRight
|
||||
if( zRight
|
||||
&& sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK
|
||||
&& N>=0
|
||||
){
|
||||
if( N>SQLITE_MAX_WORKER_THREADS ) N = SQLITE_MAX_WORKER_THREADS;
|
||||
db->mxWorker = N&0xff;
|
||||
sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, (int)(N&0x7fffffff));
|
||||
}
|
||||
returnSingleInt(pParse, "soft_heap_limit", db->mxWorker);
|
||||
returnSingleInt(pParse, "threads",
|
||||
sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, -1));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -3073,6 +3073,10 @@ int sqlite3_limit(sqlite3*, int id, int newVal);
|
||||
**
|
||||
** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
|
||||
** <dd>The maximum depth of recursion for triggers.</dd>)^
|
||||
**
|
||||
** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
|
||||
** <dd>The maximum number of separate worker threads that a single
|
||||
** [database connection] may start to help it with a computation.</dd>)^
|
||||
** </dl>
|
||||
*/
|
||||
#define SQLITE_LIMIT_LENGTH 0
|
||||
@@ -3086,6 +3090,7 @@ int sqlite3_limit(sqlite3*, int id, int newVal);
|
||||
#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
|
||||
#define SQLITE_LIMIT_VARIABLE_NUMBER 9
|
||||
#define SQLITE_LIMIT_TRIGGER_DEPTH 10
|
||||
#define SQLITE_LIMIT_WORKER_THREADS 11
|
||||
|
||||
/*
|
||||
** CAPI3REF: Compiling An SQL Statement
|
||||
|
||||
@@ -941,7 +941,7 @@ struct Schema {
|
||||
** The number of different kinds of things that can be limited
|
||||
** using the sqlite3_limit() interface.
|
||||
*/
|
||||
#define SQLITE_N_LIMIT (SQLITE_LIMIT_TRIGGER_DEPTH+1)
|
||||
#define SQLITE_N_LIMIT (SQLITE_LIMIT_WORKER_THREADS+1)
|
||||
|
||||
/*
|
||||
** Lookaside malloc is a set of fixed-size buffers that can be used
|
||||
@@ -1013,7 +1013,6 @@ struct sqlite3 {
|
||||
u8 suppressErr; /* Do not issue error messages if true */
|
||||
u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */
|
||||
u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */
|
||||
u8 mxWorker; /* Maximum number of worker threads */
|
||||
int nextPagesize; /* Pagesize after VACUUM if >0 */
|
||||
u32 magic; /* Magic number for detect library misuse */
|
||||
int nChange; /* Value returned by sqlite3_changes() */
|
||||
|
||||
@@ -796,7 +796,16 @@ int sqlite3VdbeSorterInit(
|
||||
#if SQLITE_MAX_WORKER_THREADS==0
|
||||
# define nWorker 0
|
||||
#else
|
||||
int nWorker = sqlite3TempInMemory(db) ? 0 : db->mxWorker ;
|
||||
int nWorker;
|
||||
#endif
|
||||
|
||||
/* Initialize the upper limit on the number of worker threads */
|
||||
#if SQLITE_MAX_WORKER_THREADS>0
|
||||
if( sqlite3TempInMemory(db) || sqlite3GlobalConfig.bCoreMutex==0 ){
|
||||
nWorker = 0;
|
||||
}else{
|
||||
nWorker = db->aLimit[SQLITE_LIMIT_WORKER_THREADS];
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Do not allow the total number of threads (main thread + all workers)
|
||||
|
||||
Reference in New Issue
Block a user