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