111
|
1 //===-- tsan_rtl_proc.cc ------------------------------------------------===//
|
|
2 //
|
|
3 // This file is distributed under the University of Illinois Open Source
|
|
4 // License. See LICENSE.TXT for details.
|
|
5 //
|
|
6 //===----------------------------------------------------------------------===//
|
|
7 //
|
|
8 // This file is a part of ThreadSanitizer (TSan), a race detector.
|
|
9 //
|
|
10 //===----------------------------------------------------------------------===//
|
|
11
|
|
12 #include "sanitizer_common/sanitizer_placement_new.h"
|
|
13 #include "tsan_rtl.h"
|
|
14 #include "tsan_mman.h"
|
|
15 #include "tsan_flags.h"
|
|
16
|
|
17 namespace __tsan {
|
|
18
|
|
19 Processor *ProcCreate() {
|
|
20 void *mem = InternalAlloc(sizeof(Processor));
|
|
21 internal_memset(mem, 0, sizeof(Processor));
|
|
22 Processor *proc = new(mem) Processor;
|
|
23 proc->thr = nullptr;
|
|
24 #if !SANITIZER_GO
|
|
25 AllocatorProcStart(proc);
|
|
26 #endif
|
|
27 if (common_flags()->detect_deadlocks)
|
|
28 proc->dd_pt = ctx->dd->CreatePhysicalThread();
|
|
29 return proc;
|
|
30 }
|
|
31
|
|
32 void ProcDestroy(Processor *proc) {
|
|
33 CHECK_EQ(proc->thr, nullptr);
|
|
34 #if !SANITIZER_GO
|
|
35 AllocatorProcFinish(proc);
|
|
36 #endif
|
|
37 ctx->clock_alloc.FlushCache(&proc->clock_cache);
|
|
38 ctx->metamap.OnProcIdle(proc);
|
|
39 if (common_flags()->detect_deadlocks)
|
|
40 ctx->dd->DestroyPhysicalThread(proc->dd_pt);
|
|
41 proc->~Processor();
|
|
42 InternalFree(proc);
|
|
43 }
|
|
44
|
|
45 void ProcWire(Processor *proc, ThreadState *thr) {
|
|
46 CHECK_EQ(thr->proc1, nullptr);
|
|
47 CHECK_EQ(proc->thr, nullptr);
|
|
48 thr->proc1 = proc;
|
|
49 proc->thr = thr;
|
|
50 }
|
|
51
|
|
52 void ProcUnwire(Processor *proc, ThreadState *thr) {
|
|
53 CHECK_EQ(thr->proc1, proc);
|
|
54 CHECK_EQ(proc->thr, thr);
|
|
55 thr->proc1 = nullptr;
|
|
56 proc->thr = nullptr;
|
|
57 }
|
|
58
|
|
59 } // namespace __tsan
|