cyclegraph: missing form of checkReachable()
[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 <vector>
9 #include "modeltypes.h"
10
11 /* Forward declaration */
12 class ClockVector;
13 class ModelAction;
14
15 struct ShadowTable {
16         void * array[65536];
17 };
18
19 struct ShadowBaseTable {
20         uint64_t array[65536];
21 };
22
23 struct DataRace {
24         /* Clock and thread associated with first action.  This won't change in
25                  response to synchronization. */
26
27         thread_id_t oldthread;
28         modelclock_t oldclock;
29         /* Record whether this is a write, so we can tell the user. */
30         bool isoldwrite;
31
32         /* Model action associated with second action.  This could change as
33                  a result of synchronization. */
34         ModelAction *newaction;
35         /* Record whether this is a write, so we can tell the user. */
36         bool isnewwrite;
37
38         /* Address of data race. */
39         const void *address;
40 };
41
42 #define MASK16BIT 0xffff
43
44 void initRaceDetector();
45 void raceCheckWrite(thread_id_t thread, void *location, ClockVector *currClock);
46 void raceCheckRead(thread_id_t thread, const void *location, ClockVector *currClock);
47 bool checkDataRaces();
48 void assert_race(struct DataRace *race);
49
50 extern std::vector<struct DataRace *> unrealizedraces;
51
52 /** Basic encoding idea:
53  *       (void *) Either:
54  *       (1) points to a full record or
55  *
56  * (2) encodes the information in a 64 bit word.  Encoding is as
57  * follows: lowest bit set to 1, next 8 bits are read thread id, next
58  * 23 bits are read clock vector, next 8 bites are write thread id,
59  * next 23 bits are write clock vector.  */
60
61 struct RaceRecord {
62         modelclock_t *readClock;
63         thread_id_t *thread;
64         int capacity;
65         int numReads;
66         thread_id_t writeThread;
67         modelclock_t writeClock;
68 };
69
70 #define INITCAPACITY 4
71
72 #define ISSHORTRECORD(x) ((x)&0x1)
73
74 #define THREADMASK 0xff
75 #define RDTHREADID(x) (((x)>>1)&THREADMASK)
76 #define READMASK 0x07fffff
77 #define READVECTOR(x) (((x)>>9)&READMASK)
78
79 #define WRTHREADID(x) (((x)>>32)&THREADMASK)
80
81 #define WRITEMASK READMASK
82 #define WRITEVECTOR(x) (((x)>>40)&WRITEMASK)
83
84 #define ENCODEOP(rdthread, rdtime, wrthread, wrtime) (0x1ULL | ((rdthread)<<1) | ((rdtime) << 9) | (((uint64_t)wrthread)<<32) | (((uint64_t)wrtime)<<40))
85
86 #define MAXTHREADID (THREADMASK-1)
87 #define MAXREADVECTOR (READMASK-1)
88 #define MAXWRITEVECTOR (WRITEMASK-1)
89 #endif