/ Check-in [af1835bb]
Login

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

Overview
Comment:Add the SQLITE_CONFIG_MUTEX symbol for use with sqlite3_config(). (CVS 5228)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: af1835bb5f5e3fb78d782c7c287e20db169e883f
User & Date: danielk1977 2008-06-17 18:57:49
Context
2008-06-18
02:01
Remove mem3.c and mem5.c from the amalgamation for the time being, since they do not currently work. We will add them back later once they are fixed. (CVS 5229) check-in: 39b4e1ff user: drh tags: trunk
2008-06-17
18:57
Add the SQLITE_CONFIG_MUTEX symbol for use with sqlite3_config(). (CVS 5228) check-in: af1835bb user: danielk1977 tags: trunk
17:21
Change the mutex interface to be pluggable. This is an incremental checkin, there are still changes to come. (CVS 5227) check-in: 59728363 user: danielk1977 tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/main.c.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
...
148
149
150
151
152
153
154





155
156
157
158
159
160
161
**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.445 2008/06/16 20:51:16 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

#ifdef SQLITE_ENABLE_FTS3
# include "fts3.h"
#endif
................................................................................
** or for the first call after a call to sqlite3_shutdown.
*/
int sqlite3_initialize(void){
  int rc;
  if( sqlite3IsInit ) return SQLITE_OK;
  rc = sqlite3_mutex_init();
  if( rc==SQLITE_OK ){
#ifndef SQLITE_MUTEX_NOOP
    sqlite3_mutex *pMutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
#endif
    sqlite3_mutex_enter(pMutex);
    if( sqlite3IsInit==0 ){
      sqlite3IsInit = 1;
      if( rc==SQLITE_OK ) rc = sqlite3MallocInit();
      if( rc==SQLITE_OK ) rc = sqlite3_os_init();
      if( rc!=SQLITE_OK ){
        sqlite3IsInit = 0;
................................................................................
      sqlite3Config.bFullMutex = 1;
      break;
    }
    case SQLITE_CONFIG_MALLOC: {
      /* Specify an alternative malloc implementation */
      sqlite3Config.m = *va_arg(ap, sqlite3_mem_methods*);
      break;





    }
    case SQLITE_CONFIG_MEMSTATUS: {
      /* Enable or disable the malloc status collection */
      sqlite3Config.bMemstat = va_arg(ap, int);
      break;
    }
    default: {







|







 







<

<







 







>
>
>
>
>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
72
73
74
75
76
77
78

79

80
81
82
83
84
85
86
...
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.446 2008/06/17 18:57:49 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

#ifdef SQLITE_ENABLE_FTS3
# include "fts3.h"
#endif
................................................................................
** or for the first call after a call to sqlite3_shutdown.
*/
int sqlite3_initialize(void){
  int rc;
  if( sqlite3IsInit ) return SQLITE_OK;
  rc = sqlite3_mutex_init();
  if( rc==SQLITE_OK ){

    sqlite3_mutex *pMutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);

    sqlite3_mutex_enter(pMutex);
    if( sqlite3IsInit==0 ){
      sqlite3IsInit = 1;
      if( rc==SQLITE_OK ) rc = sqlite3MallocInit();
      if( rc==SQLITE_OK ) rc = sqlite3_os_init();
      if( rc!=SQLITE_OK ){
        sqlite3IsInit = 0;
................................................................................
      sqlite3Config.bFullMutex = 1;
      break;
    }
    case SQLITE_CONFIG_MALLOC: {
      /* Specify an alternative malloc implementation */
      sqlite3Config.m = *va_arg(ap, sqlite3_mem_methods*);
      break;
    }
    case SQLITE_CONFIG_MUTEX: {
      /* Specify an alternative mutex implementation */
      sqlite3Config.mutex = *va_arg(ap, sqlite3_mutex_methods*);
      break;
    }
    case SQLITE_CONFIG_MEMSTATUS: {
      /* Enable or disable the malloc status collection */
      sqlite3Config.bMemstat = va_arg(ap, int);
      break;
    }
    default: {

Changes to src/mutex.c.

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32











33
34
35
36
37
38

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
** exclusion and is thus suitable for use only in applications
** that use SQLite in a single thread.  But this implementation
** does do a lot of error checking on mutexes to make sure they
** are called correctly and at appropriate times.  Hence, this
** implementation is suitable for testing.
** debugging purposes
**
** $Id: mutex.c,v 1.21 2008/06/17 17:21:18 danielk1977 Exp $
*/
#include "sqliteInt.h"

#ifndef SQLITE_MUTEX_NOOP
/*
** Initialize the mutex system.
*/
int sqlite3_mutex_init(void){ 
  int rc;
  if( !sqlite3Config.mutex.xMutexAlloc ){











    sqlite3_mutex_methods *p = sqlite3DefaultMutex();
    sqlite3_mutex *pMaster;

    rc = p->xMutexInit();
    if( rc==SQLITE_OK ){
      pMaster = p->xMutexAlloc(SQLITE_MUTEX_STATIC_MASTER);

      p->xMutexEnter(pMaster);
      assert( sqlite3Config.mutex.xMutexAlloc==0 
           || sqlite3Config.mutex.xMutexAlloc==p->xMutexAlloc
      );
      if( !sqlite3Config.mutex.xMutexAlloc ){
        sqlite3Config.mutex = *p;
      }
      p->xMutexLeave(pMaster);
    }

  }else{
    rc = sqlite3Config.mutex.xMutexInit();
  }

  return rc;
}








|










>
>
>
>
>
>
>
>
>
>
>






>









<







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

60
61
62
63
64
65
66
** exclusion and is thus suitable for use only in applications
** that use SQLite in a single thread.  But this implementation
** does do a lot of error checking on mutexes to make sure they
** are called correctly and at appropriate times.  Hence, this
** implementation is suitable for testing.
** debugging purposes
**
** $Id: mutex.c,v 1.22 2008/06/17 18:57:49 danielk1977 Exp $
*/
#include "sqliteInt.h"

#ifndef SQLITE_MUTEX_NOOP
/*
** Initialize the mutex system.
*/
int sqlite3_mutex_init(void){ 
  int rc;
  if( !sqlite3Config.mutex.xMutexAlloc ){
    /* If the xMutexAlloc method has not been set, then the user did not
    ** install a mutex implementation via sqlite3_config() prior to 
    ** sqlite3_initialize() being called. This block copies pointers to
    ** the default implementation into the sqlite3Config structure.
    **
    ** The danger is that although sqlite3_config() is not a threadsafe
    ** API, sqlite3_initialize() is, and so multiple threads may be
    ** attempting to run this function simultaneously. To guard write
    ** access to the sqlite3Config structure, the 'MASTER' static mutex
    ** is obtained before modifying it.
    */
    sqlite3_mutex_methods *p = sqlite3DefaultMutex();
    sqlite3_mutex *pMaster;

    rc = p->xMutexInit();
    if( rc==SQLITE_OK ){
      pMaster = p->xMutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
      assert(pMaster);
      p->xMutexEnter(pMaster);
      assert( sqlite3Config.mutex.xMutexAlloc==0 
           || sqlite3Config.mutex.xMutexAlloc==p->xMutexAlloc
      );
      if( !sqlite3Config.mutex.xMutexAlloc ){
        sqlite3Config.mutex = *p;
      }
      p->xMutexLeave(pMaster);
    }

  }else{
    rc = sqlite3Config.mutex.xMutexInit();
  }

  return rc;
}

Changes to src/sqlite.h.in.

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
....
1046
1047
1048
1049
1050
1051
1052

1053
1054
1055
1056
1057
1058
1059
** on how SQLite interfaces are suppose to operate.
**
** The name of this file under configuration management is "sqlite.h.in".
** The makefile makes some minor changes to this file (such as inserting
** the version number) and changes its name to "sqlite3.h" as
** part of the build process.
**
** @(#) $Id: sqlite.h.in,v 1.330 2008/06/17 17:21:18 danielk1977 Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
#include <stdarg.h>     /* Needed for the definition of va_list */

/*
** Make sure we can call this stuff from C++.
................................................................................
** </dl>
*/ 
#define SQLITE_CONFIG_SINGLETHREAD  1  /* nil */
#define SQLITE_CONFIG_MULTITHREAD   2  /* nil */
#define SQLITE_CONFIG_SERIALIZED    3  /* nil */
#define SQLITE_CONFIG_MALLOC        4  /* sqlite3_mem_methods* */
#define SQLITE_CONFIG_MEMSTATUS     5  /* boolean */


/* These options are to be added later.  Currently unused and undocumented. */
#define SQLITE_CONFIG_HEAP          6  /* void*, int64, min, max, tmp */


/*
** CAPI3REF: Enable Or Disable Extended Result Codes {F12200}







|







 







>







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
....
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
** on how SQLite interfaces are suppose to operate.
**
** The name of this file under configuration management is "sqlite.h.in".
** The makefile makes some minor changes to this file (such as inserting
** the version number) and changes its name to "sqlite3.h" as
** part of the build process.
**
** @(#) $Id: sqlite.h.in,v 1.331 2008/06/17 18:57:49 danielk1977 Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
#include <stdarg.h>     /* Needed for the definition of va_list */

/*
** Make sure we can call this stuff from C++.
................................................................................
** </dl>
*/ 
#define SQLITE_CONFIG_SINGLETHREAD  1  /* nil */
#define SQLITE_CONFIG_MULTITHREAD   2  /* nil */
#define SQLITE_CONFIG_SERIALIZED    3  /* nil */
#define SQLITE_CONFIG_MALLOC        4  /* sqlite3_mem_methods* */
#define SQLITE_CONFIG_MEMSTATUS     5  /* boolean */
#define SQLITE_CONFIG_MUTEX         6  /* sqlite3_mutex_methods* */

/* These options are to be added later.  Currently unused and undocumented. */
#define SQLITE_CONFIG_HEAP          6  /* void*, int64, min, max, tmp */


/*
** CAPI3REF: Enable Or Disable Extended Result Codes {F12200}