Some changes to pobj.c to support operations for non-persistent (transient)

objects. Enhancement to test-list program to work with transient objects
as well. Minor fix to header file (typo).
This commit is contained in:
Gilad Arnold 2004-12-16 23:04:21 +00:00
parent 91eb96a113
commit 58bed5beca
3 changed files with 72 additions and 59 deletions

View file

@ -98,7 +98,7 @@ int pobj_set_ref (void *, void *, void *);
int pobj_update_range (void *, void *, size_t);
#define POBJ_UPDATE_FLD(obj,fld) \
pobj_update_range((obj), &((obj)->fld), sizeof((obj)->fld))
#define pobj_UPDATE(obj) pobj_update_range ((obj), NULL, 0)
#define POBJ_UPDATE(obj) pobj_update_range ((obj), NULL, 0)
int pobj_update_recursive (void *);
int pobj_static_set_ref (void *, void *);

View file

@ -211,7 +211,7 @@ pobj_persistify (void *obj)
size_t pobj_size;
if (! g_is_init)
return;
return -1;
if (p->rep_index >= 0)
return 0; /* already persistent. */
@ -669,15 +669,9 @@ pobj_ref_flag_update (void *obj, void **fld, int set)
int bit;
unsigned long *flags_ptr;
unsigned long flags, mask;
int xid;
int xid = -1;
int ret;
if (p->rep_index < 0) {
debug ("error: object is non-persistent");
return -1;
}
pobj_slot = POBJ2REPSLOT (p);
/* Bound check. */
/* TODO: is this worthwhile? */
if ((char *) obj > (char *) fld
@ -691,11 +685,12 @@ pobj_ref_flag_update (void *obj, void **fld, int set)
return -1;
}
if ((xid = pobj_start ()) < 0) {
/* Open transaction context (persistent objects only). */
if (p->rep_index >= 0 && (xid = pobj_start ()) < 0) {
debug ("error: begin transaction failed, aborted");
return -1;
}
/* Update reference flags to allow reference adjustment during recovery. */
/* TODO: do we want to protect manipulation of object meta-data? Basically,
* it should be protected, although changes are monotonic, but that will
@ -720,11 +715,15 @@ pobj_ref_flag_update (void *obj, void **fld, int set)
*flags_ptr = flags & ~mask;
}
/* Update corresponding record. */
/* TODO: switch to set_range update. */
Tset (xid, pobj_slot->rid, p);
/* Update corresponding record (persistent objects only). */
if (p->rep_index >= 0) {
pobj_slot = POBJ2REPSLOT (p);
/* TODO: switch to set_range update. */
Tset (xid, pobj_slot->rid, p);
pobj_end ();
pobj_end ();
}
return ret;
}
@ -751,21 +750,16 @@ pobj_ref_typify (void *obj, int *reflist)
int flags_offset;
int bit;
unsigned long *flags_ptr;
int xid;
int xid = -1;
int count;
if (p->rep_index < 0) {
debug ("error: object is non-persistent");
return -1;
}
pobj_slot = POBJ2REPSLOT (p);
if (! reflist) {
debug ("error: null reference list provided, aborted");
return -1;
}
if ((xid = pobj_start ()) < 0) {
/* Open transaction context (persistent objects only). */
if (p->rep_index >= 0 && (xid = pobj_start ()) < 0) {
debug ("error: begin transaction failed, aborted");
return -1;
}
@ -803,11 +797,15 @@ pobj_ref_typify (void *obj, int *reflist)
debug ("...done (%d total)", count);
/* Update corresponding record. */
/* TODO: switch to set_range update. */
Tset (xid, pobj_slot->rid, p);
/* Update corresponding record (persistent objects only). */
if (p->rep_index >= 0) {
pobj_slot = POBJ2REPSLOT (p);
pobj_end ();
/* TODO: switch to set_range update. */
Tset (xid, pobj_slot->rid, p);
pobj_end ();
}
return 0;
}
@ -822,13 +820,7 @@ pobj_memcpy_memset_typed (void *obj, void *fld, void *data, int c, size_t len,
#ifdef HAVE_IMPLICIT_TYPES
int is_changed = 0;
#endif /* HAVE_IMPLICIT_TYPES */
int xid;
if (p->rep_index < 0) {
debug ("error: object is non-persistent");
return -1;
}
pobj_slot = POBJ2REPSLOT (p);
int xid = -1;
/* Safety check. */
/* TODO: is this worthwhile? */
@ -839,6 +831,12 @@ pobj_memcpy_memset_typed (void *obj, void *fld, void *data, int c, size_t len,
return -1;
}
/* Open transaction context (persistent objects only). */
if (p->rep_index >= 0 && (xid = pobj_start ()) < 0) {
debug ("error: begin transaction failed, aborted");
return -1;
}
#ifdef HAVE_IMPLICIT_TYPES
if (is_typed) {
switch (pobj_ref_type_enforce (obj, fld, len, is_ref)) {
@ -857,22 +855,21 @@ pobj_memcpy_memset_typed (void *obj, void *fld, void *data, int c, size_t len,
}
#endif /* HAVE_IMPLICIT_TYPES */
if ((xid = pobj_start ()) < 0) {
debug ("error: begin transaction failed, aborted");
return -1;
}
/* Update memory object field. */
if (is_copy)
memcpy (fld, data, len);
else
memset (fld, c, len);
/* Update corresponding record. */
/* TODO: switch to set_range update; not the is_changed field! */
Tset (xid, pobj_slot->rid, p);
/* Update corresponding record (persistent objects only). */
if (p->rep_index >= 0) {
pobj_slot = POBJ2REPSLOT (p);
pobj_end ();
/* TODO: switch to set_range update; note the is_changed field! */
Tset (xid, pobj_slot->rid, p);
pobj_end ();
}
return 0;
}
@ -932,10 +929,9 @@ pobj_update_range (void *obj, void *fld, size_t len)
struct pobj_rep_list_item *pobj_slot;
int xid;
if (p->rep_index < 0) {
debug ("error: object is non-persistent");
return -1;
}
if (p->rep_index < 0)
return 0; /* transient mode. */
pobj_slot = POBJ2REPSLOT (p);
/* Safety check (only if len is non-zero). */

View file

@ -3,12 +3,18 @@
#include <pobj/pobj.h>
struct data {
int val;
};
struct item {
int val;
struct data *data;
struct item *next;
int dummy[45];
};
int item_ref_fields[] = {
member_offset(struct item, data),
member_offset(struct item, next),
-1
};
@ -17,6 +23,7 @@ int
main (int argc, char **argv)
{
static struct item *list = NULL;
struct data *data;
struct item *tmp, *next;
int i;
@ -27,29 +34,38 @@ main (int argc, char **argv)
next = NULL;
for (i = 0; i < 15000; i++) {
pobj_start ();
tmp = (struct item *) pobj_malloc (sizeof (struct item));
if (! tmp) {
data = (struct data *) pobj_malloc_transient (sizeof (struct data));
if (! (tmp && data)) {
printf ("allocation error\n");
abort ();
}
/* pobj_ref_typify (tmp, item_ref_fields); */
pobj_ref_typify (tmp, item_ref_fields);
#if 0
tmp->val = i;
tmp->next = next;
#endif
pobj_static_set_ref (&list, tmp);
POBJ_SET_INT (tmp, val, i);
/* Intended crash code... */
data->val = -i;
tmp->val = i;
tmp->data = data;
tmp->next = next;
#if 0
POBJ_SET_INT (tmp, val, i);
/* Intended crash code... */
if (i == 7)
abort ();
#endif
POBJ_SET_REF (tmp, next, next);
#endif
POBJ_UPDATE (tmp);
pobj_end ();
/* pobj_update (tmp); */
next = tmp;
}
/* pobj_update_recursive (tmp); */
@ -73,8 +89,9 @@ main (int argc, char **argv)
/* Print list. */
printf ("printing list...\n");
for (tmp = list; tmp; tmp = tmp->next)
printf ("%p: val=%d next=%p\n",
(void *) tmp, tmp->val, (void *) tmp->next);
printf ("%p: val=%d next=%p data=%p data->val=%d\n",
(void *) tmp, tmp->val, (void *) tmp->next,
(void *) tmp->data, (tmp->data ? tmp->data->val : 0));
printf ("...done\n");
pobj_shutdown ();