try to organize code more...
[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>>INDEXSHIFT)); \
19   }
20
21 #define GETLOCKVAL(lock, array, byteindex) {                            \
22     lock=*(unsigned int *)((char *)array-sizeof(objheader_t)-sizeof(int)*2*(byteindex>>INDEXSHIFT)); \
23   }
24
25 #define GETVERSIONVAL(version, array, byteindex) {                      \
26     version=*(unsigned int *)((char *)array-sizeof(objheader_t)-sizeof(int)*2*(byteindex>>INDEXSHIFT)-sizeof(int)); \
27   }
28
29 #define GETVERSIONPTR(version, array, byteindex) {                      \
30     version=(unsigned int *)((char *)array-sizeof(objheader_t)-sizeof(int)*2*(byteindex>>INDEXSHIFT)-sizeof(int)); \
31   }
32
33 #define STMGETARRAY(dst, array, index, type) {                          \
34     int byteindex=index*sizeof(type);                                   \
35     int * lengthoff=&array->___length___;                               \
36     int *status;                                                        \
37     GETLOCKPTR(status, array, byteindex);                               \
38     if ((*status)==STMNONE) {                                           \
39       arraycopy(array, byteindex);                                      \
40       *status=STMCLEAN;};                                               \
41     dst=((type *)(((char *) lengthoff)+sizeof(int)))[index];            \
42   }
43
44 #define STMSETARRAY(array, index, src, type) {                          \
45     int byteindex=index*sizeof(type);                                   \
46     int * lengthoff=&array->___length___;                               \
47     int *status;                                                        \
48     GETLOCKPTR(status, array);                                          \
49     if (*status==STMNONE)                                               \
50       arraycopy(array, byteindex, sizeof(type)*(*lengthoff));           \
51     *status=STMDIRTY;                                                   \
52     ((type *)(((char *) lengthoff)+sizeof(int)))[index]=src;            \
53   }
54 #endif