1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-05 15:55:57 +03:00

Progress toward implementation of sqlite3_config() and a rework of the

mutex and memory allocation subsystems.  This is an incremental check-in. (CVS 5218)

FossilOrigin-Name: a03c5af115889f477e17187a198a7d2d40bc76bf
This commit is contained in:
drh
2008-06-13 18:24:27 +00:00
parent 655194d6ae
commit 40257ffd0a
26 changed files with 453 additions and 155 deletions

View File

@@ -11,7 +11,7 @@
*************************************************************************
** This file contains the C functions that implement mutexes for pthreads
**
** $Id: mutex_unix.c,v 1.7 2008/03/29 12:47:27 rse Exp $
** $Id: mutex_unix.c,v 1.8 2008/06/13 18:24:27 drh Exp $
*/
#include "sqliteInt.h"
@@ -45,6 +45,12 @@ struct sqlite3_mutex {
#define SQLITE3_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, 0, 0, (pthread_t)0 }
#endif
/*
** Initialize and deinitialize the mutex subsystem.
*/
int sqlite3_mutex_init(void){ return SQLITE_OK; }
int sqlite3_mutex_end(void){ return SQLITE_OK; }
/*
** The sqlite3_mutex_alloc() routine allocates a new
** mutex and returns a pointer to it. If it returns NULL
@@ -142,11 +148,12 @@ sqlite3_mutex *sqlite3_mutex_alloc(int iType){
** mutex that it allocates.
*/
void sqlite3_mutex_free(sqlite3_mutex *p){
assert( p );
assert( p->nRef==0 );
assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
pthread_mutex_destroy(&p->mutex);
sqlite3_free(p);
if( p ){
assert( p->nRef==0 );
assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
pthread_mutex_destroy(&p->mutex);
sqlite3_free(p);
}
}
/*
@@ -161,7 +168,7 @@ void sqlite3_mutex_free(sqlite3_mutex *p){
** more than once, the behavior is undefined.
*/
void sqlite3_mutex_enter(sqlite3_mutex *p){
assert( p );
if( p==0 ) return;
assert( p->id==SQLITE_MUTEX_RECURSIVE || sqlite3_mutex_notheld(p) );
#ifdef SQLITE_HOMEGROWN_RECURSIVE_MUTEX
@@ -202,7 +209,7 @@ void sqlite3_mutex_enter(sqlite3_mutex *p){
}
int sqlite3_mutex_try(sqlite3_mutex *p){
int rc;
assert( p );
if( p==0 ) return SQLITE_OK;
assert( p->id==SQLITE_MUTEX_RECURSIVE || sqlite3_mutex_notheld(p) );
#ifdef SQLITE_HOMEGROWN_RECURSIVE_MUTEX
@@ -257,7 +264,7 @@ int sqlite3_mutex_try(sqlite3_mutex *p){
** is not currently allocated. SQLite will never do either.
*/
void sqlite3_mutex_leave(sqlite3_mutex *p){
assert( p );
if( p==0 ) return;
assert( sqlite3_mutex_held(p) );
p->nRef--;
assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE );