60d21cad008edff3ae28edfb8677933dbb73febc
[IRC.git] / Robust / src / Runtime / STM / tm.h
1 #ifndef _TM_H_
2 #define _TM_H_
3
4 /* ==================
5  * Control Messages
6  * ==================
7  */
8 #define TRANS_AGREE         10
9 #define TRANS_DISAGREE      11
10 #define TRANS_SOFT_ABORT    12
11 #define TRANS_ABORT         13
12 #define TRANS_COMMIT        14
13 #define READ_OBJ            15
14 #define THREAD_NOTIFY       16
15 #define THREAD_RESPONSE     17
16
17
18 /* ========================
19  * Library header files
20  * ========================
21  */
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <pthread.h>
26 #include <sys/time.h>
27 #include <errno.h>
28 #include "threadnotify.h"
29 #include "clookup.h"
30 #include "dsmlock.h"
31
32 /* ==================================
33  * Bit designation for status field
34  * of object header 
35  * ==================================
36  */
37 #define DIRTY 0x01
38 #define NEW   0x02
39 #define LOCK  0x04
40
41 /* ================================
42  * Constants
43  * ================================
44  */
45 #define DEFAULT_OBJ_STORE_SIZE 1048510 //1MB
46 #define OSUSED(x) (((unsigned int)(x)->top)-((unsigned int) (x+1)))
47 #define OSFREE(x) ((x)->size-OSUSED(x))
48 #define TRANSREAD(x,y) { \
49   unsigned int inputvalue;\
50 if ((inputvalue=(unsigned int)y)==0) x=NULL;\
51 else { \
52 chashlistnode_t * cnodetmp=&c_table[(inputvalue&c_mask)>>1];    \
53 do { \
54   if (cnodetmp->key==inputvalue) {x=(void *)&((objheader_t*)cnodetmp->val)[1];break;} \
55 cnodetmp=cnodetmp->next;\
56  if (cnodetmp==NULL) {x=(void *)transRead(inputvalue); asm volatile("":"=m"(c_table),"=m"(c_mask));break;} \
57 } while(1);\
58 }}
59
60 /* =================================
61  * Data structures 
62  * =================================
63  */
64 typedef struct objstr {
65   unsigned int size;       //this many bytes are allocated after this header
66   void *top;
67   struct objstr *next;
68   struct objstr *prev;
69 } objstr_t;
70
71 typedef struct newObjCreated {
72   unsigned int numcreated;
73   unsigned int *oidcreated;
74 } newObjCreated_t;
75
76 #ifdef COMPILER
77 typedef struct objheader {
78   threadlist_t *notifylist;
79   unsigned short version;
80   unsigned short rcount;
81 } objheader_t;
82
83 #define OID(x) \
84   (*((unsigned int *)&((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->___nextobject___))
85
86 #define COMPOID(x) \
87   ((void*)((((void *) x )!=NULL) ? (*((unsigned int *)&((struct ___Object___ *) x)->___nextobject___)) : 0))
88
89 #define STATUS(x) \
90   *((unsigned int *) &(((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->___localcopy___))
91
92 #define STATUSPTR(x) \
93   ((unsigned int *) &(((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->___localcopy___))
94
95 #define TYPE(x) \
96   ((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->type
97
98 #define GETSIZE(size, x) { \
99     int type=TYPE(x); \
100     if (type<NUMCLASSES) { \
101       size=classsize[type]; \
102     } else { \
103       size=classsize[type]*((struct ArrayObject *)&((objheader_t *)x)[1])->___length___+sizeof(struct ArrayObject); \
104     } \
105 }
106
107 #else
108 #define OID(x) x->oid
109 #define TYPE(x) x->type
110 #define STATUS(x) x->status
111 #define STATUSPTR(x) &x->status
112 #define GETSIZE(size, x) size=classsize[TYPE(x)]
113 #endif
114
115 /* ================================
116  * Functions used
117  * ================================
118  */
119 int stmStartup();
120 objstr_t *objstrCreate(unsigned int size);
121 void transStart();
122 objheader_t *transCreateObj(unsigned int size);
123 unsigned int getNewOID(void);
124 void *objstrAlloc(objstr_t **osptr, unsigned int size);
125 __attribute__((pure)) objheader_t *transRead(unsigned int oid);
126 int transCommit();
127 char traverseCache(char *treplyretry);
128 char decideResponse(objheader_t *, unsigned int *, int *, unsigned int *, int *, unsigned int*, int *, 
129     int *, int *, int *, int*, int*);
130 int transAbortProcess(unsigned int *, int *, unsigned int *, int *);
131 int transCommmitProcess(unsigned int *, int *, unsigned int *, int *, unsigned int *, int *);
132 void randomdelay();
133
134 #endif