- 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
This commit is contained in:
Gilad Arnold 2005-02-03 21:05:48 +00:00
parent 1fd827a59e
commit 91f2c7c382
5 changed files with 23 additions and 25 deletions

View file

@ -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);

View file

@ -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

View file

@ -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 */

View file

@ -1,5 +1,4 @@
#include <string.h>
#include "hash.h"
#include "debug.h"
#include "xmem.h"

View file

@ -3,6 +3,7 @@
#include <pthread.h>
#include <lladd/transactional.h>
#include <pobj/pobj.h>
#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)