047626fa0d312302138f8847d8c502dc316b0745
[IRC.git] / Robust / src / Runtime / DSTM / interface / dstm.h
1 #ifndef _DSTM_H_
2 #define _DSTM_H_
3
4 //Coordinator Messages
5 #define READ_REQUEST            1
6 #define READ_MULT_REQUEST       2
7 #define MOVE_REQUEST            3
8 #define MOVE_MULT_REQUEST       4
9 #define TRANS_REQUEST           5
10 #define TRANS_ABORT             6
11 #define TRANS_COMMIT            7
12 #define TRANS_ABORT_BUT_RETRY_COMMIT    8
13 #define TRANS_ABORT_BUT_RETRY_COMMIT_WITH_RELOCATING    9
14
15 //Participant Messages
16 #define OBJECT_FOUND            10
17 #define OBJECT_NOT_FOUND        11
18 #define OBJECTS_FOUND           12
19 #define OBJECTS_NOT_FOUND       13
20 #define TRANS_AGREE             14
21 #define TRANS_DISAGREE          15
22 #define TRANS_AGREE_BUT_MISSING_OBJECTS 16
23 #define TRANS_SOFT_ABORT        17
24 #define TRANS_SUCESSFUL         18
25
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <pthread.h>
30 #include "clookup.h"
31
32 #define DEFAULT_OBJ_STORE_SIZE 1048510 //1MB
33 #define TID_LEN 20
34 //bit designations for status field of objheader
35 #define DIRTY 0x01
36 #define NEW   0x02
37 #define LOCK  0x04
38
39 typedef struct objheader {
40         unsigned int oid;
41         unsigned short type;
42         unsigned short version;
43         unsigned short rcount;
44         char status;
45 } objheader_t;
46
47 typedef struct objstr {
48         unsigned int size; //this many bytes are allocated after this header
49         void *top;
50         struct objstr *next;
51 } objstr_t;
52
53 typedef struct transrecord {
54         objstr_t *cache;
55         chashtable_t *lookupTable;
56 } transrecord_t;
57
58 typedef struct pile {
59         unsigned int mid;
60         unsigned int oid;
61         struct pile *next;
62 }pile_t;
63
64 // Structure that keeps track of responses from the participants
65 typedef struct thread_response {
66         char rcv_status;
67 }thread_response_t;
68
69 // Structure that holds  fixed data sizes to be sent along with TRANS_REQUEST
70 typedef struct fixed_data {
71         char control;
72         char trans_id[TID_LEN]; 
73         int mcount;             // Machine count
74         short numread;          // Number of objects read
75         short nummod;           // Number of objects modified
76         int sum_bytes;  // Total bytes modified
77 }fixed_data_t;
78
79 // Structure that holds  variable data sizes per machine participant
80 typedef struct trans_req_data {
81         fixed_data_t f;
82         unsigned int *listmid;
83         char *objread;
84         unsigned int *oidmod;
85 }trans_req_data_t;
86
87 //structure for passing multiple arguments to thread
88 typedef struct thread_data_array {
89         int thread_id;
90         int mid;    
91         int pilecount;
92         trans_req_data_t *buffer;
93         thread_response_t *recvmsg;//shared datastructure to keep track of the control message receiv
94         pthread_cond_t *threshold; //threshhold for waking up a thread
95         pthread_mutex_t *lock;    //lock the count variable
96         int *count;             //count variable
97         transrecord_t *rec;     // To send modified objects
98 }thread_data_array_t;
99
100 /* Initialize main object store and lookup tables, start server thread. */
101 int dstmInit(void);
102
103 /* Prototypes for object header */
104 unsigned int getNewOID(void);
105 unsigned int objSize(objheader_t *object);
106 /* end object header */
107
108 /* Prototypes for object store */
109 objstr_t *objstrCreate(unsigned int size); //size in bytes
110 void objstrDelete(objstr_t *store); //traverse and free entire list
111 void *objstrAlloc(objstr_t *store, unsigned int size); //size in bytes
112 /* end object store */
113
114 /* Prototypes for server portion */
115 void *dstmListen();
116 void *dstmAccept(void *);
117 /* end server portion */
118
119 /* Prototypes for transactions */
120 transrecord_t *transStart();
121 objheader_t *transRead(transrecord_t *record, unsigned int oid);
122 objheader_t *transCreateObj(transrecord_t *record, unsigned short type); //returns oid
123 void *transRequest(void *);     //the C routine that the thread will execute when TRANS_REQUEST begins
124 int transCommit(transrecord_t *record); //return 0 if successful
125 int decideResponse(thread_data_array_t *tdata, char *buffer, int sd);// Coordinator decides what response to send to the participant
126 /* end transactions */
127
128 void *getRemoteObj(transrecord_t *, unsigned int, unsigned int);
129
130 #endif