/ Check-in [fee2d7c0]
Login

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

Overview
Comment:Fix btree.c so that it works with -DSQLITE_THREADSAFE=0 and -DSQLITE_DEBUG=1 (CVS 4387)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: fee2d7c0e6d34dd19ff5f7631c1743879068c8ce
User & Date: drh 2007-09-03 22:00:39
Context
2007-09-03
22:15
Fix Makefile.in so that it rebuilds all source files that use SQLITE_TEST when constructing the testfixture. (CVS 4388) check-in: dced71a0 user: drh tags: trunk
22:00
Fix btree.c so that it works with -DSQLITE_THREADSAFE=0 and -DSQLITE_DEBUG=1 (CVS 4387) check-in: fee2d7c0 user: drh tags: trunk
20:32
Documentation updates in preparation for the release of version 3.5.0. (CVS 4386) check-in: c6809bf7 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to main.mk.

     5      5   # TOP              The toplevel directory of the source tree.  This is the
     6      6   #                  directory that contains this "Makefile.in" and the
     7      7   #                  "configure.in" script.
     8      8   #
     9      9   # BCC              C Compiler and options for use in building executables that
    10     10   #                  will run on the platform that is doing the build.
    11     11   #
    12         -# USLEEP           If the target operating system supports the "usleep()" system
    13         -#                  call, then define the HAVE_USLEEP macro for all C modules.
    14         -#
    15         -# THREADSAFE       If you want the SQLite library to be safe for use within a 
    16         -#                  multi-threaded program, then define the following macro
    17         -#                  appropriately:
    18         -#
    19     12   # THREADLIB        Specify any extra linker options needed to make the library
    20     13   #                  thread safe
    21     14   #
    22     15   # OPTS             Extra compiler command-line options.
    23     16   #
    24     17   # EXE              The suffix to add to executable files.  ".exe" for windows
    25     18   #                  and "" for Unix.
................................................................................
    47     40   #
    48     41   # Once the macros above are defined, the rest of this make script will
    49     42   # build the SQLite library and testing tools.
    50     43   ################################################################################
    51     44   
    52     45   # This is how we compile
    53     46   #
    54         -TCCX = $(TCC) $(OPTS) $(THREADSAFE) $(USLEEP) -I. -I$(TOP)/src
           47  +TCCX = $(TCC) $(OPTS) -I. -I$(TOP)/src
    55     48   
    56     49   # Object files for the SQLite library.
    57     50   #
    58     51   LIBOBJ+= alter.o analyze.o attach.o auth.o btmutex.o btree.o build.o \
    59     52            callback.o complete.o date.o delete.o \
    60     53            expr.o func.o hash.o insert.o journal.o loadext.o \
    61     54            main.o malloc.o mem1.o mem2.o mutex.o mutex_os2.o \

Changes to src/btree.c.

     5      5   ** a legal notice, here is a blessing:
     6      6   **
     7      7   **    May you do good and not evil.
     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         -** $Id: btree.c,v 1.421 2007/09/03 15:19:35 drh Exp $
           12  +** $Id: btree.c,v 1.422 2007/09/03 22:00:39 drh Exp $
    13     13   **
    14     14   ** This file implements a external (disk-based) database using BTrees.
    15     15   ** See the header comment on "btreeInt.h" for additional information.
    16     16   ** Including a description of file format and an overview of operation.
    17     17   */
    18     18   #include "btreeInt.h"
    19     19   
................................................................................
  1263   1263   #if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO)
  1264   1264       /* Add the new BtShared object to the linked list sharable BtShareds.
  1265   1265       */
  1266   1266       if( p->sharable ){
  1267   1267         sqlite3_mutex *mutexShared;
  1268   1268         pBt->nRef = 1;
  1269   1269         mutexShared = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
  1270         -      pBt->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
  1271         -      if( pBt->mutex==0 ){
  1272         -        rc = SQLITE_NOMEM;
  1273         -        pSqlite->mallocFailed = 0;
  1274         -        goto btree_open_out;
         1270  +      if( SQLITE_THREADSAFE ){
         1271  +        pBt->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
         1272  +        if( pBt->mutex==0 ){
         1273  +          rc = SQLITE_NOMEM;
         1274  +          pSqlite->mallocFailed = 0;
         1275  +          goto btree_open_out;
         1276  +        }
  1275   1277         }
  1276   1278         sqlite3_mutex_enter(mutexShared);
  1277   1279         pBt->pNext = sqlite3SharedCacheList;
  1278   1280         sqlite3SharedCacheList = pBt;
  1279   1281         sqlite3_mutex_leave(mutexShared);
  1280   1282       }
  1281   1283   #endif
................................................................................
  1350   1352         while( pList && pList->pNext!=pBt ){
  1351   1353           pList=pList->pNext;
  1352   1354         }
  1353   1355         if( pList ){
  1354   1356           pList->pNext = pBt->pNext;
  1355   1357         }
  1356   1358       }
  1357         -    sqlite3_mutex_free(pBt->mutex);
         1359  +    if( SQLITE_THREADSAFE ){
         1360  +      sqlite3_mutex_free(pBt->mutex);
         1361  +    }
  1358   1362       removed = 1;
  1359   1363     }
  1360   1364     sqlite3_mutex_leave(pMaster);
  1361   1365     return removed;
  1362   1366   #else
  1363   1367     return 1;
  1364   1368   #endif