void SyncVar::Init(ThreadState *thr, uptr pc, uptr addr, u64 uid) {
this->addr = addr;
this->uid = uid;
+ this->next = 0;
creation_stack_id = 0;
if (kCppMode) // Go does not use them
}
void SyncVar::Reset() {
- addr = 0;
uid = 0;
creation_stack_id = 0;
owner_tid = kInvalidTid;
is_recursive = 0;
is_broken = 0;
is_linker_init = 0;
- next = 0;
clock.Zero();
read_clock.Reset();
u32 myidx = 0;
SyncVar *mys = 0;
for (;;) {
- u32 idx = *meta;
+ u32 idx = idx0;
for (;;) {
if (idx == 0)
break;
}
if (!create)
return 0;
- if (*meta != idx0)
+ if (*meta != idx0) {
+ idx0 = *meta;
continue;
+ }
if (myidx == 0) {
const u64 uid = atomic_fetch_add(&uid_gen_, 1, memory_order_relaxed);
m->FreeRange(thr, 0, (uptr)&block2[0], 4 * sizeof(u64));
}
+TEST(MetaMap, ResetSync) {
+ ThreadState *thr = cur_thread();
+ MetaMap *m = &ctx->metamap;
+ u64 block[1] = {}; // fake malloc block
+ m->AllocBlock(thr, 0, (uptr)&block[0], 1 * sizeof(u64));
+ SyncVar *s = m->GetOrCreateAndLock(thr, 0, (uptr)&block[0], true);
+ s->Reset();
+ s->mtx.Unlock();
+ uptr sz = m->FreeBlock(thr, 0, (uptr)&block[0]);
+ EXPECT_EQ(sz, 1 * sizeof(u64));
+}
+
} // namespace __tsan