SQLite

Check-in [8830bbbac8]
Login

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

Overview
Comment:Convert the unix driver to use a recusive mutex. Similar changes to the windows driver are pending. (CVS 2968)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 8830bbbac8e0c9243956aac42dc9f86a0bd1fa07
User & Date: drh 2006-01-18 14:06:38.000
Context
2006-01-18
14:20
Recursive mutexes in os_win.c. (CVS 2969) (check-in: dd3e07cae4 user: drh tags: trunk)
14:06
Convert the unix driver to use a recusive mutex. Similar changes to the windows driver are pending. (CVS 2968) (check-in: 8830bbbac8 user: drh tags: trunk)
05:51
Handle malloc() failures that occur in open16() and errmsg16(). (CVS 2967) (check-in: 86eab9e53d user: danielk1977 tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/os_unix.c.
1663
1664
1665
1666
1667
1668
1669
1670


1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685





1686
1687
1688
1689
1690
1691
1692
1693




1694




1695
1696
1697
1698
1699
1700
1701



1702

1703
1704
1705
1706
1707
1708
1709
}

/*
** Static variables used for thread synchronization
*/
static int inMutex = 0;
#ifdef SQLITE_UNIX_THREADS
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;


#endif

/*
** The following pair of routine implement mutual exclusion for
** multi-threaded processes.  Only a single thread is allowed to
** executed code that is surrounded by EnterMutex() and LeaveMutex().
**
** SQLite uses only a single Mutex.  There is not much critical
** code and what little there is executes quickly and without blocking.
**
** This mutex is not recursive.
*/
void sqlite3UnixEnterMutex(){
#ifdef SQLITE_UNIX_THREADS
  pthread_mutex_lock(&mutex);





#endif
  assert( !inMutex );
  inMutex = 1;
}
void sqlite3UnixLeaveMutex(){
  assert( inMutex );
  inMutex = 0;
#ifdef SQLITE_UNIX_THREADS




  pthread_mutex_unlock(&mutex);




#endif
}

/*
** Return TRUE if we are currently within the mutex and FALSE if not.
*/
int sqlite3UnixInMutex(){



  return inMutex;

}

/*
** Remember the number of thread-specific-data blocks allocated.
** Use this to verify that we are not leaking thread-specific-data.
** Ticket #1601
*/







|
>
>














|
>
>
>
>
>

<
|


|
<

>
>
>
>
|
>
>
>
>







>
>
>

>







1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693

1694
1695
1696
1697

1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
}

/*
** Static variables used for thread synchronization
*/
static int inMutex = 0;
#ifdef SQLITE_UNIX_THREADS
static pthread_t mutexOwner;
static pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER;
#endif

/*
** The following pair of routine implement mutual exclusion for
** multi-threaded processes.  Only a single thread is allowed to
** executed code that is surrounded by EnterMutex() and LeaveMutex().
**
** SQLite uses only a single Mutex.  There is not much critical
** code and what little there is executes quickly and without blocking.
**
** This mutex is not recursive.
*/
void sqlite3UnixEnterMutex(){
#ifdef SQLITE_UNIX_THREADS
  pthread_mutex_lock(&mutex1);
  if( inMutex==0 ){
    pthread_mutex_lock(&mutex2);
    mutexOwner = pthread_self();
  }
  pthread_mutex_unlock(&mutex1);
#endif

  inMutex++;
}
void sqlite3UnixLeaveMutex(){
  assert( inMutex>0 );

#ifdef SQLITE_UNIX_THREADS
  assert( pthread_equal(mutexOwner, pthread_self()) );
  pthread_mutex_lock(&mutex1);
  inMutex--;
  if( inMutex==0 ){
    pthread_mutex_unlock(&mutex2);
  }
  pthread_mutex_unlock(&mutex1);
#else
  inMutex--;
#endif
}

/*
** Return TRUE if we are currently within the mutex and FALSE if not.
*/
int sqlite3UnixInMutex(){
#ifdef SQLITE_UNIX_THREADS
  return inMutex && pthread_equal(mutexOwner, pthread_self());
#else
  return inMutex;
#endif
}

/*
** Remember the number of thread-specific-data blocks allocated.
** Use this to verify that we are not leaking thread-specific-data.
** Ticket #1601
*/