record->writeClock = writeClock;
if (readClock != 0) {
- record->capacity = INITCAPACITY;
- record->thread = (thread_id_t *)snapshot_malloc(sizeof(thread_id_t) * record->capacity);
- record->readClock = (modelclock_t *)snapshot_malloc(sizeof(modelclock_t) * record->capacity);
+ record->thread = (thread_id_t *)snapshot_malloc(sizeof(thread_id_t) * INITCAPACITY);
+ record->readClock = (modelclock_t *)snapshot_malloc(sizeof(modelclock_t) * INITCAPACITY);
record->numReads = 1;
ASSERT(readThread >= 0);
record->thread[0] = readThread;
record->readClock[0] = readClock;
}
+ if (shadowval & ATOMICMASK)
+ record->isAtomic = 1;
*shadow = (uint64_t) record;
}
Exit:
record->numReads = 0;
record->writeThread = thread;
+ record->isAtomic = 0;
modelclock_t ourClock = currClock->getClock(thread);
record->writeClock = ourClock;
return race;
record->writeThread = thread;
modelclock_t ourClock = currClock->getClock(thread);
record->writeClock = ourClock;
+ record->isAtomic = 1;
}
/** This function just updates metadata on atomic write. */
return;
}
- *shadow = ENCODEOP(0, 0, threadid, ourClock);
+ *shadow = ENCODEOP(0, 0, threadid, ourClock) | ATOMICMASK;
}
}
}
- if (copytoindex >= record->capacity) {
- if (record->capacity == 0) {
+ if (__builtin_popcount(copytoindex) <= 1) {
+ if (copytoindex == 0) {
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);
- record->capacity = newCapacity;
- } else {
- int newCapacity = record->capacity * 2;
+ } else if (copytoindex>=INITCAPACITY) {
+ int newCapacity = copytoindex * 2;
thread_id_t *newthread = (thread_id_t *)snapshot_malloc(sizeof(thread_id_t) * newCapacity);
modelclock_t *newreadClock = (modelclock_t *)snapshot_malloc(sizeof(modelclock_t) * newCapacity);
- std::memcpy(newthread, record->thread, record->capacity * sizeof(thread_id_t));
- std::memcpy(newreadClock, record->readClock, record->capacity * sizeof(modelclock_t));
+ std::memcpy(newthread, record->thread, copytoindex * sizeof(thread_id_t));
+ std::memcpy(newreadClock, record->readClock, copytoindex * sizeof(modelclock_t));
snapshot_free(record->readClock);
snapshot_free(record->thread);
record->readClock = newreadClock;
record->thread = newthread;
- record->capacity = newCapacity;
}
}
}
}
- *shadow = ENCODEOP(threadid, ourClock, id_to_int(writeThread), writeClock);
+ *shadow = ENCODEOP(threadid, ourClock, id_to_int(writeThread), writeClock) | (shadowval & ATOMICMASK);
}
Exit:
if (race) {
struct RaceRecord {
modelclock_t *readClock;
thread_id_t *thread;
- int capacity;
- int numReads;
+ int numReads : 31;
+ int isAtomic : 1;
thread_id_t writeThread;
modelclock_t writeClock;
};
#define WRITEMASK READMASK
#define WRITEVECTOR(x) (((x)>>38)&WRITEMASK)
+#define ATOMICMASK (0x1ULL << 63)
+#define NONATOMICMASK ~(0x1ULL << 63)
+
/**
* The basic encoding idea is that (void *) either:
* -# points to a full record (RaceRecord) or
* - next 25 bits are read clock vector
* - next 6 bits are write thread id
* - next 25 bits are write clock vector
+ * - highest bit is 1 if the write is from an atomic
*/
#define ENCODEOP(rdthread, rdtime, wrthread, wrtime) (0x1ULL | ((rdthread)<<1) | ((rdtime) << 7) | (((uint64_t)wrthread)<<32) | (((uint64_t)wrtime)<<38))