Lines Matching refs:thr

25 void ReportDeadlock(ThreadState *thr, uptr pc, DDReport *r);
28 ThreadState *thr; member
31 Callback(ThreadState *thr, uptr pc) in Callback()
32 : thr(thr) in Callback()
34 DDCallback::pt = thr->proc()->dd_pt; in Callback()
35 DDCallback::lt = thr->dd_lt; in Callback()
38 StackID Unwind() override { return CurrentStackId(thr, pc); } in Unwind()
39 int UniqueTid() override { return thr->unique_id; } in UniqueTid()
42 void DDMutexInit(ThreadState *thr, uptr pc, SyncVar *s) { in DDMutexInit() argument
43 Callback cb(thr, pc); in DDMutexInit()
48 static void ReportMutexMisuse(ThreadState *thr, uptr pc, ReportType typ, in ReportMutexMisuse() argument
54 if (!ShouldReport(thr, typ)) in ReportMutexMisuse()
60 ObtainCurrentStack(thr, pc, &trace); in ReportMutexMisuse()
63 OutputReport(thr, rep); in ReportMutexMisuse()
66 void MutexCreate(ThreadState *thr, uptr pc, uptr addr, u32 flagz) { in MutexCreate() argument
67 DPrintf("#%d: MutexCreate %zx flagz=0x%x\n", thr->tid, addr, flagz); in MutexCreate()
69 CHECK(!thr->is_freeing); in MutexCreate()
70 thr->is_freeing = true; in MutexCreate()
71 MemoryAccess(thr, pc, addr, 1, kAccessWrite); in MutexCreate()
72 thr->is_freeing = false; in MutexCreate()
74 SyncVar *s = ctx->metamap.GetSyncOrCreate(thr, pc, addr, true); in MutexCreate()
79 s->creation_stack_id = CurrentStackId(thr, pc); in MutexCreate()
82 void MutexDestroy(ThreadState *thr, uptr pc, uptr addr, u32 flagz) { in MutexDestroy() argument
83 DPrintf("#%d: MutexDestroy %zx\n", thr->tid, addr); in MutexDestroy()
98 Callback cb(thr, pc); in MutexDestroy()
110 s->Reset(thr->proc()); // must not reset it before the report is printed in MutexDestroy()
112 if (unlock_locked && ShouldReport(thr, ReportTypeMutexDestroyLocked)) { in MutexDestroy()
117 ObtainCurrentStack(thr, pc, &trace); in MutexDestroy()
123 OutputReport(thr, rep); in MutexDestroy()
128 s->Reset(thr->proc()); in MutexDestroy()
131 thr->mset.Remove(mid); in MutexDestroy()
136 MemoryAccess(thr, pc, addr, 1, kAccessWrite | kAccessFree); in MutexDestroy()
140 void MutexPreLock(ThreadState *thr, uptr pc, uptr addr, u32 flagz) { in MutexPreLock() argument
141 DPrintf("#%d: MutexPreLock %zx flagz=0x%x\n", thr->tid, addr, flagz); in MutexPreLock()
143 SyncVar *s = ctx->metamap.GetSyncOrCreate(thr, pc, addr, true); in MutexPreLock()
147 if (s->owner_tid != thr->tid) { in MutexPreLock()
148 Callback cb(thr, pc); in MutexPreLock()
152 Callback cb(thr, pc); in MutexPreLock()
153 ReportDeadlock(thr, pc, ctx->dd->GetReport(&cb)); in MutexPreLock()
157 void MutexPostLock(ThreadState *thr, uptr pc, uptr addr, u32 flagz, int rec) { in MutexPostLock() argument
159 thr->tid, addr, flagz, rec); in MutexPostLock()
165 MemoryAccess(thr, pc, addr, 1, kAccessRead | kAccessAtomic); in MutexPostLock()
171 SyncVar *s = ctx->metamap.GetSyncOrCreate(thr, pc, addr, true); in MutexPostLock()
174 thr->fast_state.IncrementEpoch(); in MutexPostLock()
175 TraceAddEvent(thr, thr->fast_state, EventTypeLock, s->GetId()); in MutexPostLock()
178 s->owner_tid = thr->tid; in MutexPostLock()
179 s->last_lock = thr->fast_state.raw(); in MutexPostLock()
180 } else if (s->owner_tid == thr->tid) { in MutexPostLock()
189 AcquireImpl(thr, pc, &s->clock); in MutexPostLock()
190 AcquireImpl(thr, pc, &s->read_clock); in MutexPostLock()
193 thr->mset.Add(s->GetId(), true, thr->fast_state.epoch()); in MutexPostLock()
197 Callback cb(thr, pc); in MutexPostLock()
205 ReportMutexMisuse(thr, pc, ReportTypeMutexDoubleLock, addr, mid); in MutexPostLock()
207 Callback cb(thr, pc); in MutexPostLock()
208 ReportDeadlock(thr, pc, ctx->dd->GetReport(&cb)); in MutexPostLock()
212 int MutexUnlock(ThreadState *thr, uptr pc, uptr addr, u32 flagz) { in MutexUnlock() argument
213 DPrintf("#%d: MutexUnlock %zx flagz=0x%x\n", thr->tid, addr, flagz); in MutexUnlock()
215 MemoryAccess(thr, pc, addr, 1, kAccessRead | kAccessAtomic); in MutexUnlock()
220 SyncVar *s = ctx->metamap.GetSyncOrCreate(thr, pc, addr, true); in MutexUnlock()
222 thr->fast_state.IncrementEpoch(); in MutexUnlock()
223 TraceAddEvent(thr, thr->fast_state, EventTypeUnlock, s->GetId()); in MutexUnlock()
224 if (!SANITIZER_GO && (s->recursion == 0 || s->owner_tid != thr->tid)) { in MutexUnlock()
234 ReleaseStoreImpl(thr, pc, &s->clock); in MutexUnlock()
238 thr->mset.Del(s->GetId(), true); in MutexUnlock()
241 Callback cb(thr, pc); in MutexUnlock()
247 ReportMutexMisuse(thr, pc, ReportTypeMutexBadUnlock, addr, mid); in MutexUnlock()
249 Callback cb(thr, pc); in MutexUnlock()
250 ReportDeadlock(thr, pc, ctx->dd->GetReport(&cb)); in MutexUnlock()
255 void MutexPreReadLock(ThreadState *thr, uptr pc, uptr addr, u32 flagz) { in MutexPreReadLock() argument
256 DPrintf("#%d: MutexPreReadLock %zx flagz=0x%x\n", thr->tid, addr, flagz); in MutexPreReadLock()
259 SyncVar *s = ctx->metamap.GetSyncOrCreate(thr, pc, addr, true); in MutexPreReadLock()
262 Callback cb(thr, pc); in MutexPreReadLock()
265 Callback cb(thr, pc); in MutexPreReadLock()
266 ReportDeadlock(thr, pc, ctx->dd->GetReport(&cb)); in MutexPreReadLock()
270 void MutexPostReadLock(ThreadState *thr, uptr pc, uptr addr, u32 flagz) { in MutexPostReadLock() argument
271 DPrintf("#%d: MutexPostReadLock %zx flagz=0x%x\n", thr->tid, addr, flagz); in MutexPostReadLock()
273 MemoryAccess(thr, pc, addr, 1, kAccessRead | kAccessAtomic); in MutexPostReadLock()
278 SyncVar *s = ctx->metamap.GetSyncOrCreate(thr, pc, addr, true); in MutexPostReadLock()
281 thr->fast_state.IncrementEpoch(); in MutexPostReadLock()
282 TraceAddEvent(thr, thr->fast_state, EventTypeRLock, s->GetId()); in MutexPostReadLock()
289 AcquireImpl(thr, pc, &s->clock); in MutexPostReadLock()
290 s->last_lock = thr->fast_state.raw(); in MutexPostReadLock()
291 thr->mset.Add(s->GetId(), false, thr->fast_state.epoch()); in MutexPostReadLock()
295 Callback cb(thr, pc); in MutexPostReadLock()
303 ReportMutexMisuse(thr, pc, ReportTypeMutexBadReadLock, addr, mid); in MutexPostReadLock()
305 Callback cb(thr, pc); in MutexPostReadLock()
306 ReportDeadlock(thr, pc, ctx->dd->GetReport(&cb)); in MutexPostReadLock()
310 void MutexReadUnlock(ThreadState *thr, uptr pc, uptr addr) { in MutexReadUnlock() argument
311 DPrintf("#%d: MutexReadUnlock %zx\n", thr->tid, addr); in MutexReadUnlock()
313 MemoryAccess(thr, pc, addr, 1, kAccessRead | kAccessAtomic); in MutexReadUnlock()
317 SyncVar *s = ctx->metamap.GetSyncOrCreate(thr, pc, addr, true); in MutexReadUnlock()
319 thr->fast_state.IncrementEpoch(); in MutexReadUnlock()
320 TraceAddEvent(thr, thr->fast_state, EventTypeRUnlock, s->GetId()); in MutexReadUnlock()
327 ReleaseImpl(thr, pc, &s->read_clock); in MutexReadUnlock()
329 Callback cb(thr, pc); in MutexReadUnlock()
334 thr->mset.Del(mid, false); in MutexReadUnlock()
336 ReportMutexMisuse(thr, pc, ReportTypeMutexBadReadUnlock, addr, mid); in MutexReadUnlock()
338 Callback cb(thr, pc); in MutexReadUnlock()
339 ReportDeadlock(thr, pc, ctx->dd->GetReport(&cb)); in MutexReadUnlock()
343 void MutexReadOrWriteUnlock(ThreadState *thr, uptr pc, uptr addr) { in MutexReadOrWriteUnlock() argument
344 DPrintf("#%d: MutexReadOrWriteUnlock %zx\n", thr->tid, addr); in MutexReadOrWriteUnlock()
346 MemoryAccess(thr, pc, addr, 1, kAccessRead | kAccessAtomic); in MutexReadOrWriteUnlock()
350 SyncVar *s = ctx->metamap.GetSyncOrCreate(thr, pc, addr, true); in MutexReadOrWriteUnlock()
356 thr->fast_state.IncrementEpoch(); in MutexReadOrWriteUnlock()
357 TraceAddEvent(thr, thr->fast_state, EventTypeRUnlock, s->GetId()); in MutexReadOrWriteUnlock()
358 ReleaseImpl(thr, pc, &s->read_clock); in MutexReadOrWriteUnlock()
359 } else if (s->owner_tid == thr->tid) { in MutexReadOrWriteUnlock()
361 thr->fast_state.IncrementEpoch(); in MutexReadOrWriteUnlock()
362 TraceAddEvent(thr, thr->fast_state, EventTypeUnlock, s->GetId()); in MutexReadOrWriteUnlock()
367 ReleaseStoreImpl(thr, pc, &s->clock); in MutexReadOrWriteUnlock()
374 thr->mset.Del(s->GetId(), write); in MutexReadOrWriteUnlock()
376 Callback cb(thr, pc); in MutexReadOrWriteUnlock()
382 ReportMutexMisuse(thr, pc, ReportTypeMutexBadUnlock, addr, mid); in MutexReadOrWriteUnlock()
384 Callback cb(thr, pc); in MutexReadOrWriteUnlock()
385 ReportDeadlock(thr, pc, ctx->dd->GetReport(&cb)); in MutexReadOrWriteUnlock()
389 void MutexRepair(ThreadState *thr, uptr pc, uptr addr) { in MutexRepair() argument
390 DPrintf("#%d: MutexRepair %zx\n", thr->tid, addr); in MutexRepair()
391 SyncVar *s = ctx->metamap.GetSyncOrCreate(thr, pc, addr, true); in MutexRepair()
397 void MutexInvalidAccess(ThreadState *thr, uptr pc, uptr addr) { in MutexInvalidAccess() argument
398 DPrintf("#%d: MutexInvalidAccess %zx\n", thr->tid, addr); in MutexInvalidAccess()
399 SyncVar *s = ctx->metamap.GetSyncOrCreate(thr, pc, addr, true); in MutexInvalidAccess()
400 ReportMutexMisuse(thr, pc, ReportTypeMutexInvalidAccess, addr, s->GetId()); in MutexInvalidAccess()
403 void Acquire(ThreadState *thr, uptr pc, uptr addr) { in Acquire() argument
404 DPrintf("#%d: Acquire %zx\n", thr->tid, addr); in Acquire()
405 if (thr->ignore_sync) in Acquire()
411 AcquireImpl(thr, pc, &s->clock); in Acquire()
415 ThreadState *thr = reinterpret_cast<ThreadState*>(arg); in UpdateClockCallback() local
419 epoch = tctx->thr->fast_state.epoch(); in UpdateClockCallback()
420 tctx->thr->clock.NoteGlobalAcquire(epoch); in UpdateClockCallback()
422 thr->clock.set(&thr->proc()->clock_cache, tctx->tid, epoch); in UpdateClockCallback()
425 void AcquireGlobal(ThreadState *thr) { in AcquireGlobal() argument
426 DPrintf("#%d: AcquireGlobal\n", thr->tid); in AcquireGlobal()
427 if (thr->ignore_sync) in AcquireGlobal()
430 ctx->thread_registry.RunCallbackForEachThreadLocked(UpdateClockCallback, thr); in AcquireGlobal()
433 void ReleaseStoreAcquire(ThreadState *thr, uptr pc, uptr addr) { in ReleaseStoreAcquire() argument
434 DPrintf("#%d: ReleaseStoreAcquire %zx\n", thr->tid, addr); in ReleaseStoreAcquire()
435 if (thr->ignore_sync) in ReleaseStoreAcquire()
437 SyncVar *s = ctx->metamap.GetSyncOrCreate(thr, pc, addr, false); in ReleaseStoreAcquire()
439 thr->fast_state.IncrementEpoch(); in ReleaseStoreAcquire()
441 TraceAddEvent(thr, thr->fast_state, EventTypeMop, 0); in ReleaseStoreAcquire()
442 ReleaseStoreAcquireImpl(thr, pc, &s->clock); in ReleaseStoreAcquire()
445 void Release(ThreadState *thr, uptr pc, uptr addr) { in Release() argument
446 DPrintf("#%d: Release %zx\n", thr->tid, addr); in Release()
447 if (thr->ignore_sync) in Release()
449 SyncVar *s = ctx->metamap.GetSyncOrCreate(thr, pc, addr, false); in Release()
451 thr->fast_state.IncrementEpoch(); in Release()
453 TraceAddEvent(thr, thr->fast_state, EventTypeMop, 0); in Release()
454 ReleaseImpl(thr, pc, &s->clock); in Release()
457 void ReleaseStore(ThreadState *thr, uptr pc, uptr addr) { in ReleaseStore() argument
458 DPrintf("#%d: ReleaseStore %zx\n", thr->tid, addr); in ReleaseStore()
459 if (thr->ignore_sync) in ReleaseStore()
461 SyncVar *s = ctx->metamap.GetSyncOrCreate(thr, pc, addr, false); in ReleaseStore()
463 thr->fast_state.IncrementEpoch(); in ReleaseStore()
465 TraceAddEvent(thr, thr->fast_state, EventTypeMop, 0); in ReleaseStore()
466 ReleaseStoreImpl(thr, pc, &s->clock); in ReleaseStore()
471 ThreadState *thr = reinterpret_cast<ThreadState*>(arg); in UpdateSleepClockCallback() local
475 epoch = tctx->thr->fast_state.epoch(); in UpdateSleepClockCallback()
476 thr->last_sleep_clock.set(&thr->proc()->clock_cache, tctx->tid, epoch); in UpdateSleepClockCallback()
479 void AfterSleep(ThreadState *thr, uptr pc) { in AfterSleep() argument
480 DPrintf("#%d: AfterSleep\n", thr->tid); in AfterSleep()
481 if (thr->ignore_sync) in AfterSleep()
483 thr->last_sleep_stack_id = CurrentStackId(thr, pc); in AfterSleep()
486 thr); in AfterSleep()
490 void AcquireImpl(ThreadState *thr, uptr pc, SyncClock *c) { in AcquireImpl() argument
491 if (thr->ignore_sync) in AcquireImpl()
493 thr->clock.set(thr->fast_state.epoch()); in AcquireImpl()
494 thr->clock.acquire(&thr->proc()->clock_cache, c); in AcquireImpl()
497 void ReleaseStoreAcquireImpl(ThreadState *thr, uptr pc, SyncClock *c) { in ReleaseStoreAcquireImpl() argument
498 if (thr->ignore_sync) in ReleaseStoreAcquireImpl()
500 thr->clock.set(thr->fast_state.epoch()); in ReleaseStoreAcquireImpl()
501 thr->fast_synch_epoch = thr->fast_state.epoch(); in ReleaseStoreAcquireImpl()
502 thr->clock.releaseStoreAcquire(&thr->proc()->clock_cache, c); in ReleaseStoreAcquireImpl()
505 void ReleaseImpl(ThreadState *thr, uptr pc, SyncClock *c) { in ReleaseImpl() argument
506 if (thr->ignore_sync) in ReleaseImpl()
508 thr->clock.set(thr->fast_state.epoch()); in ReleaseImpl()
509 thr->fast_synch_epoch = thr->fast_state.epoch(); in ReleaseImpl()
510 thr->clock.release(&thr->proc()->clock_cache, c); in ReleaseImpl()
513 void ReleaseStoreImpl(ThreadState *thr, uptr pc, SyncClock *c) { in ReleaseStoreImpl() argument
514 if (thr->ignore_sync) in ReleaseStoreImpl()
516 thr->clock.set(thr->fast_state.epoch()); in ReleaseStoreImpl()
517 thr->fast_synch_epoch = thr->fast_state.epoch(); in ReleaseStoreImpl()
518 thr->clock.ReleaseStore(&thr->proc()->clock_cache, c); in ReleaseStoreImpl()
521 void AcquireReleaseImpl(ThreadState *thr, uptr pc, SyncClock *c) { in AcquireReleaseImpl() argument
522 if (thr->ignore_sync) in AcquireReleaseImpl()
524 thr->clock.set(thr->fast_state.epoch()); in AcquireReleaseImpl()
525 thr->fast_synch_epoch = thr->fast_state.epoch(); in AcquireReleaseImpl()
526 thr->clock.acq_rel(&thr->proc()->clock_cache, c); in AcquireReleaseImpl()
529 void ReportDeadlock(ThreadState *thr, uptr pc, DDReport *r) { in ReportDeadlock() argument
530 if (r == 0 || !ShouldReport(thr, ReportTypeDeadlock)) in ReportDeadlock()
552 OutputReport(thr, rep); in ReportDeadlock()