-C Very\sminor\soptimizations\sin\sthe\sunix\sVFS.
-D 2015-09-01T23:51:53.351
+C The\ssqlite3_memory_alarm()\sinterface\shas\sbeen\sdeprecated\sand\sundocumented\nfor\salmost\s8\syears\s(since\sversion\s3.5.3).\s\sChange\sit\sinto\sa\sno-op.
+D 2015-09-02T14:56:56.653
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in f85066ce844a28b671aaeeff320921cd0ce36239
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
F src/lempar.c 92bafa308607dd985ca389a788cd9e0a2b608712
F src/loadext.c dfcee8c7c032cd0fd55af3e0fc1fcfb01e426df2
F src/main.c e17fcffae4306a9b8334faf3bac80d7396850b54
-F src/malloc.c 7de3bb83deb27fb4a874d2905efe8e5f7c553b10
+F src/malloc.c 021012e28a81ffdabf4c30ec3df6ce1f6cc93f1d
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987
F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P adf9fefb00ae1dbb07a921c6796cb0a9505c6d19
-R 15ed1e546d27e5e6e36f3f7a000cba56
+P 6db3ff45bc15ece29cb2c7a736e5c6d005dde200
+R fb43199c7de8d8215fceefa0991f495e
U drh
-Z d46ac269d8c66ccb24de8ee93f61442e
+Z 048512fff9b9f8d1311c6e43a6f32096
*/
static SQLITE_WSD struct Mem0Global {
sqlite3_mutex *mutex; /* Mutex to serialize access */
-
- /*
- ** The alarm callback and its arguments. The mem0.mutex lock will
- ** be held while the callback is running. Recursive calls into
- ** the memory subsystem are allowed, but no new callbacks will be
- ** issued.
- */
- sqlite3_int64 alarmThreshold;
- void (*alarmCallback)(void*, sqlite3_int64,int);
- void *alarmArg;
+ sqlite3_int64 alarmThreshold; /* The soft heap limit */
/*
** Pointers to the end of sqlite3GlobalConfig.pScratch memory
** sqlite3_soft_heap_limit() setting.
*/
int nearlyFull;
-} mem0 = { 0, 0, 0, 0, 0, 0, 0, 0 };
+} mem0 = { 0, 0, 0, 0, 0, 0 };
#define mem0 GLOBAL(struct Mem0Global, mem0)
}
/*
-** This routine runs when the memory allocator sees that the
-** total memory allocation is about to exceed the soft heap
-** limit.
+** Return the amount of memory currently in use.
*/
-static void softHeapLimitEnforcer(
- void *NotUsed,
- sqlite3_int64 NotUsed2,
- int allocSize
-){
- UNUSED_PARAMETER2(NotUsed, NotUsed2);
- sqlite3_release_memory(allocSize);
+static sqlite3_int64 memInUse(void){
+ assert( sqlite3_mutex_held(mem0.mutex) );
+ return sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
}
/*
-** Change the alarm callback
+** Called when the soft heap limit is exceeded for an allocation
+** of nBytes.
*/
-static int sqlite3MemoryAlarm(
- void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
- void *pArg,
- sqlite3_int64 iThreshold
-){
- sqlite3_int64 nUsed;
- sqlite3_mutex_enter(mem0.mutex);
- mem0.alarmCallback = xCallback;
- mem0.alarmArg = pArg;
- mem0.alarmThreshold = iThreshold;
- nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
- mem0.nearlyFull = (iThreshold>0 && iThreshold<=nUsed);
+#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
+static void sqlite3HeapLimitExceeded(int nByte){
+ sqlite3_int64 excess = memInUse() + nByte - mem0.alarmThreshold;
sqlite3_mutex_leave(mem0.mutex);
- return SQLITE_OK;
+ sqlite3_release_memory((int)(excess & 0x7fffffff));
+ sqlite3_mutex_enter(mem0.mutex);
+}
+#else
+# define sqlite3HeapLimitExceeded(X) /* no-op */
+#endif
+
+/*
+** Check to see if increasing the total memory usage by nNew bytes
+** will exceed the soft heap limit.
+**
+** If the soft heap limit is exceeded, set the mem0.nearlyFull flag
+** and invoke sqlite3HeapLimitExceeded() to try to free up some
+** memory.
+*/
+static void sqlite3CheckSoftHeapLimit(int nNew){
+ assert( sqlite3_mutex_held(mem0.mutex) );
+ if( mem0.alarmThreshold>0 ){
+ if( mem0.alarmThreshold-nNew >= memInUse() ){
+ mem0.nearlyFull = 1;
+ sqlite3HeapLimitExceeded(nNew);
+ }else{
+ mem0.nearlyFull = 0;
+ }
+ }
}
#ifndef SQLITE_OMIT_DEPRECATED
/*
-** Deprecated external interface. Internal/core SQLite code
-** should call sqlite3MemoryAlarm.
+** Deprecated external interface. First deprecated 2007-11-05. Changed
+** into a no-op on 2015-09-02.
*/
int sqlite3_memory_alarm(
void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
void *pArg,
sqlite3_int64 iThreshold
){
- return sqlite3MemoryAlarm(xCallback, pArg, iThreshold);
+ return SQLITE_OK;
}
#endif
*/
sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 n){
sqlite3_int64 priorLimit;
- sqlite3_int64 excess;
#ifndef SQLITE_OMIT_AUTOINIT
int rc = sqlite3_initialize();
if( rc ) return -1;
#endif
sqlite3_mutex_enter(mem0.mutex);
priorLimit = mem0.alarmThreshold;
- sqlite3_mutex_leave(mem0.mutex);
- if( n<0 ) return priorLimit;
if( n>0 ){
- sqlite3MemoryAlarm(softHeapLimitEnforcer, 0, n);
- }else{
- sqlite3MemoryAlarm(0, 0, 0);
+ mem0.alarmThreshold = n;
+ sqlite3CheckSoftHeapLimit(0);
+ }else if( n==0 ){
+ mem0.alarmThreshold = 0;
+ mem0.nearlyFull = 0;
}
- excess = sqlite3_memory_used() - n;
- if( excess>0 ) sqlite3_release_memory((int)(excess & 0x7fffffff));
+ sqlite3_mutex_leave(mem0.mutex);
return priorLimit;
}
void sqlite3_soft_heap_limit(int n){
return mx;
}
-/*
-** Trigger the alarm
-*/
-static void sqlite3MallocAlarm(int nByte){
- void (*xCallback)(void*,sqlite3_int64,int);
- sqlite3_int64 nowUsed;
- void *pArg;
- if( mem0.alarmCallback==0 ) return;
- xCallback = mem0.alarmCallback;
- nowUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
- pArg = mem0.alarmArg;
- mem0.alarmCallback = 0;
- sqlite3_mutex_leave(mem0.mutex);
- xCallback(pArg, nowUsed, nByte);
- sqlite3_mutex_enter(mem0.mutex);
- mem0.alarmCallback = xCallback;
- mem0.alarmArg = pArg;
-}
-
/*
** Do a memory allocation with statistics and alarms. Assume the
** lock is already held.
assert( sqlite3_mutex_held(mem0.mutex) );
nFull = sqlite3GlobalConfig.m.xRoundup(n);
sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n);
- if( mem0.alarmCallback!=0 ){
- sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
- if( nUsed >= mem0.alarmThreshold - nFull ){
- mem0.nearlyFull = 1;
- sqlite3MallocAlarm(nFull);
- }else{
- mem0.nearlyFull = 0;
- }
- }
+ sqlite3CheckSoftHeapLimit(nFull);
p = sqlite3GlobalConfig.m.xMalloc(nFull);
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
- if( p==0 && mem0.alarmCallback ){
- sqlite3MallocAlarm(nFull);
+ if( p==0 && mem0.alarmThreshold ){
+ sqlite3HeapLimitExceeded(nFull);
p = sqlite3GlobalConfig.m.xMalloc(nFull);
}
#endif
sqlite3_mutex_enter(mem0.mutex);
sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, (int)nBytes);
nDiff = nNew - nOld;
- if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >=
- mem0.alarmThreshold-nDiff ){
- sqlite3MallocAlarm(nDiff);
- }
+ sqlite3CheckSoftHeapLimit(nDiff);
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
- if( pNew==0 && mem0.alarmCallback ){
- sqlite3MallocAlarm((int)nBytes);
+#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
+ if( pNew==0 && mem0.alarmThreshold ){
+ sqlite3HeapLimitExceeded((int)nBytes);
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
}
+#endif
if( pNew ){
nNew = sqlite3MallocSize(pNew);
sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nNew-nOld);