This source file includes following definitions.
- sqlite3_wsd_init
- sqlite3_wsd_find
#if defined(SQLITE_OMIT_WSD) && defined(SQLITE_TEST)
#include "sqliteInt.h"
#define PLS_HASHSIZE 43
typedef struct ProcessLocalStorage ProcessLocalStorage;
typedef struct ProcessLocalVar ProcessLocalVar;
struct ProcessLocalStorage {
ProcessLocalVar *aData[PLS_HASHSIZE];
int nFree;
u8 *pFree;
};
struct ProcessLocalVar {
void *pKey;
ProcessLocalVar *pNext;
};
static ProcessLocalStorage *pGlobal = 0;
int sqlite3_wsd_init(int N, int J){
if( !pGlobal ){
int nMalloc = N + sizeof(ProcessLocalStorage) + J*sizeof(ProcessLocalVar);
pGlobal = (ProcessLocalStorage *)malloc(nMalloc);
if( pGlobal ){
memset(pGlobal, 0, sizeof(ProcessLocalStorage));
pGlobal->nFree = nMalloc - sizeof(ProcessLocalStorage);
pGlobal->pFree = (u8 *)&pGlobal[1];
}
}
return pGlobal ? SQLITE_OK : SQLITE_NOMEM;
}
void *sqlite3_wsd_find(void *K, int L){
int i;
int iHash = 0;
ProcessLocalVar *pVar;
for(i=0; i<sizeof(void*); i++){
iHash = (iHash<<3) + ((unsigned char *)&K)[i];
}
iHash = iHash%PLS_HASHSIZE;
for(pVar=pGlobal->aData[iHash]; pVar && pVar->pKey!=K; pVar=pVar->pNext);
if( !pVar ){
int nByte = ROUND8(sizeof(ProcessLocalVar) + L);
assert( pGlobal->nFree>=nByte );
pVar = (ProcessLocalVar *)pGlobal->pFree;
pVar->pKey = K;
pVar->pNext = pGlobal->aData[iHash];
pGlobal->aData[iHash] = pVar;
pGlobal->nFree -= nByte;
pGlobal->pFree += nByte;
memcpy(&pVar[1], K, L);
}
return (void *)&pVar[1];
}
#endif