/ Check-in [272959cc]
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:Use local variables instead of #defines for the mutex name and length in OS/2's sqlite3_mutex_alloc(). (CVS 4453)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 272959cc91d0c9299d6fca8a962eb563650af87b
User & Date: pweilbacher 2007-10-02 19:56:04
Context
2007-10-03
08:46
Add automatic recovery from the pager "error-state". Also add a new error code - SQLITE_IOERR_NOMEM. (CVS 4454) check-in: 12eca32a user: danielk1977 tags: trunk
2007-10-02
19:56
Use local variables instead of #defines for the mutex name and length in OS/2's sqlite3_mutex_alloc(). (CVS 4453) check-in: 272959cc user: pweilbacher tags: trunk
2007-10-01
17:47
Additional #ifdefing around _XOPEN_SOURCE. Ticket #2681. (CVS 4452) check-in: eb5d7845 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/mutex_os2.c.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
...
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the C functions that implement mutexes for OS/2
**
** $Id: mutex_os2.c,v 1.2 2007/09/20 21:40:23 pweilbacher Exp $
*/
#include "sqliteInt.h"

/*
** The code in this file is only used if SQLITE_MUTEX_OS2 is defined.
** See the mutex.h file for details.
*/
................................................................................
** Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
** returns a different mutex on every call.  But for the static
** mutex types, the same mutex is returned on every call that has
** the same type number.
*/
sqlite3_mutex *sqlite3_mutex_alloc(int iType){
#define MUTEX_NAME "\\SEM32\\SQLITE\\MUTEX"
#define MUTEX_NAME_LEN 20 /* name length + null byte */
  sqlite3_mutex *p;

  switch( iType ){
    case SQLITE_MUTEX_FAST:
    case SQLITE_MUTEX_RECURSIVE: {
      p = sqlite3MallocZero( sizeof(*p) );
      if( p ){
        p->mutexName = (PSZ)malloc(MUTEX_NAME_LEN);
        sqlite3_snprintf(MUTEX_NAME_LEN, p->mutexName, "%s", MUTEX_NAME);
        p->id = iType;
        DosCreateMutexSem(p->mutexName, &p->mutex, 0, FALSE);
        DosOpenMutexSem(p->mutexName, &p->mutex);
      }
      break;
    }
    default: {
................................................................................
        static long lock = 0;
        DosEnterCritSec();
        lock++;
        if( lock == 1 ) {
          DosExitCritSec();
          int i;
          for(i = 0; i < sizeof(staticMutexes)/sizeof(staticMutexes[0]); i++) {
            staticMutexes[i].mutexName = (PSZ)malloc(MUTEX_NAME_LEN + 1);
            sqlite3_snprintf(MUTEX_NAME_LEN + 1,
                             staticMutexes[i].mutexName, "%s%1d", MUTEX_NAME, i);
            DosCreateMutexSem(staticMutexes[i].mutexName,
                              &staticMutexes[i].mutex, 0, FALSE);
            DosOpenMutexSem(staticMutexes[i].mutexName,
                            &staticMutexes[i].mutex);
          }
          isInit = 1;
        } else {







|







 







|
|







|
|







 







|
|
|







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
...
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the C functions that implement mutexes for OS/2
**
** $Id: mutex_os2.c,v 1.3 2007/10/02 19:56:04 pweilbacher Exp $
*/
#include "sqliteInt.h"

/*
** The code in this file is only used if SQLITE_MUTEX_OS2 is defined.
** See the mutex.h file for details.
*/
................................................................................
** Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
** returns a different mutex on every call.  But for the static
** mutex types, the same mutex is returned on every call that has
** the same type number.
*/
sqlite3_mutex *sqlite3_mutex_alloc(int iType){
  PSZ mutex_name = "\\SEM32\\SQLITE\\MUTEX";
  int mutex_name_len = strlen(mutex_name) + 1; /* name length + null byte */
  sqlite3_mutex *p;

  switch( iType ){
    case SQLITE_MUTEX_FAST:
    case SQLITE_MUTEX_RECURSIVE: {
      p = sqlite3MallocZero( sizeof(*p) );
      if( p ){
        p->mutexName = (PSZ)malloc(mutex_name_len);
        sqlite3_snprintf(mutex_name_len, p->mutexName, "%s", mutex_name);
        p->id = iType;
        DosCreateMutexSem(p->mutexName, &p->mutex, 0, FALSE);
        DosOpenMutexSem(p->mutexName, &p->mutex);
      }
      break;
    }
    default: {
................................................................................
        static long lock = 0;
        DosEnterCritSec();
        lock++;
        if( lock == 1 ) {
          DosExitCritSec();
          int i;
          for(i = 0; i < sizeof(staticMutexes)/sizeof(staticMutexes[0]); i++) {
            staticMutexes[i].mutexName = (PSZ)malloc(mutex_name_len + 1);
            sqlite3_snprintf(mutex_name_len + 1, /* one more for the number */
                             staticMutexes[i].mutexName, "%s%1d", mutex_name, i);
            DosCreateMutexSem(staticMutexes[i].mutexName,
                              &staticMutexes[i].mutex, 0, FALSE);
            DosOpenMutexSem(staticMutexes[i].mutexName,
                            &staticMutexes[i].mutex);
          }
          isInit = 1;
        } else {