Home | History | Annotate | Download | only in tsan

Lines Matching refs:thr

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