--- /dev/null
+#include "dstm.h"
+
+obj_store_t *obj_begin;
+obj_listnode_t *obj_lnode_begin;
+
+extern int classsize[];
+
+/* BEGIN - object store */
+
+void dstm_init(void) {
+ obj_begin = NULL;
+ obj_lnode_begin = NULL;
+ return;
+}
+
+void create_objstr(unsigned int size) {
+ obj_store_t *tmp, *ptr;
+ static int id = 0;
+
+ if ((tmp = (obj_store_t *) malloc(sizeof(obj_store_t))) < 0) {
+ printf("DSTM: Malloc error %s %d\n", __FILE__, __LINE__);
+ exit(-1);
+ }
+ if ((tmp->base = (char *) malloc(sizeof(char)*size)) < 0) {
+ printf("DSTM: Malloc error %s %d\n", __FILE__, __LINE__);
+ exit(-1);
+ }
+ tmp->size = size;
+ tmp->top = tmp->base;
+ tmp->id = id++;
+ if (obj_begin == NULL) { // First entry
+ obj_begin = tmp;
+ tmp->next = NULL;
+ } else { // Insert to the front of the linked list
+ tmp->next = obj_begin;
+ obj_begin = tmp;
+ }
+ return;
+}
+
+void delete_objstr(int id) {
+ //TODO Implement this along with garbage collector
+ return;
+}
+
+obj_store_t *get_objstr_begin(void) {
+ return obj_begin;
+}
+
+/* END object store */
+
+/* BEGIN object header */
+int get_newID(void) {
+ static int id = 0;
+
+ return ++id;
+}
+
+int insertObject(obj_header_t h) {
+ int left, req;
+
+ left = obj_begin->size - (obj_begin->top - obj_begin->base);
+ req = getObjSize(h) + sizeof(obj_header_t);
+ if (req < left) {
+ memcpy(obj_begin->top, &h, sizeof(obj_header_t));
+ obj_begin->top = obj_begin->top + sizeof(obj_header_t) + getObjSize(h);
+ } else {
+ return -1;
+ }
+ //TODO Update obj_addr_table
+ return 0;
+}
+
+int getObjSize(obj_header_t h) {
+ return classsize[h.type];
+}
+
+void createObject(unsigned short type) {
+ obj_header_t h;
+
+ h.oid = get_newID();
+ h.type = type;
+ h.version = 0;
+ h.rcount = 1;
+ h.status = CLEAN;
+ insert_object(h);
+}
+/* END object header */
+
+/* BEGIN obj_listnode */
+
+int IsEmpty(obj_listnode_t *node) {
+ return obj_lnode_begin == NULL;
+}
+
+void insert_lnode(obj_listnode_t *node) {
+ if(obj_lnode_begin == NULL) { // Enter "node" as the first node in linked list
+ obj_lnode_begin = node;
+ node->next = NULL;
+ } else { // Enter "node" to the beginning of the linked list
+ node->next = obj_lnode_begin;
+ obj_lnode_begin = node ;
+
+ }
+
+}
+
+int delete_lnode(obj_listnode_t *node, unsigned int oid) {
+ obj_listnode_t pre, curr;
+ if( obj_lnode_begin == NULL){
+ printf(" No nodes to delete ");
+ return -1;
+ }else {
+ //Traverse list
+ pre = curr = obj_lnode_begin;
+ while(node->next != NULL) {
+ pre = curr;
+ curr= curr->next;
+ if(oid == node->oid){
+ }
+ }
+}
+
+
+/* END obj_listnode */
+#ifndef _DSTM_H_
+#define _DSTM_H_
-typedef struct {
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+enum status {CLEAN, DIRTY};
+
+typedef struct obj_header {
unsigned int oid;
unsigned short type;
unsigned short version;
unsigned short rcount;
- unsigned short status;
-} obj_header;
+ char status;
+} obj_header_t;
-typedef struct obj_str{
- void *base;
+typedef struct obj_store {
+ unsigned int id;
+ char *base;
unsigned int size;
- void *top; //next available location
- struct obj_str *next;
-} obj_store;
+ char *top; //next available location
+ struct obj_store *next;
+} obj_store_t;
//use for hash tables, transaction records.
//to check oid, do object->oid
typedef struct obj_lnode{
- obj_header *object;
+ obj_header_t *object;
+ unsigned int oid;
struct obj_lnode *next;
-} obj_listnode;
+} obj_listnode_t;
-typedef struct {
- unsigned int size; //number of elements, not bytes
- obj_listnode *table; //this should point to an array of object lists, of the specified size
-} obj_addr_table;
+typedef struct obj_addr_table {
+ unsigned int size; //number of elements, not bytes
+ obj_listnode_t *table; //this should point to an array of object lists, of the specified size
+} obj_addr_table_t;
-typedef struct {
- obj_listnode *obj_list;
- obj_store *cache;
- obj_addr_table *lookupTable;
-} trans_record;
+typedef struct trans_record {
+ obj_listnode_t *obj_list;
+ obj_store_t *cache;
+ obj_addr_table_t *lookupTable;
+} trans_record_t;
typedef struct obj_location_lnode {
unsigned int oid;
unsigned int mid;
struct obj_location_lnode *next;
-} obj_location_listnode;
+} obj_location_listnode_t;
typedef struct {
unsigned int size; //number of elements, not bytes
- obj_location_listnode *table; //this should point to an array of object lists, of the specified size
+ obj_location_listnode_t *table; //this should point to an array of object lists, of the specified size
} obj_location_table;
-unsigned int objSize(obj_header *);
+/* Prototypes for object store */
+void dstm_init(void);
+void create_objstr(unsigned int);
+void delete_objstr(int);
+obj_store_t *get_objstr_begin(void);
+/* end object store */
+
+
+/* Prototypes for object header */
+int get_newID(void);
+int insertObject(obj_header_t h);
+int getObjSize(obj_header_t h);
+void createObject(unsigned short type);
+/* end object header */
+
+
+
+/*
+void * allocate_size(unsigned int);
+void initializeobj(unsigned int);
+unsigned int getobjSize(obj_header *);
int insertAddr(obj_addr_table *, obj_header *);
int removeAddr(obj_addr_table *, unsigned int);
obj_header *getAddr(obj_addr_table *, unsigned int);
int insertLocation(obj_location_table *, unsigned int, unsigned int);
int removeLocation(obj_location_table *, unsigned int);
unsigned int getLocation(obj_location_table *, unsigned int);
+*/
+#endif