1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Remove unnecessary #includes of "os.h". New mutex implementations. (CVS 4255)

FossilOrigin-Name: fbbd5bda544ffec4e1b43407b12e546235dc7873
This commit is contained in:
drh
2007-08-21 10:44:15 +00:00
parent a2451e2255
commit 29278e3dbb
39 changed files with 259 additions and 196 deletions

View File

@@ -1,5 +1,5 @@
C The\squick\stest\sruns\sagain\swith\sa\shandfull\sof\serrors\safter\sadding\sthe\nmutex\slocks\sto\sbtree,\sthe\sVFS\sregistration\sinterfaces,\sand\sFTS3.\s(CVS\s4254)
D 2007-08-20T23:50:25
C Remove\sunnecessary\s#includes\sof\s"os.h".\s\sNew\smutex\simplementations.\s(CVS\s4255)
D 2007-08-21T10:44:16
F Makefile.in 0c0e53720f658c7a551046442dd7afba0b72bfbe
F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -86,41 +86,41 @@ F src/btreeInt.h e93edf57832278138b98cf60cbc54241103c6988
F src/build.c add67be992307b4b11849a6611bfd3352aacde92
F src/callback.c 143436453bb93e831c9574fea0b9b9eb90e40ff3
F src/complete.c ea63834e798a0ab14159bdc6e6cabc3df21aa346
F src/date.c 8c37dbbabc9fceec51e8adfcd771328345679b14
F src/date.c 70a5af1944c0b76bed917cab3c1ca47e5f97d359
F src/delete.c 849846d06d29851dde0d9f424a5de5817eb140d1
F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b
F src/expr.c 3ea108a9e409f58b8203e29c54442da5085be5bf
F src/func.c 472c0610164180624ff5aa51b0521a331bfef11b
F src/func.c 8516d5f97ddc1004537490fbaffa9a8b0da5c4bb
F src/hash.c 2f322979071dd2bdba7503b5276d66f028744382
F src/hash.h 3ad3da76bfb954978d227bf495568b0e6da2c19e
F src/insert.c 633322aef1799f6604fa805e12488bc628570b0c
F src/legacy.c 6013a7cb7da1b72550b3d35d4fc598b3c3e5b8c1
F src/legacy.c a83519a8fbb488c3155fca577b010d590ec479e9
F src/limits.h 71ab25f17e35e0a9f3f6f234b8ed49cc56731d35
F src/loadext.c c0ccda3dbda109da087a8fd762deebe5fdf24a1d
F src/main.c 7310dd532c1ff751772b196c98f7e0534afd7e58
F src/malloc.c 613c65f12ff0ee4edd017aa458209ab7a23cd7b1
F src/loadext.c 245ef19db91d86b394ad50366d69f160c46764d9
F src/main.c 3f8917757c7f6a937e300b613b9cfd1bbe703c70
F src/malloc.c c2f5da620d8e030c6974a0ddcaeb7b408c9bdb3d
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
F src/mem1.c 30bf8be3846f92fdf88c490c5e5378512383bcbe
F src/mem2.c 482f0aaf14e8ef1db64cb8c5b9a9bfe708297c92
F src/mutex.c 60051a86c49cfe2ec15dd8b1d9d0d530b8893b07
F src/os.c c9f91550afa071c5b98042ce14d38a2d87c3f4df
F src/os.h da098cad985b4849fefdd6a96d671b332008aa55
F src/mutex.c 56bd91271f18300aa7da45608bd8956abe471d10
F src/os.c dfe4718104a795c4a5e4cd927b6b00c24c004c58
F src/os.h 399c89cafa93b9ef35c3dc70f77644d10936b535
F src/os_common.h a5c446d3b93f09f369d13bf217de4bed3437dd1c
F src/os_os2.c cba4e96fadb949076c717108fe0599d1a3c2e446
F src/os_os2.c 8769301bff502de642ad2634cedcb77d967ce199
F src/os_os2.h c3f7d0af7e3453d1d7aa81b06c0a56f5a226530b
F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c
F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3
F src/os_unix.c 41a737d14d00b93fae8efd0d0555922f07a29ada
F src/os_unix.c 55e4d3c441e6b9e2dd36160e61df827bac1ea41d
F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
F src/os_win.c d868d5f9e95ec9c1b9e2a30c54c996053db6dddd
F src/os_win.c 29c0e19c1072679a4c7818c49fab2f35d2ad7747
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
F src/pager.c 53af3942f97b077886e035ed15781d1f887713b6
F src/pager.c bb25ee85c990241be0f321978e6c5f6b645692b2
F src/pager.h 53087c6fb9db01aed17c7fd044662a27507e89b8
F src/parse.y c03529c3b82702ada98ce405b390e3a9409708cf
F src/pragma.c 8f5e37c3cf6dbdeb3645bb80cc58cfc3324c0178
F src/prepare.c 03292beeffce2d65debab12508a8ec1f5aec7241
F src/parse.y 2d2ce439dc6184621fb0b86f4fc5aca7f391a590
F src/pragma.c 9b989506a1b7c8aecd6befb8235e2f57a4aba7e5
F src/prepare.c 5bc8c7a943215302943fec831f8c646f6dfdf76a
F src/printf.c a8f46e0ed360c18d40e89aa636533be300b406c2
F src/random.c af7264b4ed93330b3bf40dd123e16e7f8f62e5bb
F src/random.c 89b2c5a97f5059c486c021ffc2d72c9d779ccae8
F src/select.c 98c367bce3f38c5adfcc97de9ab5c79b0e5dc2b2
F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
F src/shell.c ac29402b538515fa4697282387be9c1205e6e9eb
@@ -129,41 +129,41 @@ F src/sqlite3ext.h 647a6b8a8f76ff6c9611e4a071531d8e63ff2d6b
F src/sqliteInt.h 6891d6864a6b9fc661eadaa0328e81dff7523584
F src/sqliteLimit.h f14609c27636ebc217c9603ade26dbdd7d0f6afa
F src/table.c c725e47f6f3092b9a7b569fc58e408e2173ee008
F src/tclsqlite.c 0606c4f31711492eb4d7480a981eebb80914f3d9
F src/test1.c 6ae17d70dac0f14ab632f66c026a44fb0c71f22e
F src/test2.c 4506b6635e193a19a9bccdbe366ff4aed09cbe79
F src/test3.c b6d6a452a394c690395b1d7155e7bf00fb99a12d
F src/test4.c 1f4d2ed89867bac187d49ed8004f121592987d3e
F src/test5.c 7bc8a87c2b6fd076ec2ca9972946e71a367883ad
F src/test6.c b0090b4826d5e06df2ff2d5acaddf3f8f708fcd2
F src/test7.c 0f9d91ce8018740d5eb6e258f0fac2a2943c40f0
F src/test8.c 719c284607c1e91a893f5425df1e92b74c859aef
F src/test9.c c0f38f7795cc51d37db6c63874d90f40f10d0f0e
F src/test_async.c ba48913e4bab43b149747d3bdd3b75b1f66658ec
F src/tclsqlite.c 299fb45c5cf983b49b2c984b87b936b8132fbfe2
F src/test1.c 9e9651b0b9f85654b4bf28dfad787bc21a33aae5
F src/test2.c 4f742e99ed1bea5c14692f627bdb59a146f30504
F src/test3.c 2e4da0fe90a0aa8cf9276ea34cbe92e91dc1db07
F src/test4.c d97b87919dc3db1cc5fccc04a33f030d5940e1a9
F src/test5.c 81353afad5d795ae7155bffce1e4deef10ee8e22
F src/test6.c 9a93a5538f4ec008e8471635889091b087328532
F src/test7.c 50f5aa04fd751528ad5ee50e9be9ecee6f0b574a
F src/test8.c 4bf571b82e502094846ae06e30fe028f190aaaae
F src/test9.c b46c8fe02ac7cca1a7316436d8d38d50c66f4b2f
F src/test_async.c 9f3ab66e848930d1c3a7bc2dde77b9b643f6e4ba
F src/test_autoext.c 855157d97aa28cf84233847548bfacda21807436
F src/test_btree.c c1308ba0b88ab577fa56c9e493a09829dfcded9c
F src/test_config.c 6e2cad5669f13b38b8e02850157448a757f21df7
F src/test_config.c 6c74d82fd4a0a5a3bebd53a9cb2cb6c02af68e07
F src/test_hexio.c 82916f918687502658f02533b519c38cb180db6d
F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8
F src/test_malloc.c d9ba6be85f9c4a439b19f6e0a72d91c369d72c63
F src/test_md5.c d9f828765b242ff86f58cd879259c3da4eaede02
F src/test_schema.c 12c9de7661d6294eec2d57afbb52e2af1128084f
F src/test_server.c 319f6b1a99bab5f7149387442243d6e65a8ab4eb
F src/test_tclvar.c 160290ba5c19964da7cb97defc6c104712074b69
F src/tokenize.c 3a3fd71cfb2abb8e11ed6ab6b764b790c534defc
F src/test_tclvar.c b2d1115e4d489179d3f029e765211b2ad527ba59
F src/tokenize.c e39527c9c867774a92716c669a48ad8fbc3cdc63
F src/trigger.c dccc6fbf37d12193c90ede5b026bbd195d505ff4
F src/update.c e89b980b443d44b68bfc0b1746cdb6308e049ac9
F src/utf.c 853f97ce0d3cff8dbaef517a6dc475f7001a67c5
F src/util.c 0273ba16dbf9bab423b1b84c6d548d8f14c25f64
F src/vacuum.c f45bd9d3aad8d68bb3b85cf89d7a797be5075fde
F src/vdbe.c b5cd895a0516466daacc564da332589a903e2eb0
F src/util.c 23251cee7867dfdcc80b05d278dbca71586d95cf
F src/vacuum.c 318ccae7c4e3ddf241aeaee4d2611bfe1949a373
F src/vdbe.c f1a9a29da48ccfa49042df478abb478520589f37
F src/vdbe.h 001c5b257567c1d3de7feb2203aac71d0d7b16a3
F src/vdbeInt.h 8e360d326328e7a66100f468697edf9cfb4567dc
F src/vdbeapi.c ddfe341249929b89c47a0ff77f8043ef0987612b
F src/vdbeaux.c d2e8a63e9aea8527c79ae523036cc8f762b267a2
F src/vdbeapi.c ffd28fa0f731467a1e63155abc74cd149e57d671
F src/vdbeaux.c 14b48bfc6334682e5e5858a0835f8b00d8751953
F src/vdbeblob.c cf9ee3c7d9977cbd896f8b118da4fb4268637f4f
F src/vdbefifo.c 334c838c8f42d61a94813d136019ee566b5dc2f6
F src/vdbemem.c 019952d44066a24aef70ca8c284cfd2d1073c398
F src/vdbemem.c 2843e6f91e8f19cfd72cfc7b24a03f1647db3c28
F src/vtab.c ee29237ecc9b310dc43c0c2ac5caa6c6a20787be
F src/where.c 2776a0caf8cbbfd6ec79cfb1cd9bc25074055e5e
F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
@@ -557,7 +557,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P 1315bd8e125602275fb718780f9b2730bd37f6ab
R d4fae6ff2f91391abff6a85b93359df7
P 6cf725d212d468cbd7c7cbc22ca5ab13f1d77939
R bc41d2a41155d3978aad1298f4dc479f
U drh
Z bdcd45a572300c8ecdfe8272f9cd3707
Z 6fdad79122af6697e52d8395a5ab70ee

