Lines Matching defs:thr
26 void ReportDeadlock(ThreadState *thr, uptr pc, DDReport *r);
29 ThreadState *thr;
32 Callback(ThreadState *thr, uptr pc)
33 : thr(thr)
35 DDCallback::pt = thr->dd_pt;
36 DDCallback::lt = thr->dd_lt;
39 u32 Unwind() override { return CurrentStackId(thr, pc); }
40 int UniqueTid() override { return thr->unique_id; }
43 void DDMutexInit(ThreadState *thr, uptr pc, SyncVar *s) {
44 Callback cb(thr, pc);
49 static void ReportMutexMisuse(ThreadState *thr, uptr pc, ReportType typ,
59 ObtainCurrentStack(thr, pc, &trace);
62 OutputReport(thr, rep);
65 void MutexCreate(ThreadState *thr, uptr pc, uptr addr,
67 DPrintf("#%d: MutexCreate %zx\n", thr->tid, addr);
68 StatInc(thr, StatMutexCreate);
70 CHECK(!thr->is_freeing);
71 thr->is_freeing = true;
72 MemoryWrite(thr, pc, addr, kSizeLog1);
73 thr->is_freeing = false;
75 SyncVar *s = ctx->metamap.GetOrCreateAndLock(thr, pc, addr, true);
80 s->creation_stack_id = CurrentStackId(thr, pc);
84 void MutexDestroy(ThreadState *thr, uptr pc, uptr addr) {
85 DPrintf("#%d: MutexDestroy %zx\n", thr->tid, addr);
86 StatInc(thr, StatMutexDestroy);
94 CHECK(!thr->is_freeing);
95 thr->is_freeing = true;
96 MemoryWrite(thr, pc, addr, kSizeLog1);
97 thr->is_freeing = false;
103 Callback cb(thr, pc);
117 s->Reset(thr); // must not reset it before the report is printed
124 ObtainCurrentStack(thr, pc, &trace);
130 OutputReport(thr, rep);
135 s->Reset(thr);
139 thr->mset.Remove(mid);
143 void MutexLock(ThreadState *thr, uptr pc, uptr addr, int rec, bool try_lock) {
144 DPrintf("#%d: MutexLock %zx rec=%d\n", thr->tid, addr, rec);
147 MemoryReadAtomic(thr, pc, addr, kSizeLog1);
148 SyncVar *s = ctx->metamap.GetOrCreateAndLock(thr, pc, addr, true);
149 thr->fast_state.IncrementEpoch();
150 TraceAddEvent(thr, thr->fast_state, EventTypeLock, s->GetId());
154 s->owner_tid = thr->tid;
155 s->last_lock = thr->fast_state.raw();
156 } else if (s->owner_tid == thr->tid) {
163 StatInc(thr, StatMutexLock);
164 AcquireImpl(thr, pc, &s->clock);
165 AcquireImpl(thr, pc, &s->read_clock);
167 StatInc(thr, StatMutexRecLock);
170 thr->mset.Add(s->GetId(), true, thr->fast_state.epoch());
172 Callback cb(thr, pc);
181 ReportMutexMisuse(thr, pc, ReportTypeMutexDoubleLock, addr, mid);
183 Callback cb(thr, pc);
184 ReportDeadlock(thr, pc, ctx->dd->GetReport(&cb));
188 int MutexUnlock(ThreadState *thr, uptr pc, uptr addr, bool all) {
189 DPrintf("#%d: MutexUnlock %zx all=%d\n", thr->tid, addr, all);
191 MemoryReadAtomic(thr, pc, addr, kSizeLog1);
192 SyncVar *s = ctx->metamap.GetOrCreateAndLock(thr, pc, addr, true);
193 thr->fast_state.IncrementEpoch();
194 TraceAddEvent(thr, thr->fast_state, EventTypeUnlock, s->GetId());
197 if (kCppMode && (s->recursion == 0 || s->owner_tid != thr->tid)) {
206 StatInc(thr, StatMutexUnlock);
208 ReleaseStoreImpl(thr, pc, &s->clock);
210 StatInc(thr, StatMutexRecUnlock);
213 thr->mset.Del(s->GetId(), true);
216 Callback cb(thr, pc);
223 ReportMutexMisuse(thr, pc, ReportTypeMutexBadUnlock, addr, mid);
225 Callback cb(thr, pc);
226 ReportDeadlock(thr, pc, ctx->dd->GetReport(&cb));
231 void MutexReadLock(ThreadState *thr, uptr pc, uptr addr, bool trylock) {
232 DPrintf("#%d: MutexReadLock %zx\n", thr->tid, addr);
233 StatInc(thr, StatMutexReadLock);
235 MemoryReadAtomic(thr, pc, addr, kSizeLog1);
236 SyncVar *s = ctx->metamap.GetOrCreateAndLock(thr, pc, addr, false);
237 thr->fast_state.IncrementEpoch();
238 TraceAddEvent(thr, thr->fast_state, EventTypeRLock, s->GetId());
246 AcquireImpl(thr, pc, &s->clock);
247 s->last_lock = thr->fast_state.raw();
248 thr->mset.Add(s->GetId(), false, thr->fast_state.epoch());
250 Callback cb(thr, pc);
259 ReportMutexMisuse(thr, pc, ReportTypeMutexBadReadLock, addr, mid);
261 Callback cb(thr, pc);
262 ReportDeadlock(thr, pc, ctx->dd->GetReport(&cb));
266 void MutexReadUnlock(ThreadState *thr, uptr pc, uptr addr) {
267 DPrintf("#%d: MutexReadUnlock %zx\n", thr->tid, addr);
268 StatInc(thr, StatMutexReadUnlock);
270 MemoryReadAtomic(thr, pc, addr, kSizeLog1);
271 SyncVar *s = ctx->metamap.GetOrCreateAndLock(thr, pc, addr, true);
272 thr->fast_state.IncrementEpoch();
273 TraceAddEvent(thr, thr->fast_state, EventTypeRUnlock, s->GetId());
281 ReleaseImpl(thr, pc, &s->read_clock);
283 Callback cb(thr, pc);
289 thr->mset.Del(mid, false);
291 ReportMutexMisuse(thr, pc, ReportTypeMutexBadReadUnlock, addr, mid);
293 Callback cb(thr, pc);
294 ReportDeadlock(thr, pc, ctx->dd->GetReport(&cb));
298 void MutexReadOrWriteUnlock(ThreadState *thr, uptr pc, uptr addr) {
299 DPrintf("#%d: MutexReadOrWriteUnlock %zx\n", thr->tid, addr);
301 MemoryReadAtomic(thr, pc, addr, kSizeLog1);
302 SyncVar *s = ctx->metamap.GetOrCreateAndLock(thr, pc, addr, true);
308 StatInc(thr, StatMutexReadUnlock);
309 thr->fast_state.IncrementEpoch();
310 TraceAddEvent(thr, thr->fast_state, EventTypeRUnlock, s->GetId());
311 ReleaseImpl(thr, pc, &s->read_clock);
312 } else if (s->owner_tid == thr->tid) {
314 thr->fast_state.IncrementEpoch();
315 TraceAddEvent(thr, thr->fast_state, EventTypeUnlock, s->GetId());
319 StatInc(thr, StatMutexUnlock);
321 ReleaseImpl(thr, pc, &s->clock);
323 StatInc(thr, StatMutexRecUnlock);
329 thr->mset.Del(s->GetId(), write);
331 Callback cb(thr, pc);
338 ReportMutexMisuse(thr, pc, ReportTypeMutexBadUnlock, addr, mid);
340 Callback cb(thr, pc);
341 ReportDeadlock(thr, pc, ctx->dd->GetReport(&cb));
345 void MutexRepair(ThreadState *thr, uptr pc, uptr addr) {
346 DPrintf("#%d: MutexRepair %zx\n", thr->tid, addr);
347 SyncVar *s = ctx->metamap.GetOrCreateAndLock(thr, pc, addr, true);
353 void Acquire(ThreadState *thr, uptr pc, uptr addr) {
354 DPrintf("#%d: Acquire %zx\n", thr->tid, addr);
355 if (thr->ignore_sync)
357 SyncVar *s = ctx->metamap.GetOrCreateAndLock(thr, pc, addr, false);
358 AcquireImpl(thr, pc, &s->clock);
363 ThreadState *thr = reinterpret_cast<ThreadState*>(arg);
366 thr->clock.set(tctx->tid, tctx->thr->fast_state.epoch());
368 thr->clock.set(tctx->tid, tctx->epoch1);
371 void AcquireGlobal(ThreadState *thr, uptr pc) {
372 DPrintf("#%d: AcquireGlobal\n", thr->tid);
373 if (thr->ignore_sync)
377 UpdateClockCallback, thr);
380 void Release(ThreadState *thr, uptr pc, uptr addr) {
381 DPrintf("#%d: Release %zx\n", thr->tid, addr);
382 if (thr->ignore_sync)
384 SyncVar *s = ctx->metamap.GetOrCreateAndLock(thr, pc, addr, true);
385 thr->fast_state.IncrementEpoch();
387 TraceAddEvent(thr, thr->fast_state, EventTypeMop, 0);
388 ReleaseImpl(thr, pc, &s->clock);
392 void ReleaseStore(ThreadState *thr, uptr pc, uptr addr) {
393 DPrintf("#%d: ReleaseStore %zx\n", thr->tid, addr);
394 if (thr->ignore_sync)
396 SyncVar *s = ctx->metamap.GetOrCreateAndLock(thr, pc, addr, true);
397 thr->fast_state.IncrementEpoch();
399 TraceAddEvent(thr, thr->fast_state, EventTypeMop, 0);
400 ReleaseStoreImpl(thr, pc, &s->clock);
406 ThreadState *thr = reinterpret_cast<ThreadState*>(arg);
409 thr->last_sleep_clock.set(tctx->tid, tctx->thr->fast_state.epoch());
411 thr->last_sleep_clock.set(tctx->tid, tctx->epoch1);
414 void AfterSleep(ThreadState *thr, uptr pc) {
415 DPrintf("#%d: AfterSleep %zx\n", thr->tid);
416 if (thr->ignore_sync)
418 thr->last_sleep_stack_id = CurrentStackId(thr, pc);
421 UpdateSleepClockCallback, thr);
425 void AcquireImpl(ThreadState *thr, uptr pc, SyncClock *c) {
426 if (thr->ignore_sync)
428 thr->clock.set(thr->fast_state.epoch());
429 thr->clock.acquire(&thr->clock_cache, c);
430 StatInc(thr, StatSyncAcquire);
433 void ReleaseImpl(ThreadState *thr, uptr pc, SyncClock *c) {
434 if (thr->ignore_sync)
436 thr->clock.set(thr->fast_state.epoch());
437 thr->fast_synch_epoch = thr->fast_state.epoch();
438 thr->clock.release(&thr->clock_cache, c);
439 StatInc(thr, StatSyncRelease);
442 void ReleaseStoreImpl(ThreadState *thr, uptr pc, SyncClock *c) {
443 if (thr->ignore_sync)
445 thr->clock.set(thr->fast_state.epoch());
446 thr->fast_synch_epoch = thr->fast_state.epoch();
447 thr->clock.ReleaseStore(&thr->clock_cache, c);
448 StatInc(thr, StatSyncRelease);
451 void AcquireReleaseImpl(ThreadState *thr, uptr pc, SyncClock *c) {
452 if (thr->ignore_sync)
454 thr->clock.set(thr->fast_state.epoch());
455 thr->fast_synch_epoch = thr->fast_state.epoch();
456 thr->clock.acq_rel(&thr->clock_cache, c);
457 StatInc(thr, StatSyncAcquire);
458 StatInc(thr, StatSyncRelease);
461 void ReportDeadlock(ThreadState *thr, uptr pc, DDReport *r) {
484 OutputReport(thr, rep);