2 * @brief Data race detection code.
8 #include "clockvector.h"
15 struct ShadowBaseTable {
16 uint64_t array[65536];
20 /* Clock and thread associated with first action. This won't change in
21 response to synchronization. */
23 thread_id_t oldthread;
24 modelclock_t oldclock;
25 /* Record whether this is a write, so we can tell the user. */
28 /* Model action associated with second action. This could change as
29 a result of synchronization. */
30 ModelAction *newaction;
31 /* Record whether this is a write, so we can tell the user. */
34 /* Address of data race. */
38 #define MASK16BIT 0xffff
40 void initRaceDetector();
41 void raceCheckWrite(thread_id_t thread, void *location, ClockVector *currClock);
42 void raceCheckRead(thread_id_t thread, void *location, ClockVector *currClock);
43 bool checkDataRaces();
44 void printRace(struct DataRace *race);
46 extern std::vector<struct DataRace *> unrealizedraces;
48 /** Basic encoding idea:
50 * (1) points to a full record or
52 * (2) encodes the information in a 64 bit word. Encoding is as
53 * follows: lowest bit set to 1, next 8 bits are read thread id, next
54 * 23 bits are read clock vector, next 8 bites are write thread id,
55 * next 23 bits are write clock vector. */
58 modelclock_t *readClock;
62 thread_id_t writeThread;
63 modelclock_t writeClock;
66 #define INITCAPACITY 4
68 #define ISSHORTRECORD(x) ((x)&0x1)
70 #define THREADMASK 0xff
71 #define RDTHREADID(x) (((x)>>1)&THREADMASK)
72 #define READMASK 0x07fffff
73 #define READVECTOR(x) (((x)>>9)&READMASK)
75 #define WRTHREADID(x) (((x)>>32)&THREADMASK)
77 #define WRITEMASK READMASK
78 #define WRITEVECTOR(x) (((x)>>40)&WRITEMASK)
80 #define ENCODEOP(rdthread, rdtime, wrthread, wrtime) (0x1ULL | ((rdthread)<<1) | ((rdtime) << 9) | (((uint64_t)wrthread)<<32) | (((uint64_t)wrtime)<<40))
82 #define MAXTHREADID (THREADMASK-1)
83 #define MAXREADVECTOR (READMASK-1)
84 #define MAXWRITEVECTOR (WRITEMASK-1)