X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=apc_sma.c;h=b8f61aa07089a1d0a8ce58afc1b0f29113353250;hb=10aea07a14325aa0bfb5fe75ddcf19432c6e2c64;hp=20b8e4504279ab7141722c5d802d9f8c0457a7e0;hpb=27531cfcd6e8fb46402c6771ef4c2d97233917af;p=php5-apc.git diff --git a/apc_sma.c b/apc_sma.c index 20b8e45..b8f61aa 100644 --- a/apc_sma.c +++ b/apc_sma.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | APC | +----------------------------------------------------------------------+ - | Copyright (c) 2006 The PHP Group | + | Copyright (c) 2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -26,19 +26,24 @@ */ -/* $Id: apc_sma.c,v 1.69 2007/12/26 21:35:39 gopalv Exp $ */ +/* $Id: apc_sma.c,v 1.69.2.4 2008/05/11 18:57:00 rasmus Exp $ */ #include "apc_sma.h" #include "apc.h" #include "apc_globals.h" #include "apc_lock.h" #include "apc_shm.h" +#include "apc_cache.h" #include #if APC_MMAP void *apc_mmap(char *file_mask, size_t size); void apc_unmap(void* shmaddr, size_t size); #endif +#ifdef HAVE_VALGRIND_MEMCHECK_H +#include +#endif + /* {{{ locking macros */ #define LOCK(c) { HANDLE_BLOCK_INTERRUPTIONS(); apc_lck_lock(c); } #define RDLOCK(c) { HANDLE_BLOCK_INTERRUPTIONS(); apc_lck_rdlock(c); } @@ -110,19 +115,12 @@ struct block_t { #endif -#ifdef max -#undef max -#endif -#define max(a, b) ((a) > (b) ? (a) : (b)) - -/* {{{ ALIGNWORD: pad up x, aligned to the system's word boundary */ -typedef union { void* p; int i; long l; double d; void (*f)(); } apc_word_t; -#define ALIGNWORD(x) (sizeof(apc_word_t) * (1 + (((x)-1)/sizeof(apc_word_t)))) +/* {{{ MINBLOCKSIZE */ #define MINBLOCKSIZE (ALIGNWORD(1) + ALIGNWORD(sizeof(block_t))) /* }}} */ /* {{{ sma_allocate: tries to allocate size bytes in a segment */ -static int sma_allocate(void* shmaddr, size_t size) +static size_t sma_allocate(void* shmaddr, size_t size) { header_t* header; /* header of shared memory segment */ block_t* prv; /* block prior to working block */ @@ -239,7 +237,7 @@ static int sma_allocate(void* shmaddr, size_t size) /* }}} */ /* {{{ sma_deallocate: deallocates the block at the given offset */ -static int sma_deallocate(void* shmaddr, int offset) +static size_t sma_deallocate(void* shmaddr, size_t offset) { header_t* header; /* header of shared memory segment */ block_t* cur; /* the new block to insert */ @@ -409,7 +407,7 @@ void apc_sma_cleanup() /* {{{ apc_sma_malloc */ void* apc_sma_malloc(size_t n) { - int off; + size_t off; int i; TSRMLS_FETCH(); @@ -421,6 +419,9 @@ void* apc_sma_malloc(size_t n) void* p = (void *)(((char *)(sma_shmaddrs[sma_lastseg])) + off); if (APCG(mem_size_ptr) != NULL) { *(APCG(mem_size_ptr)) += n; } UNLOCK(((header_t*)sma_shmaddrs[sma_lastseg])->sma_lock); +#ifdef VALGRIND_MALLOCLIKE_BLOCK + VALGRIND_MALLOCLIKE_BLOCK(p, n, 0, 0); +#endif return p; } UNLOCK(((header_t*)sma_shmaddrs[sma_lastseg])->sma_lock); @@ -436,6 +437,9 @@ void* apc_sma_malloc(size_t n) if (APCG(mem_size_ptr) != NULL) { *(APCG(mem_size_ptr)) += n; } UNLOCK(((header_t*)sma_shmaddrs[i])->sma_lock); sma_lastseg = i; +#ifdef VALGRIND_MALLOCLIKE_BLOCK + VALGRIND_MALLOCLIKE_BLOCK(p, n, 0, 0); +#endif return p; } UNLOCK(((header_t*)sma_shmaddrs[i])->sma_lock); @@ -490,6 +494,9 @@ void apc_sma_free(void* p) d_size = sma_deallocate(sma_shmaddrs[i], offset); if (APCG(mem_size_ptr) != NULL) { *(APCG(mem_size_ptr)) -= d_size; } UNLOCK(((header_t*)sma_shmaddrs[i])->sma_lock); +#ifdef VALGRIND_FREELIKE_BLOCK + VALGRIND_FREELIKE_BLOCK(p, 0); +#endif return; } UNLOCK(((header_t*)sma_shmaddrs[i])->sma_lock);