SQLite

Check-in [af24e7d01a]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix locking bug in btshared.c. (CVS 4313)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: af24e7d01a7fab5e33080a0f786e0bc6f610a6f3
User & Date: drh 2007-08-28 16:44:20.000
Context
2007-08-28
19:21
remove unused os_os2.h (CVS 4314) (check-in: dd43a2de3e user: pweilbacher tags: trunk)
16:44
Fix locking bug in btshared.c. (CVS 4313) (check-in: af24e7d01a user: drh tags: trunk)
16:34
Break up the mutex implementation into separate source files, one each for unix, w32, and os2. (CVS 4312) (check-in: fc5cd71aef user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/btmutex.c.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
** 2007 August 27
**
** The author disclaims copyright to this source code.  In place of
** a legal notice, here is a blessing:
**
**    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.
**
*************************************************************************
**
** $Id: btmutex.c,v 1.1 2007/08/28 02:27:52 drh Exp $
**
** This file contains code used to implement mutexes on Btree objects.
** This code really belongs in btree.c.  But btree.c is getting too
** big and we want to break it down some.  This packaged seemed like
** a good breakout.
*/
#include "btreeInt.h"












|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
** 2007 August 27
**
** The author disclaims copyright to this source code.  In place of
** a legal notice, here is a blessing:
**
**    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.
**
*************************************************************************
**
** $Id: btmutex.c,v 1.2 2007/08/28 16:44:20 drh Exp $
**
** This file contains code used to implement mutexes on Btree objects.
** This code really belongs in btree.c.  But btree.c is getting too
** big and we want to break it down some.  This packaged seemed like
** a good breakout.
*/
#include "btreeInt.h"
81
82
83
84
85
86
87

88
89
90
91
92
93
94
    assert( !pLater->locked || pLater->wantToLock>0 );
    if( pLater->locked ){
      sqlite3_mutex_leave(pLater->pBt->mutex);
      pLater->locked = 0;
    }
  }
  sqlite3_mutex_enter(p->pBt->mutex);

  for(pLater=p->pNext; pLater; pLater=pLater->pNext){
    if( pLater->wantToLock ){
      sqlite3_mutex_enter(pLater->pBt->mutex);
      pLater->locked = 1;
    }
  }
}







>







81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
    assert( !pLater->locked || pLater->wantToLock>0 );
    if( pLater->locked ){
      sqlite3_mutex_leave(pLater->pBt->mutex);
      pLater->locked = 0;
    }
  }
  sqlite3_mutex_enter(p->pBt->mutex);
  p->locked = 1;
  for(pLater=p->pNext; pLater; pLater=pLater->pNext){
    if( pLater->wantToLock ){
      sqlite3_mutex_enter(pLater->pBt->mutex);
      pLater->locked = 1;
    }
  }
}
164
165
166
167
168
169
170

171
172
173
174
175
176
177

    /* We should already hold a lock on the database connection */
    assert( sqlite3BtreeMutexHeld(p->pSqlite->mutex) );

    p->wantToLock++;
    if( !p->locked ){
      sqlite3_mutex_enter(p->pBt->mutex);

    }
  }
}

/*
** Leave the mutex of every btree in the set.
*/







>







165
166
167
168
169
170
171
172
173
174
175
176
177
178
179

    /* We should already hold a lock on the database connection */
    assert( sqlite3BtreeMutexHeld(p->pSqlite->mutex) );

    p->wantToLock++;
    if( !p->locked ){
      sqlite3_mutex_enter(p->pBt->mutex);
      p->locked = 1;
    }
  }
}

/*
** Leave the mutex of every btree in the set.
*/
187
188
189
190
191
192
193

194
195
196
197
198
199

    /* We should already hold a lock on the database connection */
    assert( sqlite3BtreeMutexHeld(p->pSqlite->mutex) );

    p->wantToLock--;
    if( p->wantToLock==0 ){
      sqlite3_mutex_leave(p->pBt->mutex);

    }
  }
}


#endif  /* SQLITE_THREADSAFE && !SQLITE_OMIT_SHARED_CACHE */







>






189
190
191
192
193
194
195
196
197
198
199
200
201
202

    /* We should already hold a lock on the database connection */
    assert( sqlite3BtreeMutexHeld(p->pSqlite->mutex) );

    p->wantToLock--;
    if( p->wantToLock==0 ){
      sqlite3_mutex_leave(p->pBt->mutex);
      p->locked = 0;
    }
  }
}


#endif  /* SQLITE_THREADSAFE && !SQLITE_OMIT_SHARED_CACHE */