aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordan <dan@noemail.net>2009-08-21 08:29:10 +0000
committerdan <dan@noemail.net>2009-08-21 08:29:10 +0000
commit9359c7b7abeb8f56b3038f2ef5c8a6632b16fb14 (patch)
treed6e822b86e34c29d78465528fd815f21aef262c0 /src
parent6085f5e0a0d81869b6aa12d4d763c6ee8e7a285c (diff)
downloadsqlite-9359c7b7abeb8f56b3038f2ef5c8a6632b16fb14.tar.gz
sqlite-9359c7b7abeb8f56b3038f2ef5c8a6632b16fb14.zip
Add assert() statements to os_unix.c to check that the mutex is held when it should be.
FossilOrigin-Name: 11a669b6537d6bac67764fd91a319234345ac504
Diffstat (limited to 'src')
-rw-r--r--src/os_unix.c43
1 files changed, 36 insertions, 7 deletions
diff --git a/src/os_unix.c b/src/os_unix.c
index cfaf2a2bd..f972b591d 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -260,7 +260,18 @@ struct unixFile {
/*
-** Helper functions to obtain and relinquish the global mutex.
+** Helper functions to obtain and relinquish the global mutex. The
+** global mutex is used to protect the unixOpenCnt, unixLockInfo and
+** vxworksFileId objects used by this file, all of which may be
+** shared by multiple threads.
+**
+** Function unixMutexHeld() is used to assert() that the global mutex
+** is held when required. This function is only used as part of assert()
+** statements. e.g.
+**
+** unixEnterMutex()
+** assert( unixMutexHeld() );
+** unixEnterLeave()
*/
static void unixEnterMutex(void){
sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
@@ -268,6 +279,11 @@ static void unixEnterMutex(void){
static void unixLeaveMutex(void){
sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
}
+#ifdef SQLITE_DEBUG
+static int unixMutexHeld(void) {
+ return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
+}
+#endif
#ifdef SQLITE_DEBUG
@@ -278,11 +294,11 @@ static void unixLeaveMutex(void){
*/
static const char *locktypeName(int locktype){
switch( locktype ){
- case NO_LOCK: return "NONE";
- case SHARED_LOCK: return "SHARED";
- case RESERVED_LOCK: return "RESERVED";
- case PENDING_LOCK: return "PENDING";
- case EXCLUSIVE_LOCK: return "EXCLUSIVE";
+ case NO_LOCK: return "NONE";
+ case SHARED_LOCK: return "SHARED";
+ case RESERVED_LOCK: return "RESERVED";
+ case PENDING_LOCK: return "PENDING";
+ case EXCLUSIVE_LOCK: return "EXCLUSIVE";
}
return "ERROR";
}
@@ -737,7 +753,7 @@ struct unixOpenCnt {
int nRef; /* Number of pointers to this structure */
int nLock; /* Number of outstanding locks */
int nPending; /* Number of pending close() operations */
- int *aPending; /* Malloced space holding fd's awaiting a close() */
+ int *aPending; /* Malloced space holding fds awaiting close() */
#if OS_VXWORKS
sem_t *pSem; /* Named POSIX semaphore */
char aSemName[MAX_PATHNAME+1]; /* Name of that semaphore */
@@ -848,8 +864,12 @@ static void testThreadLockingBehavior(int fd_orig){
/*
** Release a unixLockInfo structure previously allocated by findLockInfo().
+**
+** The mutex entered using the unixEnterMutex() function must be held
+** when this function is called.
*/
static void releaseLockInfo(struct unixLockInfo *pLock){
+ assert( unixMutexHeld() );
if( pLock ){
pLock->nRef--;
if( pLock->nRef==0 ){
@@ -871,8 +891,12 @@ static void releaseLockInfo(struct unixLockInfo *pLock){
/*
** Release a unixOpenCnt structure previously allocated by findLockInfo().
+**
+** The mutex entered using the unixEnterMutex() function must be held
+** when this function is called.
*/
static void releaseOpenCnt(struct unixOpenCnt *pOpen){
+ assert( unixMutexHeld() );
if( pOpen ){
pOpen->nRef--;
if( pOpen->nRef==0 ){
@@ -898,6 +922,9 @@ static void releaseOpenCnt(struct unixOpenCnt *pOpen){
** describes that file descriptor. Create new ones if necessary. The
** return values might be uninitialized if an error occurs.
**
+** The mutex entered using the unixEnterMutex() function must be held
+** when this function is called.
+**
** Return an appropriate error code.
*/
static int findLockInfo(
@@ -913,6 +940,8 @@ static int findLockInfo(
struct unixLockInfo *pLock = 0;/* Candidate unixLockInfo object */
struct unixOpenCnt *pOpen; /* Candidate unixOpenCnt object */
+ assert( unixMutexHeld() );
+
/* Get low-level information about the file that we can used to
** create a unique name for the file.
*/