/ Check-in [f2f361a5]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add support for SQLITE_OPEN_FULLMUTEX. (CVS 5669)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f2f361a5e2fb81fb0f99e83ecf8bae9a750723b1
User & Date: drh 2008-09-03 00:43:15
Context
2008-09-03
01:08
Make the default threading mode multithread (-nomutex) in the TCL interface. (CVS 5670) check-in: d9e82694 user: drh tags: trunk
00:43
Add support for SQLITE_OPEN_FULLMUTEX. (CVS 5669) check-in: f2f361a5 user: drh tags: trunk
00:08
If a rollback fails, mark the database as corrupt. (CVS 5668) check-in: c8b24bd1 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/main.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Main file for the SQLite library.  The routines in this file
    13     13   ** implement the programmer interface to the library.  Routines in
    14     14   ** other files are for internal use by SQLite and should not be
    15     15   ** accessed by users of the library.
    16     16   **
    17         -** $Id: main.c,v 1.498 2008/09/02 16:22:29 danielk1977 Exp $
           17  +** $Id: main.c,v 1.499 2008/09/03 00:43:15 drh Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include <ctype.h>
    21     21   
    22     22   #ifdef SQLITE_ENABLE_FTS3
    23     23   # include "fts3.h"
    24     24   #endif
................................................................................
  1422   1422     sqlite3 **ppDb,        /* OUT: Returned database handle */
  1423   1423     unsigned flags,        /* Operational flags */
  1424   1424     const char *zVfs       /* Name of the VFS to use */
  1425   1425   ){
  1426   1426     sqlite3 *db;
  1427   1427     int rc;
  1428   1428     CollSeq *pColl;
  1429         -  int isThreadsafe = 1;
         1429  +  int isThreadsafe;
  1430   1430   
  1431   1431   #ifndef SQLITE_OMIT_AUTOINIT
  1432   1432     rc = sqlite3_initialize();
  1433   1433     if( rc ) return rc;
  1434   1434   #endif
  1435   1435   
  1436         -  if( flags&SQLITE_OPEN_NOMUTEX ){
         1436  +  if( sqlite3GlobalConfig.bCoreMutex==0 ){
         1437  +    isThreadsafe = 0;
         1438  +  }else if( flags & SQLITE_OPEN_NOMUTEX ){
  1437   1439       isThreadsafe = 0;
         1440  +  }else if( flags & SQLITE_OPEN_FULLMUTEX ){
         1441  +    isThreadsafe = 1;
         1442  +  }else{
         1443  +    isThreadsafe = sqlite3GlobalConfig.bFullMutex;
  1438   1444     }
  1439   1445   
  1440   1446     /* Remove harmful bits from the flags parameter */
  1441   1447     flags &=  ~( SQLITE_OPEN_DELETEONCLOSE |
  1442   1448                  SQLITE_OPEN_MAIN_DB |
  1443   1449                  SQLITE_OPEN_TEMP_DB | 
  1444   1450                  SQLITE_OPEN_TRANSIENT_DB | 
  1445   1451                  SQLITE_OPEN_MAIN_JOURNAL | 
  1446   1452                  SQLITE_OPEN_TEMP_JOURNAL | 
  1447   1453                  SQLITE_OPEN_SUBJOURNAL | 
  1448   1454                  SQLITE_OPEN_MASTER_JOURNAL |
  1449         -               SQLITE_OPEN_NOMUTEX
         1455  +               SQLITE_OPEN_NOMUTEX |
         1456  +               SQLITE_OPEN_FULLMUTEX
  1450   1457                );
  1451   1458   
  1452   1459     /* Allocate the sqlite data structure */
  1453   1460     db = sqlite3MallocZero( sizeof(sqlite3) );
  1454   1461     if( db==0 ) goto opendb_out;
  1455         -  if( sqlite3GlobalConfig.bFullMutex && isThreadsafe ){
         1462  +  if( isThreadsafe ){
  1456   1463       db->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
  1457   1464       if( db->mutex==0 ){
  1458   1465         sqlite3_free(db);
  1459   1466         db = 0;
  1460   1467         goto opendb_out;
  1461   1468       }
  1462   1469     }

Changes to src/tclsqlite.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** A TCL Interface to SQLite.  Append this file to sqlite3.c and
    13     13   ** compile the whole thing to build a TCL-enabled version of SQLite.
    14     14   **
    15         -** $Id: tclsqlite.c,v 1.221 2008/09/01 20:38:12 shane Exp $
           15  +** $Id: tclsqlite.c,v 1.222 2008/09/03 00:43:15 drh Exp $
    16     16   */
    17     17   #include "tcl.h"
    18     18   #include <errno.h>
    19     19   
    20     20   /*
    21     21   ** Some additional include files are needed if this file is not
    22     22   ** appended to the amalgamation.
................................................................................
  2370   2370           flags &= ~SQLITE_OPEN_CREATE;
  2371   2371         }
  2372   2372       }else if( strcmp(zArg, "-nomutex")==0 ){
  2373   2373         int b;
  2374   2374         if( Tcl_GetBooleanFromObj(interp, objv[i+1], &b) ) return TCL_ERROR;
  2375   2375         if( b ){
  2376   2376           flags |= SQLITE_OPEN_NOMUTEX;
         2377  +        flags &= ~SQLITE_OPEN_FULLMUTEX;
  2377   2378         }else{
  2378   2379           flags &= ~SQLITE_OPEN_NOMUTEX;
         2380  +      }
         2381  +   }else if( strcmp(zArg, "-fullmutex")==0 ){
         2382  +      int b;
         2383  +      if( Tcl_GetBooleanFromObj(interp, objv[i+1], &b) ) return TCL_ERROR;
         2384  +      if( b ){
         2385  +        flags |= SQLITE_OPEN_FULLMUTEX;
         2386  +        flags &= ~SQLITE_OPEN_NOMUTEX;
................................................................................
         2387  +      }else{
         2388  +        flags &= ~SQLITE_OPEN_FULLMUTEX;
  2379   2389         }
  2380   2390       }else{
  2381   2391         Tcl_AppendResult(interp, "unknown option: ", zArg, (char*)0);
  2382   2392         return TCL_ERROR;
  2383   2393       }
  2384   2394     }
  2385   2395     if( objc<3 || (objc&1)!=1 ){
  2386   2396       Tcl_WrongNumArgs(interp, 1, objv, 
  2387   2397         "HANDLE FILENAME ?-vfs VFSNAME? ?-readonly BOOLEAN? ?-create BOOLEAN?"
  2388         -      " ?-nomutex BOOLEAN?"
         2398  +      " ?-nomutex BOOLEAN? ?-fullmutex BOOLEAN?"
  2389   2399   #ifdef SQLITE_HAS_CODEC
  2390   2400         " ?-key CODECKEY?"
  2391   2401   #endif
  2392   2402       );
  2393   2403       return TCL_ERROR;
  2394   2404     }
  2395   2405     zErrMsg = 0;

Changes to test/permutations.test.

     5      5   #
     6      6   #    May you do good and not evil.
     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   #
    12         -# $Id: permutations.test,v 1.27 2008/08/30 16:07:04 drh Exp $
           12  +# $Id: permutations.test,v 1.28 2008/09/03 00:43:15 drh Exp $
    13     13   
    14     14   set testdir [file dirname $argv0]
    15     15   source $testdir/tester.tcl
    16     16   
    17     17   # Argument processing.
    18     18   #
    19     19   #puts "PERM-DEBUG: argv=$argv"
................................................................................
   262    262       catch {db close}
   263    263       sqlite3_shutdown
   264    264       sqlite3_config serialized
   265    265     } SQLITE_OK
   266    266   }
   267    267   
   268    268   run_tests "nomutex" -description {
   269         -  Tests run with the SQLITE_OPEN_SINGLETHREADED flag passed to sqlite3_open().
          269  +  Tests run with the SQLITE_OPEN_MULTITHREADED flag passed to sqlite3_open().
   270    270   } -initialize {
   271    271     rename sqlite3 sqlite3_nomutex
   272    272     proc sqlite3 {args} {
   273    273       if {[string range [lindex $args 0] 0 0] ne "-"} {
   274    274         lappend args -nomutex 1
   275    275       }
   276    276       uplevel [concat sqlite3_nomutex $args]
................................................................................
   301    301   } -shutdown {
   302    302     do_test mutex2-X {
   303    303       catch {db close}
   304    304       sqlite3_shutdown
   305    305       sqlite3_config serialized
   306    306     } SQLITE_OK
   307    307   }
          308  +
          309  +# Run some tests in SQLITE_OPEN_FULLMUTEX mode.
          310  +#
          311  +run_tests "fullmutex" -description {
          312  +  Tests run in SQLITE_OPEN_FULLMUTEX mode
          313  +} -initialize {
          314  +  rename sqlite3 sqlite3_fullmutex
          315  +  proc sqlite3 {args} {
          316  +    if {[string range [lindex $args 0] 0 0] ne "-"} {
          317  +      lappend args -fullmutex 1
          318  +    }
          319  +    uplevel [concat sqlite3_fullmutex $args]
          320  +  }
          321  +} -include {
          322  +  delete.test   delete2.test  insert.test  rollback.test  select1.test
          323  +  select2.test  trans.test    update.test  vacuum.test    types.test
          324  +  types2.test   types3.test
          325  +} -shutdown {
          326  +  rename sqlite3 {}
          327  +  rename sqlite3_fullmutex sqlite3
          328  +}
   308    329   
   309    330   # Run some tests using the "onefile" demo.
   310    331   #
   311    332   run_tests "onefile" -description {
   312    333     Run some tests using the "test_onefile.c" demo
   313    334   } -initialize {
   314    335     rename sqlite3 sqlite3_onefile

Changes to test/tclsqlite.test.

    11     11   # This file implements regression tests for TCL interface to the
    12     12   # SQLite library. 
    13     13   #
    14     14   # Actually, all tests are based on the TCL interface, so the main
    15     15   # interface is pretty well tested.  This file contains some addition
    16     16   # tests for fringe issues that the main test suite does not cover.
    17     17   #
    18         -# $Id: tclsqlite.test,v 1.67 2008/08/29 15:54:57 danielk1977 Exp $
           18  +# $Id: tclsqlite.test,v 1.68 2008/09/03 00:43:15 drh Exp $
    19     19   
    20     20   set testdir [file dirname $argv0]
    21     21   source $testdir/tester.tcl
    22     22   
    23     23   # Check the error messages generated by tclsqlite
    24     24   #
    25     25   if {[sqlite3 -has-codec]} {
    26     26     set r "sqlite_orig HANDLE FILENAME ?-key CODEC-KEY?"
    27     27   } else {
    28         -  set r "sqlite3 HANDLE FILENAME ?-vfs VFSNAME? ?-readonly BOOLEAN? ?-create BOOLEAN? ?-nomutex BOOLEAN?"
           28  +  set r "sqlite3 HANDLE FILENAME ?-vfs VFSNAME? ?-readonly BOOLEAN? ?-create BOOLEAN? ?-nomutex BOOLEAN? ?-fullmutex BOOLEAN?"
    29     29   }
    30     30   do_test tcl-1.1 {
    31     31     set v [catch {sqlite3 bogus} msg]
    32     32     regsub {really_sqlite3} $msg {sqlite3} msg
    33     33     lappend v $msg
    34     34   } [list 1 "wrong # args: should be \"$r\""]
    35     35   do_test tcl-1.2 {