SQLite

Check-in [7d24c3a5a7]
Login

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

Overview
Comment:Bug fix in the implementation of recursive mutexes using non-recursive pthreads mutexes. Ticket #2588. (CVS 4292)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 7d24c3a5a7641df2bbb8c91a0bc5aa75c96a73fe
User & Date: drh 2007-08-25 03:59:09.000
Context
2007-08-25
12:29
Make the test_async backend work again. (CVS 4293) (check-in: 04167483aa user: danielk1977 tags: trunk)
03:59
Bug fix in the implementation of recursive mutexes using non-recursive pthreads mutexes. Ticket #2588. (CVS 4292) (check-in: 7d24c3a5a7 user: drh tags: trunk)
2007-08-24
20:46
New mutex implementation for both Unix and windows. (CVS 4291) (check-in: e144b81f69 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/mutex.c.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the C functions that implement mutexes for
** use by the SQLite core.
**
** $Id: mutex.c,v 1.9 2007/08/24 20:46:59 drh Exp $
*/
/*
** If SQLITE_MUTEX_APPDEF is defined, then this whole module is
** omitted and equivalent functionality must be provided by the
** application that links against the SQLite library.
*/
#ifndef SQLITE_MUTEX_APPDEF







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the C functions that implement mutexes for
** use by the SQLite core.
**
** $Id: mutex.c,v 1.10 2007/08/25 03:59:09 drh Exp $
*/
/*
** If SQLITE_MUTEX_APPDEF is defined, then this whole module is
** omitted and equivalent functionality must be provided by the
** application that links against the SQLite library.
*/
#ifndef SQLITE_MUTEX_APPDEF
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
** 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){
  pthread_t self = pthread_self();
  if( pthread_equal(p->owner, self) && p->nRef>0 ){
    p->nRef++;
  }else{
    pthread_mutex_lock(&p->mutex);
    assert( p->nRef==0 );
    p->owner = self;
    p->nRef = 1;
  }
}
int sqlite3_mutex_try(sqlite3_mutex *p){
  pthread_t self = pthread_self();
  int rc;
  if( pthread_equal(p->owner, self) && p->nRef>0 ){
    p->nRef++;
    rc = SQLITE_OK;
  }else if( pthread_mutex_lock(&p->mutex)==0 ){
    assert( p->nRef==0 );
    p->owner = self;
    p->nRef = 1;
    rc = SQLITE_OK;







|











|







317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
** 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){
  pthread_t self = pthread_self();
  if( p->nRef>0 && pthread_equal(p->owner, self) ){
    p->nRef++;
  }else{
    pthread_mutex_lock(&p->mutex);
    assert( p->nRef==0 );
    p->owner = self;
    p->nRef = 1;
  }
}
int sqlite3_mutex_try(sqlite3_mutex *p){
  pthread_t self = pthread_self();
  int rc;
  if( p->nRef>0 && pthread_equal(p->owner, self) ){
    p->nRef++;
    rc = SQLITE_OK;
  }else if( pthread_mutex_lock(&p->mutex)==0 ){
    assert( p->nRef==0 );
    p->owner = self;
    p->nRef = 1;
    rc = SQLITE_OK;