1//===-- tsan_rtl_proc.cpp -----------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file is a part of ThreadSanitizer (TSan), a race detector.
10//
11//===----------------------------------------------------------------------===//
12
13#include "sanitizer_common/sanitizer_placement_new.h"
14#include "tsan_rtl.h"
15#include "tsan_mman.h"
16#include "tsan_flags.h"
17
18namespace __tsan {
19
20Processor *ProcCreate() {
21 void *mem = InternalAlloc(size: sizeof(Processor));
22 internal_memset(s: mem, c: 0, n: sizeof(Processor));
23 Processor *proc = new(mem) Processor;
24 proc->thr = nullptr;
25#if !SANITIZER_GO
26 AllocatorProcStart(proc);
27#endif
28 if (common_flags()->detect_deadlocks)
29 proc->dd_pt = ctx->dd->CreatePhysicalThread();
30 return proc;
31}
32
33void ProcDestroy(Processor *proc) {
34 CHECK_EQ(proc->thr, nullptr);
35#if !SANITIZER_GO
36 AllocatorProcFinish(proc);
37#endif
38 ctx->metamap.OnProcIdle(proc);
39 if (common_flags()->detect_deadlocks)
40 ctx->dd->DestroyPhysicalThread(pt: proc->dd_pt);
41 proc->~Processor();
42 InternalFree(p: proc);
43}
44
45void 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
52void 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
60

source code of compiler-rt/lib/tsan/rtl/tsan_rtl_proc.cpp