mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-12 13:01:09 +03:00
Remove the thread specific data subsystem from the unix build. Remove
legacy cruft from sqliteInt.h. Use the new mutex subsystem in the PRNG. (CVS 4237) FossilOrigin-Name: 3d60c14a32955b69e714a73372924d421899f83b
This commit is contained in:
108
src/os_unix.c
108
src/os_unix.c
@@ -2816,112 +2816,6 @@ int sqlite3UnixInMutex(int thisThrd){
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
** Remember the number of thread-specific-data blocks allocated.
|
||||
** Use this to verify that we are not leaking thread-specific-data.
|
||||
** Ticket #1601
|
||||
*/
|
||||
#ifdef SQLITE_TEST
|
||||
int sqlite3_tsd_count = 0;
|
||||
# ifdef SQLITE_UNIX_THREADS
|
||||
static pthread_mutex_t tsd_counter_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
# define TSD_COUNTER(N) \
|
||||
pthread_mutex_lock(&tsd_counter_mutex); \
|
||||
sqlite3_tsd_count += N; \
|
||||
pthread_mutex_unlock(&tsd_counter_mutex);
|
||||
# else
|
||||
# define TSD_COUNTER(N) sqlite3_tsd_count += N
|
||||
# endif
|
||||
#else
|
||||
# define TSD_COUNTER(N) /* no-op */
|
||||
#endif
|
||||
|
||||
/*
|
||||
** If called with allocateFlag>0, then return a pointer to thread
|
||||
** specific data for the current thread. Allocate and zero the
|
||||
** thread-specific data if it does not already exist.
|
||||
**
|
||||
** If called with allocateFlag==0, then check the current thread
|
||||
** specific data. Return it if it exists. If it does not exist,
|
||||
** then return NULL.
|
||||
**
|
||||
** If called with allocateFlag<0, check to see if the thread specific
|
||||
** data is allocated and is all zero. If it is then deallocate it.
|
||||
** Return a pointer to the thread specific data or NULL if it is
|
||||
** unallocated or gets deallocated.
|
||||
*/
|
||||
ThreadData *sqlite3UnixThreadSpecificData(int allocateFlag){
|
||||
static const ThreadData zeroData = {0}; /* Initializer to silence warnings
|
||||
** from broken compilers */
|
||||
#ifdef SQLITE_UNIX_THREADS
|
||||
static pthread_key_t key;
|
||||
static int keyInit = 0;
|
||||
ThreadData *pTsd;
|
||||
|
||||
if( !keyInit ){
|
||||
sqlite3OsEnterMutex();
|
||||
if( !keyInit ){
|
||||
int rc;
|
||||
rc = pthread_key_create(&key, 0);
|
||||
if( rc ){
|
||||
sqlite3OsLeaveMutex();
|
||||
return 0;
|
||||
}
|
||||
keyInit = 1;
|
||||
}
|
||||
sqlite3OsLeaveMutex();
|
||||
}
|
||||
|
||||
pTsd = pthread_getspecific(key);
|
||||
if( allocateFlag>0 ){
|
||||
if( pTsd==0 ){
|
||||
if( !sqlite3TestMallocFail() ){
|
||||
pTsd = sqlite3OsMalloc(sizeof(zeroData));
|
||||
}
|
||||
#ifdef SQLITE_MEMDEBUG
|
||||
sqlite3_isFail = 0;
|
||||
#endif
|
||||
if( pTsd ){
|
||||
*pTsd = zeroData;
|
||||
pthread_setspecific(key, pTsd);
|
||||
TSD_COUNTER(+1);
|
||||
}
|
||||
}
|
||||
}else if( pTsd!=0 && allocateFlag<0
|
||||
&& memcmp(pTsd, &zeroData, sizeof(ThreadData))==0 ){
|
||||
sqlite3OsFree(pTsd);
|
||||
pthread_setspecific(key, 0);
|
||||
TSD_COUNTER(-1);
|
||||
pTsd = 0;
|
||||
}
|
||||
return pTsd;
|
||||
#else
|
||||
static ThreadData *pTsd = 0;
|
||||
if( allocateFlag>0 ){
|
||||
if( pTsd==0 ){
|
||||
#if 0
|
||||
if( !sqlite3TestMallocFail() ){
|
||||
pTsd = sqlite3OsMalloc( sizeof(zeroData) );
|
||||
}
|
||||
#ifdef SQLITE_MEMDEBUG
|
||||
sqlite3_isFail = 0;
|
||||
#endif
|
||||
#endif
|
||||
if( pTsd ){
|
||||
*pTsd = zeroData;
|
||||
TSD_COUNTER(+1);
|
||||
}
|
||||
}
|
||||
}else if( pTsd!=0 && allocateFlag<0
|
||||
&& memcmp(pTsd, &zeroData, sizeof(ThreadData))==0 ){
|
||||
sqlite3OsFree(pTsd);
|
||||
TSD_COUNTER(-1);
|
||||
pTsd = 0;
|
||||
}
|
||||
return pTsd;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
** The following variable, if set to a non-zero value, becomes the result
|
||||
** returned from sqlite3OsCurrentTime(). This is used for testing.
|
||||
@@ -2952,5 +2846,5 @@ int sqlite3UnixCurrentTime(double *prNow){
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif /* OS_UNIX */
|
||||
|
||||
Reference in New Issue
Block a user