*/
-/* $Id: apc_sma.c,v 1.69 2007/12/26 21:35:39 gopalv Exp $ */
+/* $Id: apc_sma.c,v 1.69.2.2 2008/03/28 20:17:47 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 <limits.h>
#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 <valgrind/memcheck.h>
+#endif
+
/* {{{ locking macros */
#define LOCK(c) { HANDLE_BLOCK_INTERRUPTIONS(); apc_lck_lock(c); }
#define RDLOCK(c) { HANDLE_BLOCK_INTERRUPTIONS(); apc_lck_rdlock(c); }
#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 */
/* }}} */
/* {{{ 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 */
/* {{{ apc_sma_malloc */
void* apc_sma_malloc(size_t n)
{
- int off;
+ size_t off;
int i;
+ size_t *orig_mem_size_ptr;
TSRMLS_FETCH();
assert(sma_initialized);
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);
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);
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);