fix broken OS/2 mutex implementation (Ticket #2905) (CVS 4770)
FossilOrigin-Name: 05afd86e2d25a219843be48c21c212e84f94e7ef
This commit is contained in:
parent
dd95535f20
commit
dc965c3c81
14
manifest
14
manifest
@ -1,5 +1,5 @@
|
||||
C Minor\sfixes\sto\sFTS3\sso\sthat\sit\sworks\sbetter\swhen\sappended\sto\sthe\send\nof\sthe\samalgamation.\s(CVS\s4769)
|
||||
D 2008-02-01T15:34:10
|
||||
C fix\sbroken\sOS/2\smutex\simplementation\s(Ticket\s#2905)\s(CVS\s4770)
|
||||
D 2008-02-01T19:42:38
|
||||
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
|
||||
F Makefile.in bc2b5df3e3d0d4b801b824b7ef6dec43812b049b
|
||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||
@ -111,7 +111,7 @@ F src/mem3.c 9d80034bb004c1bddc28d6befe1ddb044d18deab
|
||||
F src/mem4.c 36ecd536a8b7acfe4cbf011353dae6ea68121e40
|
||||
F src/mutex.c 3259f62c2429967aee6dc112117a6d2f499ef061
|
||||
F src/mutex.h 079fa6fe9da18ceb89e79012c010594c6672addb
|
||||
F src/mutex_os2.c 4058d04e81a6c1e240020d299a3192d92352c7ef
|
||||
F src/mutex_os2.c 19ab15764736f13b94b4f70e53f77547cbddd47a
|
||||
F src/mutex_unix.c a6e111947a3cdaa2cda394ed060d7f496fcb4af8
|
||||
F src/mutex_w32.c 6e197765f283815496193e78e9548b5d0e53b68e
|
||||
F src/os.c 50c0c1706c35f872db312815aaecc4b5ebcd6a4c
|
||||
@ -614,7 +614,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
|
||||
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
|
||||
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
|
||||
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
|
||||
P c336b2318a56c1deb94c41107754f5f622a9b1ee
|
||||
R 21445e001f0b9559aceb264d61ee0e1d
|
||||
U drh
|
||||
Z ca3eea9585d8ee2592a2134b916f159f
|
||||
P 62ede6699d8f116921a5a0baddca5e7e63740cd3
|
||||
R a3c12d2656e30bd09a6226afe41e9199
|
||||
U pweilbacher
|
||||
Z 90ac1767b82b52f948a282a45e6b19e8
|
||||
|
@ -1 +1 @@
|
||||
62ede6699d8f116921a5a0baddca5e7e63740cd3
|
||||
05afd86e2d25a219843be48c21c212e84f94e7ef
|
@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** This file contains the C functions that implement mutexes for OS/2
|
||||
**
|
||||
** $Id: mutex_os2.c,v 1.4 2007/12/30 23:29:07 pweilbacher Exp $
|
||||
** $Id: mutex_os2.c,v 1.5 2008/02/01 19:42:38 pweilbacher Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@ -31,13 +31,14 @@
|
||||
** Each recursive mutex is an instance of the following structure.
|
||||
*/
|
||||
struct sqlite3_mutex {
|
||||
PSZ mutexName; /* Mutex name controlling the lock */
|
||||
HMTX mutex; /* Mutex controlling the lock */
|
||||
int id; /* Mutex type */
|
||||
int nRef; /* Number of references */
|
||||
TID owner; /* Thread holding this mutex */
|
||||
};
|
||||
|
||||
#define OS2_MUTEX_INITIALIZER 0,0,0,0
|
||||
|
||||
/*
|
||||
** The sqlite3_mutex_alloc() routine allocates a new
|
||||
** mutex and returns a pointer to it. If it returns NULL
|
||||
@ -78,46 +79,55 @@ struct sqlite3_mutex {
|
||||
** 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;
|
||||
|
||||
sqlite3_mutex *p = NULL;
|
||||
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);
|
||||
if( DosCreateMutexSem( 0, &p->mutex, 0, FALSE ) != NO_ERROR ){
|
||||
sqlite3_free( p );
|
||||
p = NULL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
static sqlite3_mutex staticMutexes[5];
|
||||
static int isInit = 0;
|
||||
while( !isInit ) {
|
||||
static long lock = 0;
|
||||
DosEnterCritSec();
|
||||
lock++;
|
||||
if( lock == 1 ) {
|
||||
int i;
|
||||
DosExitCritSec();
|
||||
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);
|
||||
static volatile int isInit = 0;
|
||||
static sqlite3_mutex staticMutexes[] = {
|
||||
{ OS2_MUTEX_INITIALIZER, },
|
||||
{ OS2_MUTEX_INITIALIZER, },
|
||||
{ OS2_MUTEX_INITIALIZER, },
|
||||
{ OS2_MUTEX_INITIALIZER, },
|
||||
{ OS2_MUTEX_INITIALIZER, },
|
||||
};
|
||||
if ( !isInit ){
|
||||
APIRET rc;
|
||||
PTIB ptib;
|
||||
PPIB ppib;
|
||||
HMTX mutex;
|
||||
char name[32];
|
||||
DosGetInfoBlocks( &ptib, &ppib );
|
||||
sqlite3_snprintf( sizeof(name), name, "\\SEM32\\SQLITE%04x",
|
||||
ppib->pib_ulpid );
|
||||
while( !isInit ){
|
||||
mutex = 0;
|
||||
rc = DosCreateMutexSem( name, &mutex, 0, FALSE);
|
||||
if( rc == NO_ERROR ){
|
||||
int i;
|
||||
if( !isInit ){
|
||||
for( i = 0; i < sizeof(staticMutexes)/sizeof(staticMutexes[0]); i++ ){
|
||||
DosCreateMutexSem( 0, &staticMutexes[i].mutex, 0, FALSE );
|
||||
}
|
||||
isInit = 1;
|
||||
}
|
||||
DosCloseMutexSem( mutex );
|
||||
}else if( rc == ERROR_DUPLICATE_NAME ){
|
||||
DosSleep( 1 );
|
||||
}else{
|
||||
return p;
|
||||
}
|
||||
isInit = 1;
|
||||
} else {
|
||||
DosExitCritSec();
|
||||
DosSleep(1);
|
||||
}
|
||||
}
|
||||
assert( iType-2 >= 0 );
|
||||
@ -139,9 +149,8 @@ void sqlite3_mutex_free(sqlite3_mutex *p){
|
||||
assert( p );
|
||||
assert( p->nRef==0 );
|
||||
assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
|
||||
DosCloseMutexSem(p->mutex);
|
||||
free(p->mutexName);
|
||||
sqlite3_free(p);
|
||||
DosCloseMutexSem( p->mutex );
|
||||
sqlite3_free( p );
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user