View File

@@ -1 +1 @@
6cf725d212d468cbd7c7cbc22ca5ab13f1d77939
fbbd5bda544ffec4e1b43407b12e546235dc7873

View File

@@ -16,7 +16,7 @@
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: date.c,v 1.69 2007/08/18 10:59:20 danielk1977 Exp $
** $Id: date.c,v 1.70 2007/08/21 10:44:16 drh Exp $
**
** SQLite processes all times and dates as Julian Day numbers. The
** dates and times are stored as the number of days since noon
@@ -46,7 +46,6 @@
** Richmond, Virginia (USA)
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>
#include <stdlib.h>
#include <assert.h>

View File

@@ -16,15 +16,13 @@
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: func.c,v 1.166 2007/08/16 10:36:34 danielk1977 Exp $
** $Id: func.c,v 1.167 2007/08/21 10:44:16 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
/* #include <math.h> */
#include <stdlib.h>
#include <assert.h>
#include "vdbeInt.h"
#include "os.h"
/*

View File

@@ -14,11 +14,10 @@
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: legacy.c,v 1.19 2007/08/16 04:30:40 drh Exp $
** $Id: legacy.c,v 1.20 2007/08/21 10:44:16 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>
/*

View File

@@ -17,7 +17,6 @@
#define SQLITE_CORE 1 /* Disable the API redefinition in sqlite3ext.h */
#include "sqlite3ext.h"
#include "sqliteInt.h"
#include "os.h"
#include <string.h>
#include <ctype.h>

