From 91f2c7c3828409c4ee03a2ee616260ae8d2b6956 Mon Sep 17 00:00:00 2001 From: Gilad Arnold Date: Thu, 3 Feb 2005 21:05:48 +0000 Subject: [PATCH] - moved pobj header internals back into the .c file (sorry Amir) - added pobj_is_persistent() call to replace the formerly used macro - minor rearragement of common contants/macros - minor fix to makefile --- pobj/pobj.h | 20 +------------------- src/pobj/Makefile.am | 2 +- src/pobj/common.h | 6 ++++-- src/pobj/hash.c | 1 - src/pobj/pobj.c | 19 +++++++++++++++++-- 5 files changed, 23 insertions(+), 25 deletions(-) diff --git a/pobj/pobj.h b/pobj/pobj.h index 120f6e7..5bcf532 100644 --- a/pobj/pobj.h +++ b/pobj/pobj.h @@ -5,25 +5,6 @@ #define member_offset(s,x) ((int)&(((s *)NULL)->x)) -/* Note: the alignment and pobj header info was placed here in order - * to allow fast IS_PERSISTENT check. */ - -/* Architecture specific word size and alignment. */ -#define WORDSIZE sizeof(int) -#define WORDBITS (WORDSIZE * 8) -#define ALIGN(s) ((size_t) (((s) + (WORDSIZE - 1)) / WORDSIZE) * WORDSIZE) - -/* Persistent object control block (header). */ -struct pobj { - size_t size; - int type_index; - int rep_index; -}; -#define POBJ_HEADER_SIZE sizeof(struct pobj) -#define IS_PERSISTENT(p) \ - (((struct pobj *)(((char *) p) - ALIGN(POBJ_HEADER_SIZE)))->rep_index >= 0) - - struct pobj_memfunc { void *(*malloc) (size_t); void *(*calloc) (size_t, size_t); @@ -39,6 +20,7 @@ int pobj_end (void); /* Persistency control. */ int pobj_persistify (void *); int pobj_unpersistify (void *); +int pobj_is_persistent (void *); /* Memory management calls. */ void *pobj_malloc (size_t); diff --git a/src/pobj/Makefile.am b/src/pobj/Makefile.am index 5947d81..719b168 100644 --- a/src/pobj/Makefile.am +++ b/src/pobj/Makefile.am @@ -1,3 +1,3 @@ lib_LIBRARIES=libpobj.a -libpobj_a_SOURCES=xmem.c hash.c pobj.c +libpobj_a_SOURCES=xmem.c hash.c queue.c pobj.c AM_CFLAGS= -g -Wall # -pedantic -std=gnu99 diff --git a/src/pobj/common.h b/src/pobj/common.h index 425281f..70a2e3a 100644 --- a/src/pobj/common.h +++ b/src/pobj/common.h @@ -1,8 +1,10 @@ #ifndef __COMMON_H #define __COMMON_H -#define member_sizeof(s,x) (sizeof(((s *)NULL)->x)) -#define member_offset(s,x) ((int)&(((s *)NULL)->x)) +/* Architecture specific word size and alignment. */ +#define WORDSIZE sizeof(int) +#define WORDBITS (WORDSIZE * 8) +#define ALIGN(s) ((size_t) (((s) + (WORDSIZE - 1)) / WORDSIZE) * WORDSIZE) #endif /* __COMMON_H */ diff --git a/src/pobj/hash.c b/src/pobj/hash.c index c74b821..edb84fb 100644 --- a/src/pobj/hash.c +++ b/src/pobj/hash.c @@ -1,5 +1,4 @@ #include -#include "hash.h" #include "debug.h" #include "xmem.h" diff --git a/src/pobj/pobj.c b/src/pobj/pobj.c index 8590534..7a40ac4 100644 --- a/src/pobj/pobj.c +++ b/src/pobj/pobj.c @@ -3,6 +3,7 @@ #include #include #include +#include "common.h" #include "hash.h" #include "debug.h" #include "xmem.h" @@ -34,8 +35,14 @@ #define TMPBUF_GROW_FACTOR 2 -/* Note: persistent object header has been moved to pobj.h in order to - * allow fast IS_PERSISTENT check. */ +/* Persistent object control block (header). */ +struct pobj { + size_t size; + int type_index; + int repo_index; +}; + +#define POBJ_HEADER_SIZE sizeof(struct pobj) #define POBJ_NREFS(s) ((s) / WORDSIZE) #define POBJ_REFFLAGS_OFFSET(s) (ALIGN(POBJ_HEADER_SIZE) + ALIGN(s)) #define POBJ_REFFLAGS_SIZE(s) ((size_t) ALIGN((POBJ_NREFS(s) + 7) / 8)) @@ -426,6 +433,14 @@ pobj_unpersistify (void *obj) return 0; } +int +pobj_is_persistent (void *obj) +{ + struct pobj *p = OBJ2POBJ (obj); + return (p->repo_index >= 0); +} + + static void * pobj_allocate (size_t size, void *(*alloc) (size_t), void (*dealloc) (void *), int persist, int zero)