]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/compiler-rt/lib/tsan/rtl/tsan_rtl_proc.cc
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm-project / compiler-rt / lib / tsan / rtl / tsan_rtl_proc.cc
1 //===-- tsan_rtl_proc.cc ------------------------------------------------===//
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
18 namespace __tsan {
19
20 Processor *ProcCreate() {
21   void *mem = InternalAlloc(sizeof(Processor));
22   internal_memset(mem, 0, 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
33 void ProcDestroy(Processor *proc) {
34   CHECK_EQ(proc->thr, nullptr);
35 #if !SANITIZER_GO
36   AllocatorProcFinish(proc);
37 #endif
38   ctx->clock_alloc.FlushCache(&proc->clock_cache);
39   ctx->metamap.OnProcIdle(proc);
40   if (common_flags()->detect_deadlocks)
41      ctx->dd->DestroyPhysicalThread(proc->dd_pt);
42   proc->~Processor();
43   InternalFree(proc);
44 }
45
46 void ProcWire(Processor *proc, ThreadState *thr) {
47   CHECK_EQ(thr->proc1, nullptr);
48   CHECK_EQ(proc->thr, nullptr);
49   thr->proc1 = proc;
50   proc->thr = thr;
51 }
52
53 void ProcUnwire(Processor *proc, ThreadState *thr) {
54   CHECK_EQ(thr->proc1, proc);
55   CHECK_EQ(proc->thr, thr);
56   thr->proc1 = nullptr;
57   proc->thr = nullptr;
58 }
59
60 }  // namespace __tsan