View File

@@ -14,10 +14,9 @@
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.389 2007/08/20 22:48:42 drh Exp $
** $Id: main.c,v 1.390 2007/08/21 10:44:16 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>
/*

View File

@@ -12,10 +12,9 @@
** Memory allocation functions used throughout sqlite.
**
**
** $Id: malloc.c,v 1.6 2007/08/16 10:09:03 danielk1977 Exp $
** $Id: malloc.c,v 1.7 2007/08/21 10:44:16 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <stdarg.h>
#include <ctype.h>

View File

@@ -12,21 +12,42 @@
** This file contains the C functions that implement mutexes for
** use by the SQLite core.
**
** $Id: mutex.c,v 1.5 2007/08/20 22:48:43 drh Exp $
** $Id: mutex.c,v 1.6 2007/08/21 10:44:16 drh Exp $
*/
/*
** If SQLITE_MUTEX_APPDEF is defined, then this whole module is
** omitted and equivalent functionality just be provided by the
** omitted and equivalent functionality must be provided by the
** application that links against the SQLite library.
*/
#ifndef SQLITE_MUTEX_APPDEF
/*
** The start of real code
/* This is the beginning of real code
*/
#include "sqliteInt.h"
/*
** Figure out what version of the code to use
*/
#define SQLITE_MUTEX_NOOP 1 /* The default */
#if 0
#if defined(SQLITE_DEBUG) && !SQLITE_THREADSAFE
# undef SQLITE_MUTEX_NOOP
# define SQLITE_MUTEX_NOOP_DEBUG
#endif
#if defined(SQLITE_MUTEX_NOOP) && SQLITE_THREADSAFE && OS_UNIX
# undef SQLITE_MUTEX_NOOP
# define SQLITE_MUTEX_PTHREAD
#endif
#if defined(SQLITE_MUTEX_NOOP) && SQLITE_THREADSAFE && OS_WIN
# undef SQLITE_MUTEX_NOOP
# define SQLITE_MUTEX_WIN
#endif
#endif
#ifdef SQLITE_MUTEX_NOOP
/************************ No-op Mutex Implementation **********************
**
** This first implementation of mutexes is really a no-op. In other words,
@@ -81,8 +102,112 @@ int sqlite3_mutex_held(sqlite3_mutex *pNotUsed){
int sqlite3_mutex_notheld(sqlite3_mutex *pNotUsed){
return 1;
}
#endif /* SQLITE_MUTEX_NOOP */
#if 0
#ifdef SQLITE_MUTEX_NOOP_DEBUG
/*************** Error-checking No-op Mutex Implementation *******************
**
** In this implementation, mutexes do not provide any mutual exclusion.
** But the error checking is provided. This implementation is useful
** for test purposes.
*/
/*
** The mutex object
*/
struct sqlite3_mutex {
int id;
int cnt;
};
/*
** The sqlite3_mutex_alloc() routine allocates a new
** mutex and returns a pointer to it. If it returns NULL
** that means that a mutex could not be allocated.
*/
sqlite3_mutex *sqlite3_mutex_alloc(int id){
static sqlite3_mutex aStatic[3];
sqlite3_mutex *pNew = 0;
switch( id ){
case SQLITE_MUTEX_FAST:
case SQLITE_MUTEX_RECURSIVE: {
pNew = sqlite3_malloc(sizeof(*pNew));
if( pNew ){
pNew->id = id;
pNew->cnt = 0;
}
break;
}
default: {
pNew = &aStatic[id-SQLITE_MUTEX_STATIC_MASTER];
pNew->id = id;
break;
}
}
return pNew;
}
/*
** This routine deallocates a previously allocated mutex.
*/
void sqlite3_mutex_free(sqlite3_mutex *p){
assert( p );
assert( p->cnt==0 );
assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
sqlite3_free(p);
}
/*
** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
** to enter a mutex. If another thread is already within the mutex,
** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
** SQLITE_BUSY. The sqlite3_mutex_try() interface returns SQLITE_OK
** upon successful entry. Mutexes created using SQLITE_MUTEX_RECURSIVE can
** be entered multiple times by the same thread. In such cases the,
** mutex must be exited an equal number of times before another thread
** can enter. If the same thread tries to enter any other kind of mutex
** more than once, the behavior is undefined.
*/
void sqlite3_mutex_enter(sqlite3_mutex *p){
assert( p );
assert( p->cnt==0 || p->id==SQLITE_MUTEX_RECURSIVE );
p->cnt++;
}
int sqlite3_mutex_try(sqlite3_mutex *p){
assert( p );
if( p->cnt>0 && p->id!=SQLITE_MUTEX_RECURSIVE ){
return SQLITE_BUSY;
}
p->cnt++;
return SQLITE_OK;
}
/*
** The sqlite3_mutex_leave() routine exits a mutex that was
** previously entered by the same thread. The behavior
** is undefined if the mutex is not currently entered or
** is not currently allocated. SQLite will never do either.
*/
void sqlite3_mutex_leave(sqlite3_mutex *p){
assert( p->cnt>0 );
p->cnt--;
}
/*
** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
** intended for use inside assert() statements.
*/
int sqlite3_mutex_held(sqlite3_mutex *p){
return p==0 || p->cnt>0;
}
int sqlite3_mutex_notheld(sqlite3_mutex *p){
return p==0 || p->cnt==0;
}
#endif /* SQLITE_MUTEX_NOOP_DEBUG */
#ifdef SQLITE_MUTEX_PTHREAD
/**************** Non-recursive Pthread Mutex Implementation *****************
**
** This implementation of mutexes is built using a version of pthreads that
@@ -92,41 +217,14 @@ int sqlite3_mutex_notheld(sqlite3_mutex *pNotUsed){
/*
** Each recursive mutex is an instance of the following structure.
*/
struct RMutex {
int recursiveMagic; /* Magic number identifying this as recursive */
int nRef; /* Number of entrances */
pthread_mutex_t auxMutex; /* Mutex controlling access to nRef and owner */
struct sqlite3_mutex {
pthread_mutex_t mainMutex; /* Mutex controlling the lock */
pthread_mutex_t auxMutex; /* Mutex controlling access to nRef and owner */
int id; /* Mutex type */
int nRef; /* Number of entrances */
pthread_t owner; /* Thread that is within this mutex */
};
/*
** Each fast mutex is an instance of the following structure
*/
struct FMutex {
int fastMagic; /* Identifies this as a fast mutex */
pthread_mutex_t mutex; /* The actual underlying mutex */
};
/*
** Either of the above
*/
union AnyMutex {
struct RMutex r;
struct FMutex f;
};
/*
** Magic numbers
*/
#define SQLITE_MTX_RECURSIVE 0x4ED886ED
#define SQLITE_MTX_STATIC 0x56FCE1B4
#define SQLITE_MTX_FAST 0x245BFD4F
/*
** Static mutexes
*/
/*
** The sqlite3_mutex_alloc() routine allocates a new
** mutex and returns a pointer to it. If it returns NULL
@@ -167,35 +265,34 @@ union AnyMutex {
** the same type number.
*/
sqlite3_mutex *sqlite3_mutex_alloc(int iType){
static struct FMutex staticMutexes[] = {
{ SQLITE_MTX_STATIC, PTHREAD_MUTEX_INITIALIZER },
{ SQLITE_MTX_STATIC, PTHREAD_MUTEX_INITIALIZER },
{ SQLITE_MTX_STATIC, PTHREAD_MUTEX_INITIALIZER },
static sqlite3_mutex staticMutexes[] = {
{ PTHREAD_MUTEX_INITIALIZER, },
{ PTHREAD_MUTEX_INITIALIZER, },
{ PTHREAD_MUTEX_INITIALIZER, },
};
sqlite3_mutex *p;
switch( iType ){
case SQLITE_MUTEX_FAST: {
struct FMutex *px = sqlite3_malloc( sizeof(*px) );
if( px ){
px->fastMagic = SQLITE_MTX_FAST;
pthread_mutex_init(&px->mutex, 0);
p = sqlite3MallocZero( sizeof(*p) );
if( p ){
p->id = iType;
pthread_mutex_init(&px->mainMutex, 0);
}
p = (sqlite3_mutex*)px;
break;
}
case SQLITE_MUTEX_RECURSIVE: {
struct RMutex *px = sqlite3_malloc( sizeof(*px) );
if( px ){
px->recursiveMagic = SQLITE_MTX_RECURSIVE;
p = sqlite3_malloc( sizeof(*p) );
if( p ){
px->id = iType;
pthread_mutex_init(&px->auxMutex, 0);
pthread_mutex_init(&px->mainMutex, 0);
px->nRef = 0;
}
p = (sqlite3_mutex*)px;
break;
}
default: {
p = &staticMutexes[iType-2];
p->id = iType;
break;
}
}
@@ -208,18 +305,17 @@ sqlite3_mutex *sqlite3_mutex_alloc(int iType){
** allocated mutex. SQLite is careful to deallocate every
** mutex that it allocates.
*/
void sqlite3_mutex_free(sqlite3_mutex *pMutex){
int iType = *(int*)pMutex;
if( iType==SQLITE_MTX_FAST ){
struct FMutex *p = (struct FMutex*)pMutex;
pthread_mutex_destroy(&p->mutex);
sqlite3_free(p);
}else if( iType==SQLITE_MTX_RECURSIVE ){
struct RMutex *p = (struct RMutex*)pMutex;
void sqlite3_mutex_free(sqlite3_mutex *p){
assert( p );
assert( p->nRef==0 );
if( p->id==SQLITE_MUTEX_FAST ){
pthread_mutex_destroy(&p->mainMutex);
}else{
assert( p->id==SQLITE_MUTEX_RECURSIVE );
pthread_mutex_destroy(&p->auxMutex);
pthread_mutex_destroy(&p->mainMutex);
sqlite3_free(p);
}
sqlite3_free(p);
}
/*
@@ -233,12 +329,8 @@ void sqlite3_mutex_free(sqlite3_mutex *pMutex){
** can enter. If the same thread tries to enter any other kind of mutex
** more than once, the behavior is undefined.
*/
void sqlite3_mutex_enter(sqlite3_mutex *pMutex){
if( SQLITE_MTX_FAST == *(int*)pMutex ){
struct FMutex *p = (struct FMutex*)pMutex;
pthread_mutex_lock(&p->mutex);
}else{
struct RMutex *p = (struct RMutex*)pMutex;
void sqlite3_mutex_enter(sqlite3_mutex *p){
if( p->id==SQLITE_MUTEX_RECURSIVE ){
while(1){
pthread_mutex_lock(&p->auxMutex);
if( p->nRef==0 ){
@@ -257,16 +349,15 @@ void sqlite3_mutex_enter(sqlite3_mutex *pMutex){
pthread_mutex_unlock(&p->mainMutex);
}
}
}else{
assert( p->nRef==0 || pthread_equal(p->owner, pthread_self())==0 );
pthread_mutex_lock(&p->mutex);
assert( (p->nRef = 1)!=0 );
assert( (p->owner = pthread_self())==pthread_self() );
}
}
int sqlite3_mutex_try(sqlite3_mutex *pMutex){
if( SQLITE_MTX_FAST == *(int*)pMutex ){
struct FMutex *p = (struct FMutex*)pMutex;
if( pthread_mutex_trylock(&p->mutex) ){
return SQLITE_BUSY;
}
}else{
struct RMutex *p = (struct RMutex*)pMutex;
int sqlite3_mutex_try(sqlite3_mutex *p){
if( p->id==SQLITE_MUTEX_RECURSIVE ){
pthread_mutex_lock(&p->auxMutex);
if( p->nRef==0 ){
p->nRef++;
@@ -280,28 +371,36 @@ int sqlite3_mutex_try(sqlite3_mutex *pMutex){
pthread_mutex_unlock(&p->auxMutex);
return SQLITE_BUSY;
}
}else{
assert( p->nRef==0 || pthread_equal(p->owner, pthread_self())==0 );
if( pthread_mutex_trylock(&p->mutex) ){
return SQLITE_BUSY;
}
}
return SQLITE_OK;
}
/*
** The sqlite3_mutex_exit() routine exits a mutex that was
** The sqlite3_mutex_leave() routine exits a mutex that was
** previously entered by the same thread. The behavior
** is undefined if the mutex is not currently entered or
** is not currently allocated. SQLite will never do either.
*/
void sqlite3_mutex_leave(sqlite3_mutex *pMutex){
if( SQLITE_MTX_FAST == *(int*)pMutex ){
struct FMutex *p = (struct FMutex*)pMutex;
pthread_mutex_unlock(&p->mutex);
}else{
struct RMutex *p = (struct RMutex*)pMutex;
if( p->id==SQLITE_MUTEX_RECURSIVE ){
pthread_mutex_lock(&p->auxMutex);
assert( p->nRef>0 );
assert( pthread_equal(p->owner, pthread_self()) );
p->nRef--;
if( p->nRef<=0 ){
pthread_mutex_unlock(&p->mainMutex);
}
pthread_mutex_unlock(&p->auxMutex);
}else{
assert( p->nRef==1 );
assert( pthread_equal(p->owner, pthread_self()) );
p->nRef = 0;
pthread_mutex_unlock(&p->mutex);
}
}
@@ -309,12 +408,14 @@ void sqlite3_mutex_leave(sqlite3_mutex *pMutex){
** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
** intended for use inside assert() statements.
*/
int sqlite3_mutex_held(sqlite3_mutex *pNotUsed){
return 1;
int sqlite3_mutex_held(sqlite3_mutex *p){
assert( p );
return p==0 || (p->nRef!=0 && pthread_equal(p->owner, pthread_self()));
}
int sqlite3_mutex_notheld(sqlite3_mutex *pNotUsed){
return 1;
assert( p );
return p==0 || p->nRef==0 || pthread_equal(p->owner, pthread_self())==0;
}
#endif /* non-recursive pthreads */
#endif /* SQLITE_MUTEX_PTHREAD */
#endif /* !defined(SQLITE_MUTEX_APPDEF) */

View File

@@ -15,7 +15,6 @@
*/
#define _SQLITE_OS_C_ 1
#include "sqliteInt.h"
#include "os.h"
#undef _SQLITE_OS_C_
/*

View File

@@ -13,13 +13,18 @@
** This header file (together with is companion C source-code file
** "os.c") attempt to abstract the underlying operating system so that
** the SQLite library will work on both POSIX and windows systems.
**
** This header file is #include-ed by sqliteInt.h and thus ends up
** being included by every source file.
*/
#ifndef _SQLITE_OS_H_
#define _SQLITE_OS_H_
/*
** Figure out if we are dealing with Unix, Windows, or some other
** operating system.
** operating system. After the following block of preprocess macros,
** all of OS_UNIX, OS_WIN, OS_OS2, and OS_OTHER will defined to either
** 1 or 0. One of the four will be 1. The other three will be 0.
*/
#if defined(OS_OTHER)
# if OS_OTHER==1
@@ -60,6 +65,7 @@
#endif
/*
** Define the maximum size of a temporary filename
*/

View File

@@ -14,7 +14,6 @@
*/
#include "sqliteInt.h"
#include "os.h"
#if OS_OS2

View File

@@ -13,7 +13,6 @@
** This file contains code that is specific to Unix systems.
*/
#include "sqliteInt.h"
#include "os.h"
#if OS_UNIX /* This file is used on unix only */
/* #define SQLITE_ENABLE_LOCKING_STYLE 0 */

View File

@@ -13,7 +13,6 @@
** This file contains code that is specific to windows.
*/
#include "sqliteInt.h"
#include "os.h"
#if OS_WIN /* This file is used for windows only */
#include <winbase.h>

View File

@@ -18,12 +18,10 @@
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.362 2007/08/20 16:07:01 danielk1977 Exp $
** @(#) $Id: pager.c,v 1.363 2007/08/21 10:44:16 drh Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
#include "os.h"
#include "pager.h"
#include <assert.h>
#include <string.h>

View File

@@ -14,7 +14,7 @@
** the parser. Lemon will also generate a header file containing
** numeric codes for all of the tokens.
**
** @(#) $Id: parse.y,v 1.233 2007/08/16 10:09:03 danielk1977 Exp $
** @(#) $Id: parse.y,v 1.234 2007/08/21 10:44:16 drh Exp $
*/
// All token codes are small integers with #defines that begin with "TK_"
@@ -55,7 +55,6 @@
//
%include {
#include "sqliteInt.h"
#include "parse.h"
/*
** An instance of this structure holds information about the

View File

@@ -11,21 +11,15 @@
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
** $Id: pragma.c,v 1.145 2007/08/17 15:53:37 danielk1977 Exp $
** $Id: pragma.c,v 1.146 2007/08/21 10:44:16 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>
/* Ignore this whole file if pragmas are disabled
*/
#if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER)
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
# include "pager.h"
# include "btree.h"
#endif
/*
** Interpret the given string as a safety level. Return 0 for OFF,
** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or

View File

@@ -13,10 +13,9 @@
** interface, and routines that contribute to loading the database schema
** from disk.
**
** $Id: prepare.c,v 1.54 2007/08/16 10:09:03 danielk1977 Exp $
** $Id: prepare.c,v 1.55 2007/08/21 10:44:16 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>
/*

View File

@@ -15,10 +15,9 @@
** Random numbers are used by some of the database backends in order
** to generate random integer keys for tables or random filenames.
**
** $Id: random.c,v 1.18 2007/08/20 22:48:43 drh Exp $
** $Id: random.c,v 1.19 2007/08/21 10:44:16 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
/*

View File

@@ -12,7 +12,7 @@
** A TCL Interface to SQLite. Append this file to sqlite3.c and
** compile the whole thing to build a TCL-enabled version of SQLite.
**
** $Id: tclsqlite.c,v 1.195 2007/08/15 19:16:43 drh Exp $
** $Id: tclsqlite.c,v 1.196 2007/08/21 10:44:16 drh Exp $
*/
#include "tcl.h"
#include <errno.h>
@@ -23,7 +23,6 @@
*/
#ifndef SQLITE_AMALGAMATION
# include "sqliteInt.h"
# include "hash.h"
# include <stdlib.h>
# include <string.h>
# include <assert.h>

View File

@@ -13,11 +13,10 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test1.c,v 1.265 2007/08/20 22:48:43 drh Exp $
** $Id: test1.c,v 1.266 2007/08/21 10:44:16 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include "os.h"
#include <stdlib.h>
#include <string.h>

View File

@@ -13,11 +13,9 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test2.c,v 1.49 2007/08/20 22:48:43 drh Exp $
** $Id: test2.c,v 1.50 2007/08/21 10:44:16 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include "pager.h"
#include "tcl.h"
#include <stdlib.h>
#include <string.h>

View File

@@ -13,11 +13,9 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test3.c,v 1.79 2007/08/20 23:50:25 drh Exp $
** $Id: test3.c,v 1.80 2007/08/21 10:44:16 drh Exp $
*/
#include "sqliteInt.h"
#include "pager.h"
#include "btree.h"
#include "tcl.h"
#include <stdlib.h>
#include <string.h>

View File

@@ -11,11 +11,10 @@
*************************************************************************
** Code for testing the the SQLite library in a multithreaded environment.
**
** $Id: test4.c,v 1.19 2007/08/20 22:48:43 drh Exp $
** $Id: test4.c,v 1.20 2007/08/21 10:44:16 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include "os.h"
#if defined(OS_UNIX) && OS_UNIX==1 && SQLITE_THREADSAFE
#include <stdlib.h>
#include <string.h>

View File

@@ -15,11 +15,10 @@
** is used for testing the SQLite routines for converting between
** the various supported unicode encodings.
**
** $Id: test5.c,v 1.18 2007/08/16 10:09:03 danielk1977 Exp $
** $Id: test5.c,v 1.19 2007/08/21 10:44:16 drh Exp $
*/
#include "sqliteInt.h"
#include "vdbeInt.h"
#include "os.h" /* to get SQLITE_BIGENDIAN */
#include "tcl.h"
#include <stdlib.h>
#include <string.h>

View File

@@ -16,7 +16,6 @@
*/
#if SQLITE_TEST /* This file is used for the testing only */
#include "sqliteInt.h"
#include "os.h"
#include "tcl.h"
#ifndef SQLITE_OMIT_DISKIO /* This file is a no-op if disk I/O is disabled */

View File

@@ -12,11 +12,10 @@
** Code for testing the client/server version of the SQLite library.
** Derived from test4.c.
**
** $Id: test7.c,v 1.6 2007/08/20 22:48:43 drh Exp $
** $Id: test7.c,v 1.7 2007/08/21 10:44:16 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include "os.h"
/*
** This test only works on UNIX with a SQLITE_THREADSAFE build that includes

View File

@@ -13,11 +13,10 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test8.c,v 1.51 2007/08/16 11:36:15 danielk1977 Exp $
** $Id: test8.c,v 1.52 2007/08/21 10:44:16 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include "os.h"
#include <stdlib.h>
#include <string.h>

View File

@@ -14,11 +14,10 @@
** for completeness. Test code is written in C for these cases
** as there is not much point in binding to Tcl.
**
** $Id: test9.c,v 1.3 2007/04/23 23:56:32 drh Exp $
** $Id: test9.c,v 1.4 2007/08/21 10:44:16 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include "os.h"
#include <stdlib.h>
#include <string.h>

View File

@@ -71,7 +71,6 @@
*/
#include "sqliteInt.h"
#include "os.h"
#include <tcl.h>
/*

View File

@@ -16,11 +16,10 @@
** The focus of this file is providing the TCL testing layer
** access to compile-time constants.
**
** $Id: test_config.c,v 1.10 2007/08/20 23:50:25 drh Exp $
** $Id: test_config.c,v 1.11 2007/08/21 10:44:16 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include "os.h"
#include <stdlib.h>
#include <string.h>

View File

@@ -16,11 +16,10 @@
** The emphasis of this file is a virtual table that provides
** access to TCL variables.
**
** $Id: test_tclvar.c,v 1.13 2007/08/16 11:36:15 danielk1977 Exp $
** $Id: test_tclvar.c,v 1.14 2007/08/21 10:44:16 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include "os.h"
#include <stdlib.h>
#include <string.h>

View File

@@ -15,10 +15,9 @@
** individual tokens and sends those tokens one-by-one over to the
** parser for analysis.
**
** $Id: tokenize.c,v 1.133 2007/08/16 10:09:03 danielk1977 Exp $
** $Id: tokenize.c,v 1.134 2007/08/21 10:44:16 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>
#include <stdlib.h>

View File

@@ -14,10 +14,9 @@
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
** $Id: util.c,v 1.209 2007/08/16 10:09:03 danielk1977 Exp $
** $Id: util.c,v 1.210 2007/08/21 10:44:16 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <stdarg.h>
#include <ctype.h>

View File

@@ -14,11 +14,10 @@
** Most of the code in this file may be omitted by defining the
** SQLITE_OMIT_VACUUM macro.
**
** $Id: vacuum.c,v 1.70 2007/08/16 04:30:40 drh Exp $
** $Id: vacuum.c,v 1.71 2007/08/21 10:44:16 drh Exp $
*/
#include "sqliteInt.h"
#include "vdbeInt.h"
#include "os.h"
#if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
/*

View File

@@ -43,10 +43,9 @@
** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
** $Id: vdbe.c,v 1.642 2007/08/17 15:53:37 danielk1977 Exp $
** $Id: vdbe.c,v 1.643 2007/08/21 10:44:16 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>
#include <math.h>
#include "vdbeInt.h"

View File

@@ -15,7 +15,6 @@
*/
#include "sqliteInt.h"
#include "vdbeInt.h"
#include "os.h"
/*
** Return TRUE (non-zero) of the statement supplied as an argument needs

View File

@@ -15,7 +15,6 @@
** But that file was getting too big so this subroutines were split out.
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>
#include "vdbeInt.h"

View File

@@ -16,7 +16,6 @@
** name sqlite_value
*/
#include "sqliteInt.h"
#include "os.h"
#include <math.h>
#include <ctype.h>
#include "vdbeInt.h"