-static void reportDataRace(thread_id_t oldthread, modelclock_t oldclock, bool isoldwrite, ModelAction *newaction, bool isnewwrite, const void *address) {
- struct DataRace *race = (struct DataRace *)snapshot_malloc(sizeof(struct DataRace));
- race->oldthread=oldthread;
- race->oldclock=oldclock;
- race->isoldwrite=isoldwrite;
- race->newaction=newaction;
- race->isnewwrite=isnewwrite;
- race->address=address;
- unrealizedraces.push_back(race);
-
- /* If the race is realized, bail out now. */
- if (checkDataRaces()) {
- model->set_assert();
- model->switch_to_master(NULL);
+static struct DataRace * reportDataRace(thread_id_t oldthread, modelclock_t oldclock, bool isoldwrite, ModelAction *newaction, bool isnewwrite, const void *address)
+{
+ struct DataRace *race = (struct DataRace *)model_malloc(sizeof(struct DataRace));
+ race->oldthread = oldthread;
+ race->oldclock = oldclock;
+ race->isoldwrite = isoldwrite;
+ race->newaction = newaction;
+ race->isnewwrite = isnewwrite;
+ race->address = address;
+ return race;
+}
+
+/**
+ * @brief Assert a data race
+ *
+ * Asserts a data race which is currently realized, causing the execution to
+ * end and stashing a message in the model-checker's bug list
+ *
+ * @param race The race to report
+ */
+void assert_race(struct DataRace *race)
+{
+ model_print("Race detected at location: \n");
+ backtrace_symbols_fd(race->backtrace, race->numframes, model_out);
+ model_print("\nData race detected @ address %p:\n"
+ " Access 1: %5s in thread %2d @ clock %3u\n"
+ " Access 2: %5s in thread %2d @ clock %3u\n\n",
+ race->address,
+ race->isoldwrite ? "write" : "read",
+ id_to_int(race->oldthread),
+ race->oldclock,
+ race->isnewwrite ? "write" : "read",
+ id_to_int(race->newaction->get_tid()),
+ race->newaction->get_seq_number()
+ );
+}
+
+/** This function does race detection for a write on an expanded record. */
+struct DataRace * fullRaceCheckWrite(thread_id_t thread, void *location, uint64_t *shadow, ClockVector *currClock)
+{
+ struct RaceRecord *record = (struct RaceRecord *)(*shadow);
+ struct DataRace * race = NULL;
+
+ /* Check for datarace against last read. */
+
+ for (int i = 0;i < record->numReads;i++) {
+ modelclock_t readClock = record->readClock[i];
+ thread_id_t readThread = record->thread[i];
+
+ /* Note that readClock can't actuall be zero here, so it could be
+ optimized. */
+
+ if (clock_may_race(currClock, thread, readClock, readThread)) {
+ /* We have a datarace */
+ race = reportDataRace(readThread, readClock, false, get_execution()->get_parent_action(thread), true, location);
+ goto Exit;
+ }
+ }
+
+ /* Check for datarace against last write. */
+
+ {
+ modelclock_t writeClock = record->writeClock;
+ thread_id_t writeThread = record->writeThread;
+
+ if (clock_may_race(currClock, thread, writeClock, writeThread)) {
+ /* We have a datarace */
+ race = reportDataRace(writeThread, writeClock, true, get_execution()->get_parent_action(thread), true, location);
+ goto Exit;
+ }