Merge branch 'master' of ssh://demsky.eecs.uci.edu/home/git/model-checker
[c11tester.git] / datarace.h
1 #ifndef DATARACE_H
2 #include "config.h"
3 #include <stdint.h>
4 #include "clockvector.h"
5
6 struct ShadowTable {
7         void * array[65536];
8 };
9
10 struct ShadowBaseTable {
11         uint64_t array[65536];
12 };
13
14 #define MASK16BIT 0xffff
15
16 void initRaceDetector();
17 void raceCheckWrite(thread_id_t thread, void *location, ClockVector *currClock);
18 void raceCheckRead(thread_id_t thread, void *location, ClockVector *currClock);
19
20
21
22 /** Encoding idea:
23  *       (void *) Either:
24  *       (1) points to a full record or
25  *
26  * (2) encodes the information in a 64 bit word.  Encoding is as
27  * follows: lowest bit set to 1, next 8 bits are read thread id, next
28  * 23 bits are read clock vector, next 8 bites are write thread id,
29  * next 23 bits are write clock vector.  */
30
31 struct RaceRecord {
32         modelclock_t *readClock;
33         thread_id_t *thread;
34         int capacity;
35         int numReads;
36         thread_id_t writeThread;
37         modelclock_t writeClock;
38 };
39
40 #define INITCAPACITY 4
41
42 #define ISSHORTRECORD(x) ((x)&0x1)
43
44 #define THREADMASK 0xff
45 #define RDTHREADID(x) (((x)>>1)&THREADMASK)
46 #define READMASK 0x07fffff
47 #define READVECTOR(x) (((x)>>9)&READMASK)
48
49 #define WRTHREADID(x) (((x)>>32)&THREADMASK)
50
51 #define WRITEMASK READMASK
52 #define WRITEVECTOR(x) (((x)>>40)&WRITEMASK)
53
54 #define ENCODEOP(rdthread, rdtime, wrthread, wrtime) (0x1ULL | ((rdthread)<<1) | ((rdtime) << 9) | (((uint64_t)wrthread)<<32) | (((uint64_t)wrtime)<<40))
55
56 #define MAXTHREADID (THREADMASK-1)
57 #define MAXREADVECTOR (READMASK-1)
58 #define MAXWRITEVECTOR (WRITEMASK-1)
59 #endif