a4648e0801113918ce81aa5ca1fcb3536c85cc34
[IRC.git] / Robust / src / Runtime / STM / array.h
1 #ifndef ARRAY_H
2 #define ARRAY_H
3
4 /* Array layout */
5 #define INDEXSHIFT 4   //must be at least 3 for doubles
6 //#define DBLINDEXSHIFT INDEXSHIFT-1   //must be at least 3 for doubles
7 #define INDEXLENGTH (1<<INDEXSHIFT)
8 #define LOWMASK (INDEXLENGTH-1) //mast off low order bits
9 #define HIGHMASK ~(LOWMASK) //mask off high order bits
10
11 #define STMNONE 0
12 #define STMCLEAN 1
13 #define STMDIRTY 2
14
15 #define MAXARRAYSIZE 2147483647
16
17 #define GETLOCKPTR(lock, array, byteindex) {                            \
18     lock=(unsigned int *)((char *)array-sizeof(objheader_t)-sizeof(int)*2*(byteindex)-2*sizeof(int)); \
19   }
20
21 #define GETLOCKVAL(lock, array, byteindex) {                            \
22     lock=*(unsigned int *)((char *)array-sizeof(objheader_t)-sizeof(int)*2*(byteindex)-2*sizeof(int)); \
23   }
24
25 #define GETVERSIONVAL(version, array, byteindex) {                      \
26     version=*(unsigned int *)((char *)array-sizeof(objheader_t)-sizeof(int)*2*(byteindex)-sizeof(int)); \
27   }
28
29 #define SETVERSION(array, byteindex, version) {                         \
30     *(unsigned int *)((char *)array-sizeof(objheader_t)-sizeof(int)*2*(byteindex)-sizeof(int))=version; \
31   }
32
33 #define GETVERSIONPTR(version, array, byteindex) {                      \
34     version=(unsigned int *)((char *)array-sizeof(objheader_t)-sizeof(int)*2*(byteindex)-sizeof(int)); \
35   }
36
37 #define STMGETARRAY(dst, array, index, type) {                          \
38     int byteindex=index*sizeof(type);                                   \
39     int * lengthoff=&array->___length___;                               \
40     if (array!=array->___objlocation___) {                              \
41       if(!(array->___objstatus___&NEW)) {                               \
42         int *status;                                                    \
43         GETLOCKPTR(status, array, byteindex>>INDEXSHIFT);               \
44         if ((*status)==STMNONE) {                                       \
45           arraycopy(array, byteindex);                                  \
46           *status=STMCLEAN;}                                            \
47       }                                                                 \
48     }                                                                   \
49     dst=((type *)(((char *) lengthoff)+sizeof(int)))[index];            \
50   }
51
52 #define STMSETARRAY(array, index, src, type) {                          \
53     int byteindex=index*sizeof(type);                                   \
54     int * lengthoff=&array->___length___;                               \
55     if (!(array->___objstatus___&NEW)) {                                \
56       int *status;                                                      \
57       GETLOCKPTR(status, array, byteindex>>INDEXSHIFT);                 \
58       if ((*status)==STMNONE)                                           \
59         arraycopy(array, byteindex);                                    \
60       *status=STMDIRTY;                                                 \
61     }                                                                   \
62     ((type *)(((char *) lengthoff)+sizeof(int)))[index]=src;            \
63   }
64 #endif