sl@0: /* sl@0: ** 2003 December 18 sl@0: ** sl@0: ** The author disclaims copyright to this source code. In place of sl@0: ** a legal notice, here is a blessing: sl@0: ** sl@0: ** May you do good and not evil. sl@0: ** May you find forgiveness for yourself and forgive others. sl@0: ** May you share freely, never taking more than you give. sl@0: ** sl@0: ************************************************************************* sl@0: ** Code for testing the the SQLite library in a multithreaded environment. sl@0: ** sl@0: ** $Id: test4.c,v 1.23 2008/07/28 19:34:54 drh Exp $ sl@0: */ sl@0: #include "sqliteInt.h" sl@0: #include "tcl.h" sl@0: #if defined(SQLITE_OS_UNIX) && OS_UNIX==1 && SQLITE_THREADSAFE sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: /* sl@0: ** Each thread is controlled by an instance of the following sl@0: ** structure. sl@0: */ sl@0: typedef struct Thread Thread; sl@0: struct Thread { sl@0: /* The first group of fields are writable by the master and read-only sl@0: ** to the thread. */ sl@0: char *zFilename; /* Name of database file */ sl@0: void (*xOp)(Thread*); /* next operation to do */ sl@0: char *zArg; /* argument usable by xOp */ sl@0: int opnum; /* Operation number */ sl@0: int busy; /* True if this thread is in use */ sl@0: sl@0: /* The next group of fields are writable by the thread but read-only to the sl@0: ** master. */ sl@0: int completed; /* Number of operations completed */ sl@0: sqlite3 *db; /* Open database */ sl@0: sqlite3_stmt *pStmt; /* Pending operation */ sl@0: char *zErr; /* operation error */ sl@0: char *zStaticErr; /* Static error message */ sl@0: int rc; /* operation return code */ sl@0: int argc; /* number of columns in result */ sl@0: const char *argv[100]; /* result columns */ sl@0: const char *colv[100]; /* result column names */ sl@0: }; sl@0: sl@0: /* sl@0: ** There can be as many as 26 threads running at once. Each is named sl@0: ** by a capital letter: A, B, C, ..., Y, Z. sl@0: */ sl@0: #define N_THREAD 26 sl@0: static Thread threadset[N_THREAD]; sl@0: sl@0: sl@0: /* sl@0: ** The main loop for a thread. Threads use busy waiting. sl@0: */ sl@0: static void *thread_main(void *pArg){ sl@0: Thread *p = (Thread*)pArg; sl@0: if( p->db ){ sl@0: sqlite3_close(p->db); sl@0: } sl@0: sqlite3_open(p->zFilename, &p->db); sl@0: if( SQLITE_OK!=sqlite3_errcode(p->db) ){ sl@0: p->zErr = strdup(sqlite3_errmsg(p->db)); sl@0: sqlite3_close(p->db); sl@0: p->db = 0; sl@0: } sl@0: p->pStmt = 0; sl@0: p->completed = 1; sl@0: while( p->opnum<=p->completed ) sched_yield(); sl@0: while( p->xOp ){ sl@0: if( p->zErr && p->zErr!=p->zStaticErr ){ sl@0: sqlite3_free(p->zErr); sl@0: p->zErr = 0; sl@0: } sl@0: (*p->xOp)(p); sl@0: p->completed++; sl@0: while( p->opnum<=p->completed ) sched_yield(); sl@0: } sl@0: if( p->pStmt ){ sl@0: sqlite3_finalize(p->pStmt); sl@0: p->pStmt = 0; sl@0: } sl@0: if( p->db ){ sl@0: sqlite3_close(p->db); sl@0: p->db = 0; sl@0: } sl@0: if( p->zErr && p->zErr!=p->zStaticErr ){ sl@0: sqlite3_free(p->zErr); sl@0: p->zErr = 0; sl@0: } sl@0: p->completed++; sl@0: sqlite3_thread_cleanup(); sl@0: return 0; sl@0: } sl@0: sl@0: /* sl@0: ** Get a thread ID which is an upper case letter. Return the index. sl@0: ** If the argument is not a valid thread ID put an error message in sl@0: ** the interpreter and return -1. sl@0: */ sl@0: static int parse_thread_id(Tcl_Interp *interp, const char *zArg){ sl@0: if( zArg==0 || zArg[0]==0 || zArg[1]!=0 || !isupper((unsigned char)zArg[0]) ){ sl@0: Tcl_AppendResult(interp, "thread ID must be an upper case letter", 0); sl@0: return -1; sl@0: } sl@0: return zArg[0] - 'A'; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: thread_create NAME FILENAME sl@0: ** sl@0: ** NAME should be an upper case letter. Start the thread running with sl@0: ** an open connection to the given database. sl@0: */ sl@0: static int tcl_thread_create( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: const char **argv /* Text of each argument */ sl@0: ){ sl@0: int i; sl@0: pthread_t x; sl@0: int rc; sl@0: sl@0: if( argc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " ID FILENAME", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: i = parse_thread_id(interp, argv[1]); sl@0: if( i<0 ) return TCL_ERROR; sl@0: if( threadset[i].busy ){ sl@0: Tcl_AppendResult(interp, "thread ", argv[1], " is already running", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: threadset[i].busy = 1; sl@0: sqlite3_free(threadset[i].zFilename); sl@0: threadset[i].zFilename = sqlite3DbStrDup(0, argv[2]); sl@0: threadset[i].opnum = 1; sl@0: threadset[i].completed = 0; sl@0: rc = pthread_create(&x, 0, thread_main, &threadset[i]); sl@0: if( rc ){ sl@0: Tcl_AppendResult(interp, "failed to create the thread", 0); sl@0: sqlite3_free(threadset[i].zFilename); sl@0: threadset[i].busy = 0; sl@0: return TCL_ERROR; sl@0: } sl@0: pthread_detach(x); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Wait for a thread to reach its idle state. sl@0: */ sl@0: static void thread_wait(Thread *p){ sl@0: while( p->opnum>p->completed ) sched_yield(); sl@0: } sl@0: sl@0: /* sl@0: ** Usage: thread_wait ID sl@0: ** sl@0: ** Wait on thread ID to reach its idle state. sl@0: */ sl@0: static int tcl_thread_wait( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: const char **argv /* Text of each argument */ sl@0: ){ sl@0: int i; sl@0: sl@0: if( argc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " ID", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: i = parse_thread_id(interp, argv[1]); sl@0: if( i<0 ) return TCL_ERROR; sl@0: if( !threadset[i].busy ){ sl@0: Tcl_AppendResult(interp, "no such thread", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: thread_wait(&threadset[i]); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Stop a thread. sl@0: */ sl@0: static void stop_thread(Thread *p){ sl@0: thread_wait(p); sl@0: p->xOp = 0; sl@0: p->opnum++; sl@0: thread_wait(p); sl@0: sqlite3_free(p->zArg); sl@0: p->zArg = 0; sl@0: sqlite3_free(p->zFilename); sl@0: p->zFilename = 0; sl@0: p->busy = 0; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: thread_halt ID sl@0: ** sl@0: ** Cause a thread to shut itself down. Wait for the shutdown to be sl@0: ** completed. If ID is "*" then stop all threads. sl@0: */ sl@0: static int tcl_thread_halt( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: const char **argv /* Text of each argument */ sl@0: ){ sl@0: int i; sl@0: sl@0: if( argc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " ID", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( argv[1][0]=='*' && argv[1][1]==0 ){ sl@0: for(i=0; i=threadset[i].argc ){ sl@0: Tcl_AppendResult(interp, "column number out of range", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: Tcl_AppendResult(interp, threadset[i].argv[n], 0); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: thread_colname ID N sl@0: ** sl@0: ** Wait on the most recent thread_step to complete, then return the sl@0: ** name of the N-th columns in the result set. sl@0: */ sl@0: static int tcl_thread_colname( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: const char **argv /* Text of each argument */ sl@0: ){ sl@0: int i; sl@0: int n; sl@0: sl@0: if( argc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " ID N", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: i = parse_thread_id(interp, argv[1]); sl@0: if( i<0 ) return TCL_ERROR; sl@0: if( !threadset[i].busy ){ sl@0: Tcl_AppendResult(interp, "no such thread", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( Tcl_GetInt(interp, argv[2], &n) ) return TCL_ERROR; sl@0: thread_wait(&threadset[i]); sl@0: if( n<0 || n>=threadset[i].argc ){ sl@0: Tcl_AppendResult(interp, "column number out of range", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: Tcl_AppendResult(interp, threadset[i].colv[n], 0); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: thread_result ID sl@0: ** sl@0: ** Wait on the most recent operation to complete, then return the sl@0: ** result code from that operation. sl@0: */ sl@0: static int tcl_thread_result( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: const char **argv /* Text of each argument */ sl@0: ){ sl@0: int i; sl@0: const char *zName; sl@0: sl@0: if( argc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " ID", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: i = parse_thread_id(interp, argv[1]); sl@0: if( i<0 ) return TCL_ERROR; sl@0: if( !threadset[i].busy ){ sl@0: Tcl_AppendResult(interp, "no such thread", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: thread_wait(&threadset[i]); sl@0: switch( threadset[i].rc ){ sl@0: case SQLITE_OK: zName = "SQLITE_OK"; break; sl@0: case SQLITE_ERROR: zName = "SQLITE_ERROR"; break; sl@0: case SQLITE_PERM: zName = "SQLITE_PERM"; break; sl@0: case SQLITE_ABORT: zName = "SQLITE_ABORT"; break; sl@0: case SQLITE_BUSY: zName = "SQLITE_BUSY"; break; sl@0: case SQLITE_LOCKED: zName = "SQLITE_LOCKED"; break; sl@0: case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break; sl@0: case SQLITE_READONLY: zName = "SQLITE_READONLY"; break; sl@0: case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break; sl@0: case SQLITE_IOERR: zName = "SQLITE_IOERR"; break; sl@0: case SQLITE_CORRUPT: zName = "SQLITE_CORRUPT"; break; sl@0: case SQLITE_FULL: zName = "SQLITE_FULL"; break; sl@0: case SQLITE_CANTOPEN: zName = "SQLITE_CANTOPEN"; break; sl@0: case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break; sl@0: case SQLITE_EMPTY: zName = "SQLITE_EMPTY"; break; sl@0: case SQLITE_SCHEMA: zName = "SQLITE_SCHEMA"; break; sl@0: case SQLITE_CONSTRAINT: zName = "SQLITE_CONSTRAINT"; break; sl@0: case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break; sl@0: case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break; sl@0: case SQLITE_NOLFS: zName = "SQLITE_NOLFS"; break; sl@0: case SQLITE_AUTH: zName = "SQLITE_AUTH"; break; sl@0: case SQLITE_FORMAT: zName = "SQLITE_FORMAT"; break; sl@0: case SQLITE_RANGE: zName = "SQLITE_RANGE"; break; sl@0: case SQLITE_ROW: zName = "SQLITE_ROW"; break; sl@0: case SQLITE_DONE: zName = "SQLITE_DONE"; break; sl@0: default: zName = "SQLITE_Unknown"; break; sl@0: } sl@0: Tcl_AppendResult(interp, zName, 0); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: thread_error ID sl@0: ** sl@0: ** Wait on the most recent operation to complete, then return the sl@0: ** error string. sl@0: */ sl@0: static int tcl_thread_error( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: const char **argv /* Text of each argument */ sl@0: ){ sl@0: int i; sl@0: sl@0: if( argc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " ID", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: i = parse_thread_id(interp, argv[1]); sl@0: if( i<0 ) return TCL_ERROR; sl@0: if( !threadset[i].busy ){ sl@0: Tcl_AppendResult(interp, "no such thread", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: thread_wait(&threadset[i]); sl@0: Tcl_AppendResult(interp, threadset[i].zErr, 0); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** This procedure runs in the thread to compile an SQL statement. sl@0: */ sl@0: static void do_compile(Thread *p){ sl@0: if( p->db==0 ){ sl@0: p->zErr = p->zStaticErr = "no database is open"; sl@0: p->rc = SQLITE_ERROR; sl@0: return; sl@0: } sl@0: if( p->pStmt ){ sl@0: sqlite3_finalize(p->pStmt); sl@0: p->pStmt = 0; sl@0: } sl@0: p->rc = sqlite3_prepare(p->db, p->zArg, -1, &p->pStmt, 0); sl@0: } sl@0: sl@0: /* sl@0: ** Usage: thread_compile ID SQL sl@0: ** sl@0: ** Compile a new virtual machine. sl@0: */ sl@0: static int tcl_thread_compile( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: const char **argv /* Text of each argument */ sl@0: ){ sl@0: int i; sl@0: if( argc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " ID SQL", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: i = parse_thread_id(interp, argv[1]); sl@0: if( i<0 ) return TCL_ERROR; sl@0: if( !threadset[i].busy ){ sl@0: Tcl_AppendResult(interp, "no such thread", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: thread_wait(&threadset[i]); sl@0: threadset[i].xOp = do_compile; sl@0: sqlite3_free(threadset[i].zArg); sl@0: threadset[i].zArg = sqlite3DbStrDup(0, argv[2]); sl@0: threadset[i].opnum++; sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** This procedure runs in the thread to step the virtual machine. sl@0: */ sl@0: static void do_step(Thread *p){ sl@0: int i; sl@0: if( p->pStmt==0 ){ sl@0: p->zErr = p->zStaticErr = "no virtual machine available"; sl@0: p->rc = SQLITE_ERROR; sl@0: return; sl@0: } sl@0: p->rc = sqlite3_step(p->pStmt); sl@0: if( p->rc==SQLITE_ROW ){ sl@0: p->argc = sqlite3_column_count(p->pStmt); sl@0: for(i=0; ipStmt); i++){ sl@0: p->argv[i] = (char*)sqlite3_column_text(p->pStmt, i); sl@0: } sl@0: for(i=0; iargc; i++){ sl@0: p->colv[i] = sqlite3_column_name(p->pStmt, i); sl@0: } sl@0: } sl@0: } sl@0: sl@0: /* sl@0: ** Usage: thread_step ID sl@0: ** sl@0: ** Advance the virtual machine by one step sl@0: */ sl@0: static int tcl_thread_step( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: const char **argv /* Text of each argument */ sl@0: ){ sl@0: int i; sl@0: if( argc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " IDL", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: i = parse_thread_id(interp, argv[1]); sl@0: if( i<0 ) return TCL_ERROR; sl@0: if( !threadset[i].busy ){ sl@0: Tcl_AppendResult(interp, "no such thread", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: thread_wait(&threadset[i]); sl@0: threadset[i].xOp = do_step; sl@0: threadset[i].opnum++; sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** This procedure runs in the thread to finalize a virtual machine. sl@0: */ sl@0: static void do_finalize(Thread *p){ sl@0: if( p->pStmt==0 ){ sl@0: p->zErr = p->zStaticErr = "no virtual machine available"; sl@0: p->rc = SQLITE_ERROR; sl@0: return; sl@0: } sl@0: p->rc = sqlite3_finalize(p->pStmt); sl@0: p->pStmt = 0; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: thread_finalize ID sl@0: ** sl@0: ** Finalize the virtual machine. sl@0: */ sl@0: static int tcl_thread_finalize( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: const char **argv /* Text of each argument */ sl@0: ){ sl@0: int i; sl@0: if( argc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " IDL", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: i = parse_thread_id(interp, argv[1]); sl@0: if( i<0 ) return TCL_ERROR; sl@0: if( !threadset[i].busy ){ sl@0: Tcl_AppendResult(interp, "no such thread", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: thread_wait(&threadset[i]); sl@0: threadset[i].xOp = do_finalize; sl@0: sqlite3_free(threadset[i].zArg); sl@0: threadset[i].zArg = 0; sl@0: threadset[i].opnum++; sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: thread_swap ID ID sl@0: ** sl@0: ** Interchange the sqlite* pointer between two threads. sl@0: */ sl@0: static int tcl_thread_swap( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: const char **argv /* Text of each argument */ sl@0: ){ sl@0: int i, j; sl@0: sqlite3 *temp; sl@0: if( argc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " ID1 ID2", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: i = parse_thread_id(interp, argv[1]); sl@0: if( i<0 ) return TCL_ERROR; sl@0: if( !threadset[i].busy ){ sl@0: Tcl_AppendResult(interp, "no such thread", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: thread_wait(&threadset[i]); sl@0: j = parse_thread_id(interp, argv[2]); sl@0: if( j<0 ) return TCL_ERROR; sl@0: if( !threadset[j].busy ){ sl@0: Tcl_AppendResult(interp, "no such thread", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: thread_wait(&threadset[j]); sl@0: temp = threadset[i].db; sl@0: threadset[i].db = threadset[j].db; sl@0: threadset[j].db = temp; sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: thread_db_get ID sl@0: ** sl@0: ** Return the database connection pointer for the given thread. Then sl@0: ** remove the pointer from the thread itself. Afterwards, the thread sl@0: ** can be stopped and the connection can be used by the main thread. sl@0: */ sl@0: static int tcl_thread_db_get( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: const char **argv /* Text of each argument */ sl@0: ){ sl@0: int i; sl@0: char zBuf[100]; sl@0: extern int sqlite3TestMakePointerStr(Tcl_Interp*, char*, void*); sl@0: if( argc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " ID", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: i = parse_thread_id(interp, argv[1]); sl@0: if( i<0 ) return TCL_ERROR; sl@0: if( !threadset[i].busy ){ sl@0: Tcl_AppendResult(interp, "no such thread", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: thread_wait(&threadset[i]); sl@0: sqlite3TestMakePointerStr(interp, zBuf, threadset[i].db); sl@0: threadset[i].db = 0; sl@0: Tcl_AppendResult(interp, zBuf, (char*)0); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: thread_stmt_get ID sl@0: ** sl@0: ** Return the database stmt pointer for the given thread. Then sl@0: ** remove the pointer from the thread itself. sl@0: */ sl@0: static int tcl_thread_stmt_get( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: const char **argv /* Text of each argument */ sl@0: ){ sl@0: int i; sl@0: char zBuf[100]; sl@0: extern int sqlite3TestMakePointerStr(Tcl_Interp*, char*, void*); sl@0: if( argc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " ID", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: i = parse_thread_id(interp, argv[1]); sl@0: if( i<0 ) return TCL_ERROR; sl@0: if( !threadset[i].busy ){ sl@0: Tcl_AppendResult(interp, "no such thread", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: thread_wait(&threadset[i]); sl@0: sqlite3TestMakePointerStr(interp, zBuf, threadset[i].pStmt); sl@0: threadset[i].pStmt = 0; sl@0: Tcl_AppendResult(interp, zBuf, (char*)0); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Register commands with the TCL interpreter. sl@0: */ sl@0: int Sqlitetest4_Init(Tcl_Interp *interp){ sl@0: static struct { sl@0: char *zName; sl@0: Tcl_CmdProc *xProc; sl@0: } aCmd[] = { sl@0: { "thread_create", (Tcl_CmdProc*)tcl_thread_create }, sl@0: { "thread_wait", (Tcl_CmdProc*)tcl_thread_wait }, sl@0: { "thread_halt", (Tcl_CmdProc*)tcl_thread_halt }, sl@0: { "thread_argc", (Tcl_CmdProc*)tcl_thread_argc }, sl@0: { "thread_argv", (Tcl_CmdProc*)tcl_thread_argv }, sl@0: { "thread_colname", (Tcl_CmdProc*)tcl_thread_colname }, sl@0: { "thread_result", (Tcl_CmdProc*)tcl_thread_result }, sl@0: { "thread_error", (Tcl_CmdProc*)tcl_thread_error }, sl@0: { "thread_compile", (Tcl_CmdProc*)tcl_thread_compile }, sl@0: { "thread_step", (Tcl_CmdProc*)tcl_thread_step }, sl@0: { "thread_finalize", (Tcl_CmdProc*)tcl_thread_finalize }, sl@0: { "thread_swap", (Tcl_CmdProc*)tcl_thread_swap }, sl@0: { "thread_db_get", (Tcl_CmdProc*)tcl_thread_db_get }, sl@0: { "thread_stmt_get", (Tcl_CmdProc*)tcl_thread_stmt_get }, sl@0: }; sl@0: int i; sl@0: sl@0: for(i=0; i