fix mutex_trylock bug
[c11tester.git] / datarace.cc
index d4d3d1c71a79f7d1d7f954f9ed72d7d4647233c1..9c403668e90d7c0fbe6ff76cda3cc3f1a2c37d81 100644 (file)
@@ -16,6 +16,7 @@ static void *memory_base;
 static void *memory_top;
 static RaceSet * raceset;
 
+#ifdef COLLECT_STAT
 static unsigned int store8_count = 0;
 static unsigned int store16_count = 0;
 static unsigned int store32_count = 0;
@@ -25,6 +26,7 @@ static unsigned int load8_count = 0;
 static unsigned int load16_count = 0;
 static unsigned int load32_count = 0;
 static unsigned int load64_count = 0;
+#endif
 
 static const ModelExecution * get_execution()
 {
@@ -53,7 +55,7 @@ void * table_calloc(size_t size)
 
 /** This function looks up the entry in the shadow table corresponding to a
  * given address.*/
-static uint64_t * lookupAddressEntry(const void *address)
+static inline uint64_t * lookupAddressEntry(const void *address)
 {
        struct ShadowTable *currtable = root;
 #if BIT48
@@ -153,6 +155,8 @@ static void expandRecord(uint64_t *shadow)
                ASSERT(readThread >= 0);
                record->thread[0] = readThread;
                record->readClock[0] = readClock;
+       } else {
+               record->thread = NULL;
        }
        if (shadowval & ATOMICMASK)
                record->isAtomic = 1;
@@ -496,7 +500,7 @@ void recordWrite(thread_id_t thread, void *location) {
 
 /** This function just updates metadata on atomic write. */
 void recordCalloc(void *location, size_t size) {
-       thread_id_t thread = thread_current()->get_id();
+       thread_id_t thread = thread_current_id();
        for(;size != 0;size--) {
                uint64_t *shadow = lookupAddressEntry(location);
                uint64_t shadowval = *shadow;
@@ -554,16 +558,16 @@ struct DataRace * fullRaceCheckRead(thread_id_t thread, const void *location, ui
                if (clock_may_race(currClock, thread, readClock, readThread)) {
                        /* Still need this read in vector */
                        if (copytoindex != i) {
-                               ASSERT(record->thread[i] >= 0);
-                               record->readClock[copytoindex] = record->readClock[i];
-                               record->thread[copytoindex] = record->thread[i];
+                               ASSERT(readThread >= 0);
+                               record->readClock[copytoindex] = readClock;
+                               record->thread[copytoindex] = readThread;
                        }
                        copytoindex++;
                }
        }
 
        if (__builtin_popcount(copytoindex) <= 1) {
-               if (copytoindex == 0) {
+               if (copytoindex == 0 && record->thread == NULL) {
                        int newCapacity = INITCAPACITY;
                        record->thread = (thread_id_t *)snapshot_malloc(sizeof(thread_id_t) * newCapacity);
                        record->readClock = (modelclock_t *)snapshot_malloc(sizeof(modelclock_t) * newCapacity);
@@ -1210,6 +1214,7 @@ void raceCheckWrite8(thread_id_t thread, const void *location)
        raceCheckWrite_firstIt(thread, location, &old_shadowval, &new_shadowval);
 }
 
+#ifdef COLLECT_STAT
 void print_normal_accesses()
 {
        model_print("store 8  count: %u\n", store8_count);
@@ -1222,3 +1227,4 @@ void print_normal_accesses()
        model_print("load  32 count: %u\n", load32_count);
        model_print("load  64 count: %u\n", load64_count);
 }
+#endif