OLD | NEW |
1 /* | 1 /* |
2 ** 2007 October 14 | 2 ** 2007 October 14 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 /* If none of the above worked, then we fail. */ | 426 /* If none of the above worked, then we fail. */ |
427 return 0; | 427 return 0; |
428 } | 428 } |
429 | 429 |
430 /* | 430 /* |
431 ** Free an outstanding memory allocation. | 431 ** Free an outstanding memory allocation. |
432 ** | 432 ** |
433 ** This function assumes that the necessary mutexes, if any, are | 433 ** This function assumes that the necessary mutexes, if any, are |
434 ** already held by the caller. Hence "Unsafe". | 434 ** already held by the caller. Hence "Unsafe". |
435 */ | 435 */ |
436 void memsys3FreeUnsafe(void *pOld){ | 436 static void memsys3FreeUnsafe(void *pOld){ |
437 Mem3Block *p = (Mem3Block*)pOld; | 437 Mem3Block *p = (Mem3Block*)pOld; |
438 int i; | 438 int i; |
439 u32 size, x; | 439 u32 size, x; |
440 assert( sqlite3_mutex_held(mem3.mutex) ); | 440 assert( sqlite3_mutex_held(mem3.mutex) ); |
441 assert( p>mem3.aPool && p<&mem3.aPool[mem3.nPool] ); | 441 assert( p>mem3.aPool && p<&mem3.aPool[mem3.nPool] ); |
442 i = p - mem3.aPool; | 442 i = p - mem3.aPool; |
443 assert( (mem3.aPool[i-1].u.hdr.size4x&1)==1 ); | 443 assert( (mem3.aPool[i-1].u.hdr.size4x&1)==1 ); |
444 size = mem3.aPool[i-1].u.hdr.size4x/4; | 444 size = mem3.aPool[i-1].u.hdr.size4x/4; |
445 assert( i+size<=mem3.nPool+1 ); | 445 assert( i+size<=mem3.nPool+1 ); |
446 mem3.aPool[i-1].u.hdr.size4x &= ~1; | 446 mem3.aPool[i-1].u.hdr.size4x &= ~1; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 assert( nBytes>0 ); /* malloc.c filters out 0 byte requests */ | 501 assert( nBytes>0 ); /* malloc.c filters out 0 byte requests */ |
502 memsys3Enter(); | 502 memsys3Enter(); |
503 p = memsys3MallocUnsafe(nBytes); | 503 p = memsys3MallocUnsafe(nBytes); |
504 memsys3Leave(); | 504 memsys3Leave(); |
505 return (void*)p; | 505 return (void*)p; |
506 } | 506 } |
507 | 507 |
508 /* | 508 /* |
509 ** Free memory. | 509 ** Free memory. |
510 */ | 510 */ |
511 void memsys3Free(void *pPrior){ | 511 static void memsys3Free(void *pPrior){ |
512 assert( pPrior ); | 512 assert( pPrior ); |
513 memsys3Enter(); | 513 memsys3Enter(); |
514 memsys3FreeUnsafe(pPrior); | 514 memsys3FreeUnsafe(pPrior); |
515 memsys3Leave(); | 515 memsys3Leave(); |
516 } | 516 } |
517 | 517 |
518 /* | 518 /* |
519 ** Change the size of an existing memory allocation | 519 ** Change the size of an existing memory allocation |
520 */ | 520 */ |
521 void *memsys3Realloc(void *pPrior, int nBytes){ | 521 static void *memsys3Realloc(void *pPrior, int nBytes){ |
522 int nOld; | 522 int nOld; |
523 void *p; | 523 void *p; |
524 if( pPrior==0 ){ | 524 if( pPrior==0 ){ |
525 return sqlite3_malloc(nBytes); | 525 return sqlite3_malloc(nBytes); |
526 } | 526 } |
527 if( nBytes<=0 ){ | 527 if( nBytes<=0 ){ |
528 sqlite3_free(pPrior); | 528 sqlite3_free(pPrior); |
529 return 0; | 529 return 0; |
530 } | 530 } |
531 nOld = memsys3Size(pPrior); | 531 nOld = memsys3Size(pPrior); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 memsys3Size, | 678 memsys3Size, |
679 memsys3Roundup, | 679 memsys3Roundup, |
680 memsys3Init, | 680 memsys3Init, |
681 memsys3Shutdown, | 681 memsys3Shutdown, |
682 0 | 682 0 |
683 }; | 683 }; |
684 return &mempoolMethods; | 684 return &mempoolMethods; |
685 } | 685 } |
686 | 686 |
687 #endif /* SQLITE_ENABLE_MEMSYS3 */ | 687 #endif /* SQLITE_ENABLE_MEMSYS3 */ |
OLD | NEW |